2013-03-15 32 views
2

我使用傑基爾一個靜態的網站,我試圖生成博客作爲一個子目錄/子文件夾:傑基爾分頁博客作爲子目錄

http://example.com/blog 

在運行之前傑基爾的目錄結構,這是博客/index.html。

我試圖通過添加「分頁:5」添加到分頁_config.yml,但生成的URL的是以下形式:

http://example.com/page2/ 

即,沒有「/博客」。

paginate_path:這是由固定/博客/頁/:NUM

在_config.yml

但在導致生成的頁面:

http://example.com/blog/page/2/ 

不要使用博客/ index.html作爲它們的佈局。他們使用根index.html。那麼,即使有paginate_path選項,什麼意思?

我如何通過使用Jekyll在example.com/blog上使用分頁來獲取我的博客?

回答

4

在您的_config.yml文件中使用destination鍵來設置要將輸出發佈到的基本路徑。例如,

paginate: 5 
destination: _site/blog 

注意,假設您的網站是設置到服務器根(例如「http://example.com/」)從‘_site’傑奇不會產生與‘index.html的’在那個位置上。 jekyll構建的所有東西都將位於「博客」目錄下,但這聽起來像是你之後的事情。

+1

其實,我使用化身爲整個網站,而不僅僅是博客。所以我不能使用'目的地'。我結束了使用[這個插件](https://github.com/MrWerewolf/jekyll-category-pagination),而不是分類分類,而是讓博客使用blog/index.html作爲佈局。 – user1431368 2013-03-22 18:19:39

+0

對於服務器,您會使用網站的網址作爲目的地,還是堅持使用_site.blog? – Doidgey 2013-12-17 21:02:07

+0

@ Mat-visual - 目標是磁盤上的一個位置。所以,你不想使用URL。我沒有測試過,但我認爲這不會起作用。 – 2013-12-18 16:31:22

2

我通過這個page發現了一個修復程序基本上它涉及到一點點黑客來弄清楚你是否在博客的第n頁上,然後包含一個文件來拉你的博客部分。

_includes/custom/中創建一個名爲pagination的文件。在有你的分頁代碼

<!-- This loops through the paginated posts --> 
{% for post in paginator.posts %} 
    <h1><a href="{{ post.url }}">{{ post.title }}</a></h1> 
    <p class="author"> 
    <span class="date">{{ post.date }}</span> 
    </p> 
    <div class="content"> 
    {{ post.content }} 
    </div> 
{% endfor %} 

<!-- Pagination links --> 
<div class="pagination"> 
    {% if paginator.previous_page %} 
    <a href="/page{{ paginator.previous_page }}" class="previous">Previous</a> 
    {% else %} 
    <span class="previous">Previous</span> 
    {% endif %} 
    <span class="page_number ">Page: {{ paginator.page }} of {{ paginator.total_pages  }}</span> 
    {% if paginator.next_page %} 
    <a href="/page{{ paginator.next_page }}" class="next">Next</a> 
    {% else %} 
    <span class="next ">Next</span> 
    {% endif %} 
</div> 

現在,在您_layout/index.html添加

{% if paginator.page != 1 %} 
{% include custom/pagination %} 
{% else %} 
The original content of index 
{% endif %}