首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在Docpad中仅显示部分博客文章,并带有“阅读更多”链接

在Docpad中仅显示部分博客文章,并带有“阅读更多”链接
EN

Stack Overflow用户
提问于 2013-06-19 02:20:18
回答 4查看 888关注 0票数 3

我只需要显示部分博客帖子...有一个“阅读更多”链接到完整的博客文章。

主页:列出最近5个部分/介绍帖子和阅读更多。

这在Docpad中是可能的吗?

谢谢..

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2013-06-19 15:29:33

可在

代码语言:javascript
运行
复制
    getCuttedContent: (content) ->            
        i = content.search('<!-- Read more -->')
        if i >= 0
            content[0..i-1]                
        else
            content

    hasReadMore: (content) ->
        content.search('<!-- Read more -->') >= 0

more

代码语言:javascript
运行
复制
        <% 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>Читать далее &rarr;</strong></a></div>
                <% end %>
            </article>
        <% end %>

posts

并添加到帖子中

代码语言:javascript
运行
复制
 <!-- Read more -->
票数 4
EN

Stack Overflow用户

发布于 2013-07-02 18:50:59

如果你想在之前更多和之后更多的时候使用不同的页面,你可以使用paged plugin和他们的Splitting a Document into Multiple Pages example

类似于:

代码语言:javascript
运行
复制
---
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页”检查中,以防止这种情况发生。

票数 0
EN

Stack Overflow用户

发布于 2013-07-02 18:56:14

如果你不想要之前更多和之后更多的不同页面,但只想在内容列表中使用之前更多的页面。你可以像这样在"description“元数据属性中把你的东西放在更多的东西之前:

代码语言:javascript
运行
复制
--- cson
title: 'Awesome Pages Post"
layout: "default"
description: """
    Before more content goes here
    """
---

After more content (the actual page content) goes here.

然后,您可以通过执行以下操作在内容列表中显示描述:

代码语言:javascript
运行
复制
<%- post.description or post.contentRenderedWithoutLayouts  %>

如果未定义描述,则将回退到完整内容。

如果您希望能够呈现您的描述,text plugin将为您提供支持。将您的元数据描述改为以下内容:

代码语言:javascript
运行
复制
description: """
    <t render="markdown">With the text plugin **you can render anything providing you have the plugins installed!**</t>
    """
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17176094

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档