Show only a partial blog post on Docpad, with the link "Details"

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

HOME: List of the last 5 partial / entry posts with more.

Is this possible in Docpad?

Thanks..

+3
source share
4 answers

Can

getCuttedContent: (content) -> i = content.search('<!-- Read more -->') if i >= 0 content[0..i-1] else content hasReadMore: (content) -> content.search('<!-- Read more -->') >= 0 

more

and

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

and add to message

  <!-- Read more --> 
+4
source

If you no longer need different pages, and you can use a paid plug-in with their Separation of the document into several pages .

Something like:

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

Gotta do the trick. Then you can just stick with the logic to handle the various use cases. For example, they will have the text β€œup to more” shown on both pages. But you can wrap "before" in the "page" to prevent this if you want.

0
source

If you no longer need different pages for more and more, but simply more, but you want to use them more in the content list. You can simply add your data to the description metadata attribute of description as follows:

 --- cson title: 'Awesome Pages Post" layout: "default" description: """ Before more content goes here """ --- After more content (the actual page content) goes here. 

You can then display the description in your content list by following these steps:

 <%- post.description or post.contentRenderedWithoutLayouts %> 

What will happen in the case of a full description if the description is not defined.

If you want your description to be displayed, you have covered the text plugin . Change the metadata description as follows:

 description: """ <t render="markdown">With the text plugin **you can render anything providing you have the plugins installed!**</t> """ 
0
source

Otherwise, I use the following method in docpad.coffee to truncate messages for display on the home page. It deals with links that make text seem longer and block records that you could break in the middle

 # 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 
0
source

All Articles