2013-05-07 117 views
24

我期待在索引頁上顯示較長文章或摘要頁的短文摘要。我本來打算在接待物質使用自定義變量,抓住,後來我看到了.excerpt如何在Jekyll中使用markdownify在索引上顯示摘錄

我在Jekyll docs看到有{{ page.excerpt | markdownify }}東西叫我怎麼會標記降價頁面或文章,以便在過濾器使用該過濾器?

編輯:或者markdownify獲取整個.md文件?

回答

14

在您需要先設置您的摘錄後降價文件,這裏是我的信息的一個例子

layout: post 
title: A developers toolkit 
date: Friday 14 December, 2012 
excerpt: What text editor to use? Sass or plain old CSS? What on earth is Compass? Command line? I'm not touching that. Sound like you? Welcome, I was once like you and this is the guide I wish someone had given me. 

然後索引頁上所說的標籤

{{ post.excerpt }} 

這應該然後輸出您在降價文件中寫下的內容。好,簡單,爲什麼我愛傑基爾。

72

Jekyll有一個選項excerpt_separator,它適合你。 事情是這樣的:

_config.yml

excerpt_separator: <!--more--> # you can specify your own separator, of course. 

在你後:

--- 
layout: post 
title: Foo 
--- 

This appears in your `index.html` 

This appears, too. 

<!--more--> 

This doesn't appear. It is separated. 

注意您必須準確鍵入<!--more-->,不<!--More--><!-- more -->

在你index.html

<!-- Loop in you posts --> 
{% for post in site.posts %} 
    <!-- Here's the header --> 
    <header> 
    <h2 class="title"><a href="{{ post.url }}">{{ post.title }}</a></h2> 
    </header> 

    <!-- Your post's summary goes here --> 
    <article>{{ post.excerpt }}</article> 
{% endfor %} 

輸出是這樣的:

<header> 
    <h2 class="title"><a href="Your post URL">Foo</a></h2> 
</header> 

<article> 

This appears in your `index.html` 

This appears, too. 

</article> 
+0

@kaplan這是更合適的答案。它應該被接受。 – kleinfreund 2014-01-19 16:15:22

+0

@kleinfreund事實上,我在接受第一個答案几個月後回答了這個問題。 – 2014-01-21 02:18:21

+0

我知道。這就是我評論的原因。這是更合適的答案。 – kleinfreund 2014-01-21 09:18:19

1

作爲參考84cfc1cef GitHub的版本支持每帖excerpt_separator所以你必須添加引用到Gemfile

gem 'jekyll', github: 'jekyll/jekyll', ref: '84cfc1ceff0474fd3eb3beb193ae59ae43694863' 

和創建具有以下YAML柱:

--- 
title: Post Excerpt Separator 
excerpt_separator: "\n---\n" 
--- 
2

不工作爲畝,或集合,擊中除了解析液體時化身恐慌。我不知道這是爲什麼,它應該按照你的建議工作。

還存在另一種:

post.content或我的情況是:blogX.content並通過一些文字過濾器,限制內容的大小粉碎它。

ie: {{blog.content | strip_html | truncatewords:100}}

相關問題