最近在訂定一個小目標,就是要在今年破200篇文章,但是octopress的外掛需要自己寫,看了高見龍大大的幫你的Octopress增加文章分類文章,也直接偷偷改了他的程式碼,產生文章數量的silderbar。
把下面的程式碼新增到plugins/article_total.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
module Jekyll | |
class Site | |
def create_article_total_list(site) | |
write_to_Article_total_sidebar(site) if @config['article_total_sidebar'] | |
end | |
private | |
# generate category tag list and write to 'source/_includes/asides/categories_tag.html' | |
def write_to_Article_total_sidebar(site) | |
all_posts = site.site_payload['site']['posts'] | |
puts ' => Creating Article total Sidebar' | |
html = "<ul>\n" | |
# case insensitive sorting | |
html << " <li>#{@config['article_my_site_has']} #{all_posts.count} #{@config['article_my_site_article']}</li>\n" | |
html << "</ul>" | |
File.open(File.join(@source, '_includes/asides/article_total_sidebar.html'), 'w') do |file| | |
file << """{% if site.article_total_sidebar %} | |
<section> | |
<h1>#{@config['article_total_title'] || 'Article Total'}</h1> | |
#{html} | |
</section> | |
{% endif %} | |
""" | |
end | |
end | |
end | |
class ArticleTotal < Generator | |
safe true | |
priority :low | |
def generate(site) | |
if site.config['article_total'] | |
puts "## Generating Article Total.." | |
site.create_article_total_list(site) | |
end | |
end | |
end | |
end |
這邊是會將你的outopress建立的post的數量,建立一個html的檔案
然後把下面幾行設定檔加到_config.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
可以修改的地方是article_my_site_has
跟article_my_site_article
按照你的語言
如果是要中文的話可以把這兩行改成
1 2 |
|
最後就要把產生的article_total_sidebar.html
檔案加到_config.yml
在default_asides:裡面加上asides/article_total_sidebar.html
才能夠將article total 加到 asides裡面!
因為我也是改高見龍大大的程式,如果有問題可以跟我說,或是有更好的建議可以提供給我~~
參考網站
幫你的Octopress增加文章分類 by 高見龍