2014-09-11 3 views
0

나는 Jekyll 정적 사이트 생성기를 사용하는 블로깅을 위해 Octopress 2.0을 사용하고 있습니다. 비록 일부 게시물에 대한Octopress/Jekyll에서 발췌 한 내용을 어떻게 생략 할 수 있습니까?

..

당신이 게시물에 <!--more-->를 삽입 할 수 있습니다, 프론트 페이지에 대한 블로그 게시물의 발췌를 표시하려면, 그 시점에 콘텐츠를 최대 발췌로 사용됩니다 내가 발췌를 원한다면, 나는 그것으로부터 특정 것들을 제외하고 싶다. (포스트에서만 이해할 수있는 목차 나 발췌에 쓸모없는 여분의 노트가 필요할 것이다.)

발췌를 생성하는 <!--more--> 방법을 사용하는 Octopress/지킬/액체의 방법이 아니라 마르크 내용의 일부 소량을 생략 할 수 있나요?


다음은 간단한 예입니다. 이 게시물을 가지고 :

--- 
layout: post 
title: "Example Post" 
--- 

This is the first paragraph. It will be included in the excerpt. 

[Jump to third paragraph](#para3). This paragraph should **not** be in the excerpt. 

This is the second paragraph. It will be included in the excerpt. 

<!--more--> 

<a name="para3"></a>This is the third paragraph. It won't be in the excerpt. 

내가 원하는 방법을이 게시물에 대해 생성 된 발췌를 가질 수 :

This is the first paragraph. It will be included in the excerpt. 

This is the second paragraph. It will be included in the excerpt. 
+0

참고 : Octopress에서와 같이 보이지만, 'post.excerpt' 속성은 무시됩니다. – detly

+0

예제/컨텍스트를 제공 할 수 있습니까? 전체 발췌 부분을 어디에 표시하고 싶습니까? 발췌 부분은 어디에 넣으시겠습니까? 정말 명확하지 않습니다. –

+0

@DavidJacquel - "전체"및 "청크"발췌의 구분을 이해할 수 없습니다. 한 종류의 발췌 부분 만 있어야하며 Octopress가 현재 발췌 부분을 표시하는 곳이면 어디에서나 표시되어야합니다. – detly

답변

1

편집을 : 지금 당신이 뭘 하려는지 이해합니다.

기본 옥타 압 마크 다운 : rdiscount을 사용하고 있다고 가정합니다.

하자 필터 방식 얻었다 : 게시물에서 gem 'nokogiri'

를 추가

Gemfile년을, 아이디어는 때때로 제거해야하는 부분에 span.secondary를 추가하는 것입니다. _includes의 내용

... 
remove_secondary_content_from_excerpt : true 
--- 
This is the first paragraph. It will be included in the excerpt. 

[[Jump to third paragraph](#para3). This paragraph should **not** 
be in the excerpt.](class:secondary) 

This is the second paragraph. It will be included in the excerpt. 
<!--more--> 
### This is the TEXT title 
This is **the text** 

/article.html _plugins에서

... 
    </header> 
{% endunless %} 
{% if index %} 
    <div class="entry-content"> 
     {% if post.remove_secondary_content_from_excerpt == true %} 
     {% capture secondary_content %}{{ post.excerpt | excerpt_get_secondary_content }}{% endcapture %} 
     {{ post.excerpt | remove: secondary_content }} 
     {% else %} 
     {{ post.excerpt }} 
     {% endif %} 
    </div> 
    {% capture excerpted %}{{ content | has_excerpt }}{% endcapture %} 
    {% if excerpted == 'true' %} 
    <footer> 
     <a rel="full-article" href="{{ root_url }}{{ post.url }}">{{ site.excerpt_link }}</a> 
    </footer> 
    {% endif %} 
{% else %} 
<div class="entry-content"> 
    <!-- example on how to use it in post page --> 
    {% if page.remove_secondary_content_from_excerpt == true %} 
     {% capture secondary_content %}{{ page.excerpt | excerpt_get_secondary_content }}{% endcapture %} 
     {{ page.excerpt | remove: secondary_content }} 
     {{ secondary_content }} 
     {{ page.content | markdownify | remove: page.excerpt }} 
    {% else %} 
     {{ content }} 
    {% endif %} 
</div> 
{% endif %} 

/octopress_filters.rb

... 
module OctopressLiquidFilters 

    def excerpt_get_secondary_content(input) 
    require 'nokogiri' 
    doc = Nokogiri::HTML(input) 
    # as excerpt can surrounded by one <p> (when no double newline in it) 
    # or with multiple <p> when a double newline is found 
    multiparagraph = doc.css("p").length > 1 

    if multiparagraph 
     # look for parent <p> 
     xpathString = "span.secondary/.." 
    end 
     # look only for the span element 
     xpathString = "span.secondary" 
    else 

    secondary = doc.css(xpathString) 
    secondary.to_s 
    end 

... 

나는 당신의 rake generate 당신을 행복하게 만들 것 홉 노코 기리 bundle update

를 설치합니다.

+0

Octopress는 실제로'post.excerpt'를 설정하지 않으므로'content | 발췌'. – detly

+0

또한 - 저는 Ruby에 익숙하지 않지만'else /'end'를'multiparagraph 인 경우'에 섞어 놓았습니까? – detly

+0

'span.secondary/..'가 생성을 오류로 만들었습니다 ('Liquid Exception : unexpected '.'. '가 색인에 있습니다.html'), 단락 사이에 ''마커 만 사용 했으므로 그 지점을 제거했습니다. – detly