仅显示Docpad中的部分博客文章,并带有“阅读更多内容"关联 [英] Show only partial blog post in Docpad, with "Read More" link

查看:99
本文介绍了仅显示Docpad中的部分博客文章,并带有“阅读更多内容"关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只需要显示部分博客文章...,并带有指向完整博客文章的阅读更多"链接.

I need show only partial blog post... with a "Read more" link to full blog post.

HOME:列出最近阅读"的最后5个部分/简介帖子.

HOME: List last 5 partial/intro posts with Read More.

这在Docpad中可以吗?

This is possible in Docpad?

谢谢..

推荐答案

5月

    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>Читать далее &rarr;</strong></a></div>
                <% end %>
            </article>
        <% end %>

帖子

并添加到帖子

 <!-- Read more -->

这篇关于仅显示Docpad中的部分博客文章,并带有“阅读更多内容"关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆