我只需要显示部分博客帖子...带有“阅读更多”链接到完整博客文章。仅显示Docpad中的部分博客帖子,带有“阅读更多”链接
首页:列出最后5部分/介绍帖子与阅读更多。
这是可能在Docpad?
谢谢..
我只需要显示部分博客帖子...带有“阅读更多”链接到完整博客文章。仅显示Docpad中的部分博客帖子,带有“阅读更多”链接
首页:列出最后5部分/介绍帖子与阅读更多。
这是可能在Docpad?
谢谢..
月由
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 [@[email protected]ndIdx]: %>
<% 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 %>
的D收藏张贴
<!-- Read more -->
如果您更前后更希望在不同的页面,你可以与他们Splitting a Document into Multiple Pages example使用paged plugin。
喜欢的东西:
---
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 %>
应该做的伎俩。然后你可以定义逻辑来处理不同的用例。例如,这两个页面上都会显示“before more”文本。但是如果你愿意的话,你可以在“第0页”检查中包裹“before more”。
如果您不想为之前和之后的其他页面创建不同的页面,但只希望在内容列表之前使用更多页面。你可以把你以前更多的东西在“说明”元数据属性,像这样:
--- 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>
"""
正如另一种方式,我用下面的方法docpad.coffee截断显示职位主页上。它处理的链接,这将使文字看起来更长,并可能最终打破在中间的报价
# Used for shortening a post
truncateText: (content,trimTo) ->
trimTo = trimTo || 200
output = content.substr(0,trimTo).trim()
#remove anchor tags as they don't show up on the page
nolinks = output.replace(/<a(\s[^>]*)?>.*?<\/a>/ig,"")
#check if there is a difference in length - if so add this
#difference to the trimTo length - add the text length that will not show
#up in the rendered HTML
diff = output.length - nolinks.length
output = content.substr(0,trimTo + diff)
#find the last space so that we don't break the text
#in the middle of a word
i = output.lastIndexOf(' ',output.length-1)
output = output.substr(0,i)+"..."
count1 = (output.match(/<blockquote>/g) || []).length
count2 = (output.match(/<\/blockquote>/g) || []).length
if count1 > count2
output += "</blockquote>"
return output