Показывать только частичную запись блога в Docpad со ссылкой «Подробнее»

Мне нужно показать только частичную запись в блоге... со ссылкой "Подробнее" на полную запись в блоге.

ГЛАВНАЯ: Перечислите последние 5 неполных/вступительных постов с надписью «Подробнее».

Это возможно в Docpad?

Спасибо..


person Diogo Moretti    schedule 18.06.2013    source источник


Ответы (4)


может

    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]]: %>
            <% 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 -->
person npofopr    schedule 19.06.2013

Если вам нужны разные страницы для «до и после», вы можете использовать подключаемый модуль с их Пример разделения документа на несколько страниц.

Что-то типа:

---
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». Но вы можете обернуть «before more» проверкой «is page 0», чтобы предотвратить это, если хотите.

person balupton    schedule 02.07.2013

Если вам не нужны разные страницы для «до» и «после», а просто хотите использовать «до» в списке контента. Вы можете просто поместить свои дополнительные материалы в атрибут метаданных «описание» следующим образом:

--- 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  %>

Который вернется к полному содержимому, если описание не определено.

Если вы хотите, чтобы ваше описание отображалось, воспользуйтесь текстовым плагином. Вместо этого измените описание метаданных на следующее:

description: """
    <t render="markdown">With the text plugin **you can render anything providing you have the plugins installed!**</t>
    """
person balupton    schedule 02.07.2013

В качестве другого способа я использую следующий метод в 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
person Steve Mc    schedule 26.08.2015