【问题标题】:Adding a search form to Docpad site向 Docpad 站点添加搜索表单
【发布时间】:2013-04-18 03:24:06
【问题描述】:

有没有办法让本地搜索表单在 Docpad 中为搜索结果编制索引。动态搜索页面示例不起作用,查看代码对我没有任何帮助。我认为一个搜索表单示例和一个基本联系表单示例对于像我这样希望将 Docpad 及其工作流程采用的新手来说会很有用。

提前感谢您的帮助!

【问题讨论】:

    标签: docpad


    【解决方案1】:

    取决于您所说的不工作是什么意思。您是否能够安装 Kitchin Sink 骨架?此框架中的搜索页面从 URL 中读取查询词,并搜索网站中标题中包含“咖啡”一词的所有文档

    @getCollection('documents').findAll({title:$like:query})
    

    您应该只获得标题中带有“咖啡”的文档的链接列表 - 本身并没有那么令人兴奋。

    如果您的意思是您尝试在自己的项目中实现此搜索页面,那么您必须确保在您的项目中安装了 docpad 插件 clean urls,这似乎有点“陷阱”。

    【讨论】:

    • 谢谢,我忽略了需要安装“干净的网址”。
    【解决方案2】:

    你可以像这样在 url 上传递参数:http://yoursite.com/search?query=your-query

    这就是解决问题的代码

    ### coffee
    layout: 'default'
    title: 'Search Results'
    dynamic: true
    ###
    
    if @req.query.query
        query = @req.query.query
    
        h2 "Searching for #{query}"
    
        ul ->
            for document in @getCollection('documents').findAll({title:$like:query}).toJSON()
                li 'typeof': 'sioc:Page', about: document.url, class: ('active'  if @document.url is document.url), ->
                    a href: document.url, property: 'dc:title', ->
                        text document.title
    
    else
        h2 "No query provided"
    

    【讨论】:

      猜你喜欢
      • 2014-09-05
      • 2012-04-25
      • 2022-01-10
      • 2013-12-02
      • 1970-01-01
      • 2014-04-12
      • 1970-01-01
      • 1970-01-01
      • 2012-10-28
      相关资源
      最近更新 更多