我只需要显示部分博客帖子...有一个“阅读更多”链接到完整的博客文章。
主页:列出最近5个部分/介绍帖子和阅读更多。
这在Docpad中是可能的吗?
谢谢..
发布于 2013-06-19 15:29:33
可在
getCuttedContent: (content) ->
i = content.search('<!-- Read more -->')
if i >= 0
content[0..i-1]
else
content
hasReadMore: (content) ->
content.search('<!-- Read more -->') >= 0和
<% posts = @getCollection('posts') %>
<% for i in [@document.page.startIdx...@document.page.endIdx]: %>
<% document = posts.at(i).toJSON() %>
<article class="post">
<h3><span class="posts_date"><%= @formatDate(document.date) %></span> <a class="post_head" href="<%= document.url %>"><%= document.title %></a></h3>
<div class="post-content"><%- @getCuttedContent(String(document.contentRenderedWithoutLayouts)) %></div>
<% if @hasReadMore(String(document.contentRenderedWithoutLayouts)): %>
<div class="read_more"><a href="<%= document.url %>"><strong>Читать далее →</strong></a></div>
<% end %>
</article>
<% end %>并添加到帖子中
<!-- Read more -->发布于 2013-07-02 18:50:59
如果你想在之前更多和之后更多的时候使用不同的页面,你可以使用paged plugin和他们的Splitting a Document into Multiple Pages example。
类似于:
---
title: 'Awesome Pages Post'
layout: 'default'
isPaged: true
pageCount: 2
pageSize: 1
---
<!-- Page Content -->
before more
if @document.page.number is 1: %>
after more
<% end %>
<!-- Page Listing -->
<% if @document.page.number is 0: %>
<!-- Read More Button -->
<a href="<%= @getNextPage() %>">Read more!</a></li>
<% end %>应该能行得通。然后,您可以只保留逻辑来处理不同的用例。例如,在两个页面上都会显示“更多之前”的文本。但是如果你愿意,你可以把“更多之前”放在“是第0页”检查中,以防止这种情况发生。
发布于 2013-07-02 18:56:14
如果你不想要之前更多和之后更多的不同页面,但只想在内容列表中使用之前更多的页面。你可以像这样在"description“元数据属性中把你的东西放在更多的东西之前:
--- cson
title: 'Awesome Pages Post"
layout: "default"
description: """
Before more content goes here
"""
---
After more content (the actual page content) goes here.然后,您可以通过执行以下操作在内容列表中显示描述:
<%- post.description or post.contentRenderedWithoutLayouts %>如果未定义描述,则将回退到完整内容。
如果您希望能够呈现您的描述,text plugin将为您提供支持。将您的元数据描述改为以下内容:
description: """
<t render="markdown">With the text plugin **you can render anything providing you have the plugins installed!**</t>
"""https://stackoverflow.com/questions/17176094
复制相似问题