From d4d7c4a3ff7120c1703de85281d8daa764515bd2 Mon Sep 17 00:00:00 2001 From: Zhihao Date: Fri, 6 Mar 2015 16:17:21 +0800 Subject: [PATCH] update for http://codinfox.github.io/dev/2015/03/06/use-tags-and-categories-in-your-jekyll-based-github-pages/ --- _posts/2013-12-31-whats-jekyll.md | 1 + blog/category.html | 85 +++++++++++++++++++++++++++++++ blog/category_index.html | 39 -------------- blog/index.html | 76 +++++++++++++++------------ blog/tag.html | 64 +++++++++++++++++++++++ 5 files changed, 193 insertions(+), 72 deletions(-) create mode 100644 blog/category.html delete mode 100644 blog/category_index.html create mode 100644 blog/tag.html diff --git a/_posts/2013-12-31-whats-jekyll.md b/_posts/2013-12-31-whats-jekyll.md index 6af83b08..b544aae0 100644 --- a/_posts/2013-12-31-whats-jekyll.md +++ b/_posts/2013-12-31-whats-jekyll.md @@ -3,6 +3,7 @@ layout: post title: What's Jekyll? comments: true category: Misc +tags: jekyll --- [Jekyll](http://jekyllrb.com) is a static site generator, an open-source tool for creating simple yet powerful websites of all shapes and sizes. From [the project's readme](https://github.com/mojombo/jekyll/blob/master/README.markdown): diff --git a/blog/category.html b/blog/category.html new file mode 100644 index 00000000..37391b36 --- /dev/null +++ b/blog/category.html @@ -0,0 +1,85 @@ +--- +layout: blog_index +title: Category +--- +{% comment%} +Here we generate all the categories. +{% endcomment%} + +{% assign rawcats = "" %} +{% for post in site.posts %} +{% assign tcats = post.category | join:'|' | append:'|' %} +{% assign rawcats = rawcats | append:tcats %} +{% endfor %} + +{% assign rawcats = rawcats | split:'|' | sort %} + +{% assign cats = "" %} + +{% for cat in rawcats %} +{% if cat != "" %} + +{% if cats == "" %} +{% assign cats = cat | split:'|' %} +{% endif %} + +{% unless cats contains cat %} +{% assign cats = cats | join:'|' | append:'|' | append:cat | split:'|' %} +{% endunless %} +{% endif %} +{% endfor %} + +

+ Blog | {{ page.title }} +

+
+ +
+

+{% for ct in cats %} + {{ ct }}    +{% endfor %} + No Category    +

+ +{% for ct in cats %} +

{{ ct }}

+ +{% endfor %} + +

No Category

+ + +
diff --git a/blog/category_index.html b/blog/category_index.html deleted file mode 100644 index 7e0405f8..00000000 --- a/blog/category_index.html +++ /dev/null @@ -1,39 +0,0 @@ ---- -layout: blog_index -title: Category -to-list: [Dev, General, Misc, Notes] ---- - -

- Blog | {{ page.title }} -

-
- -
-

-{% for ct in page.to-list %} - {{ ct }}    -{% endfor %} -

- -{% for ct in page.to-list %} -

{{ ct }}

- -{% endfor %} -
diff --git a/blog/index.html b/blog/index.html index 8fae8cd7..1b79a421 100644 --- a/blog/index.html +++ b/blog/index.html @@ -3,48 +3,58 @@ title: Blog --- -

- {{ page.title }} | Category -

-
+

{{ page.title }}

+ +
+ Browse by Category or Tag +
+ +

- {% for post in paginator.posts %} -
-

- - {{ post.title }} - -

- - - - {% if post.content contains "" %} - {{ post.content | split:"" | first % }} - {% else %} - {{ post.content | truncatewords:35 }} - {% endif %} - - -
- {% endfor %} + {% for post in paginator.posts %} +
+

+ + {{ post.title }} + +

+ + + + {{ post.content | split:"" | first % }} + +
+ Comment  + Read more +
+
+ +
+ {% endfor %}
diff --git a/blog/tag.html b/blog/tag.html new file mode 100644 index 00000000..240cd3d3 --- /dev/null +++ b/blog/tag.html @@ -0,0 +1,64 @@ +--- +layout: blog_index +title: Tag +--- +{% comment%} +Here we generate all the tags. +{% endcomment%} + +{% assign rawtags = "" %} +{% for post in site.posts %} +{% assign ttags = post.tags | join:'|' | append:'|' %} +{% assign rawtags = rawtags | append:ttags %} +{% endfor %} + +{% assign rawtags = rawtags | split:'|' | sort %} + +{% assign tags = "" %} + +{% for tag in rawtags %} +{% if tag != "" %} + +{% if tags == "" %} +{% assign tags = tag | split:'|' %} +{% endif %} + +{% unless tags contains tag %} +{% assign tags = tags | join:'|' | append:'|' | append:tag | split:'|' %} +{% endunless %} +{% endif %} +{% endfor %} + +

+ Blog | {{ page.title }} +

+
+ +
+

+{% for tag in tags %} + {{ tag }}    +{% endfor %} + +{% for tag in tags %} +

{{ tag }}

+ +{% endfor %} + +