ブログ投稿の一部のみを表示する必要があります...完全なブログ投稿への「続きを読む」リンクを使用します。
HOME: 続きを読むを使用して、最新の 5 つの部分的 / イントロ投稿を一覧表示します。
これはDocpadで可能ですか?
ありがとう..
ブログ投稿の一部のみを表示する必要があります...完全なブログ投稿への「続きを読む」リンクを使用します。
HOME: 続きを読むを使用して、最新の 5 つの部分的 / イントロ投稿を一覧表示します。
これはDocpadで可能ですか?
ありがとう..
別の方法として、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