【问题标题】:Dynamic categories with docpad带有 docpad 的动态类别
【发布时间】:2013-07-31 08:54:36
【问题描述】:

我的博客中有以下帖子:

src/documents/posts/foo.html.md

---
category: cooking
---

src/documents/posts/bar.html.md

---
category: programmation
---

我想生成以下路线:

http://example.org/cooking/
http://example.org/programmation/

每条路线都有一个集合,其中仅包含所选类别中的帖子。帖子仍将在标准位置:

http://example.org/posts/foo.html
http://example.org/posts/bar.html

加分:我还希望能够在我的布局中列出类别。类似的东西:

<% for cat in @getCategories() %>
    <a href="<%= cat.route %>"><%= cat.name %></a>
<% endfor %>

是否已经存在提供这些功能的插件?如果没有,开始实施它的最佳方式是什么?

我在this answer 中看到了setFilter 方法,但是在解析每个帖子以获取类别后,我仍在努力寻找如何生成新页面。

如果无法实现动态页面生成(我可以理解,因为它需要按特定顺序解析页面),在配置中使用静态数组是否会更容易?

【问题讨论】:

    标签: docpad


    【解决方案1】:

    看看这个相关的插件:

    https://github.com/docpad/docpad-plugin-related

    据我所知,它不会自动为您生成标签页面,但这是一个好的开始。

    【讨论】:

    【解决方案2】:

    我可以用标签插件做同样的事情:https://github.com/rantecki/docpad-plugin-tagging

    它会自动为您使用的每个标签创建视图。列出类别也很简单。这就是我所拥有的,使用一个选择框:

    <select ONCHANGE="location = this.options[this.selectedIndex].value;">
    <option value="">Choose</option>
    <% for tag, data of @getTagCloud(): %>
    <option value="<%= data.url %>">
    <%= tag %>
    </option>
    <% end %>
    </select>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-17
      • 1970-01-01
      • 2013-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多