Skip to content

Commit 4ee9773

Browse files
[ADD] Adding page which will list all the available tags in the blog. (#11)
Generating individual feed file for each tag. Providing list page which will list all the posts according specific tag.
1 parent 73f40d4 commit 4ee9773

10 files changed

+227
-3
lines changed

_layouts/atom.html

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<feed xmlns="http://www.w3.org/2005/Atom" {% if site.lang %}xml:lang="{{ site.lang }}"{% endif %}>
3+
<generator uri="https://jekyllrb.com/" version="{{ jekyll.version }}">Jekyll</generator>
4+
<link href="{{ page.url | absolute_url }}" rel="self" type="application/atom+xml" />
5+
<link href="{{ '/' | absolute_url }}" rel="alternate" type="text/html" {% if site.lang %}hreflang="{{ site.lang }}" {% endif %}/>
6+
<updated>{{ site.time | date_to_xmlschema }}</updated>
7+
<id>{{ '/' | absolute_url | xml_escape }}</id>
8+
9+
{% if site.title %}
10+
<title type="html">{{ site.title | smartify | xml_escape }}</title>
11+
{% elsif site.name %}
12+
<title type="html">{{ site.name | smartify | xml_escape }}</title>
13+
{% endif %}
14+
15+
{% if site.description %}
16+
<subtitle>{{ site.description | xml_escape }}</subtitle>
17+
{% endif %}
18+
19+
{% if site.author %}
20+
<author>
21+
<name>{{ site.author.name | default: site.author | xml_escape }}</name>
22+
{% if site.author.email %}
23+
<email>{{ site.author.email | xml_escape }}</email>
24+
{% endif %}
25+
{% if site.author.uri %}
26+
<uri>{{ site.author.uri | xml_escape }}</uri>
27+
{% endif %}
28+
</author>
29+
{% endif %}
30+
31+
{% assign posts = site.posts | where_exp: "post", "post.draft != true" %}
32+
{% for post in posts limit: 10 %}
33+
{% for tag in post.tags %}
34+
{% if tag == page.tag %}
35+
<entry{% if post.lang %}{{" "}}xml:lang="{{ post.lang }}"{% endif %}>
36+
<title type="html">{{ post.title | smartify | strip_html | normalize_whitespace | xml_escape }}</title>
37+
<link href="{{ post.url | absolute_url }}" rel="alternate" type="text/html" title="{{ post.title | xml_escape }}" />
38+
<published>{{ post.date | date_to_xmlschema }}</published>
39+
<updated>{{ post.last_modified_at | default: post.date | date_to_xmlschema }}</updated>
40+
<id>{{ post.id | absolute_url | xml_escape }}</id>
41+
<content type="html" xml:base="{{ post.url | absolute_url | xml_escape }}">{{ post.content | strip | xml_escape }}</content>
42+
43+
{% assign post_author = post.author | default: post.authors[0] | default: site.author %}
44+
{% assign post_author = site.data.authors[post_author] | default: post_author %}
45+
{% assign post_author_email = post_author.email | default: nil %}
46+
{% assign post_author_uri = post_author.uri | default: nil %}
47+
{% assign post_author_name = post_author.name | default: post_author %}
48+
49+
<author>
50+
<name>{{ post_author_name | default: "" | xml_escape }}</name>
51+
{% if post_author_email %}
52+
<email>{{ post_author_email | xml_escape }}</email>
53+
{% endif %}
54+
{% if post_author_uri %}
55+
<uri>{{ post_author_uri | xml_escape }}</uri>
56+
{% endif %}
57+
</author>
58+
59+
{% if post.category %}
60+
<category term="{{ post.category | xml_escape }}" />
61+
{% endif %}
62+
63+
{% for tag in post.tags %}
64+
<category term="{{ tag | xml_escape }}" />
65+
{% endfor %}
66+
67+
{% if post.excerpt and post.excerpt != empty %}
68+
<summary type="html">{{ post.excerpt | strip_html | normalize_whitespace | xml_escape }}</summary>
69+
{% endif %}
70+
71+
{% assign post_image = post.image.path | default: post.image %}
72+
{% if post_image %}
73+
{% unless post_image contains "://" %}
74+
{% assign post_image = post_image | absolute_url | xml_escape %}
75+
{% endunless %}
76+
<media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="{{ post_image }}" />
77+
{% endif %}
78+
</entry>
79+
{% endif %}
80+
{% endfor %}
81+
{% endfor %}
82+
</feed>

_layouts/tag_index.html

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
layout: default
3+
---
4+
<div class="home">
5+
6+
<h1 class="page-heading">Posts</h1>
7+
8+
{{ content }}
9+
10+
<ul class="post-list">
11+
{% for post in site.posts %}
12+
{% for tag in post.tags %}
13+
{% if tag == page.tag %}
14+
<li>
15+
{% assign date_format = site.minima.date_format | default: "%b %-d, %Y" %}
16+
<span class="post-meta">{{ post.date | date: date_format }}</span>
17+
18+
<h2>
19+
<a class="post-link" href="{{ post.url | relative_url }}">{{ post.title | escape }}</a>
20+
</h2>
21+
</li>
22+
{% endif %}
23+
{% endfor %}
24+
{% endfor %}
25+
</ul>
26+
27+
<p class="rss-subscribe">subscribe <a href="/tags/{{ page.tag }}/feed.xml">via RSS</a></p>
28+
29+
</div>

_layouts/tags_folder_index.html

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
layout: page
3+
title: Tags
4+
permalink: /tags/
5+
---
6+
7+
{% assign sorted_posts = site.tags | sort %}
8+
9+
{% for post in sorted_posts %}
10+
{% assign tag = post | first %}
11+
<ul class="post-list">
12+
<h2>
13+
<a class="post-link" href="/tags/{{ tag }}/">{{ tag | escape }}</a>
14+
</h2>
15+
</ul>
16+
{% endfor %}

_plugins/rss_tag.rb

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module Jekyll
2+
class TagAtom < Page
3+
def initialize(site, base, dir, tag)
4+
@site = site
5+
@base = base
6+
@dir = dir
7+
@name = "feed.xml"
8+
9+
process(@name)
10+
read_yaml(File.join(base, '_layouts'), 'atom.html')
11+
data['tag'] = tag
12+
end
13+
end
14+
15+
class TagPageGenerator < Generator
16+
safe true
17+
18+
# Generate tag page and atom feed for each tag used in the blogs
19+
def generate(site)
20+
# if site.layouts.key? 'tagpage'
21+
site.tags.each_key do |tag|
22+
site.pages << TagAtom.new(site, site.source, File.join('tags',tag), tag)
23+
end
24+
# end
25+
end
26+
end
27+
end

_plugins/tag_gen.rb

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
module Jekyll
2+
3+
class TagIndex < Page
4+
def initialize(site, base, dir, tag)
5+
@site = site
6+
@base = base
7+
@dir = dir
8+
@name = 'index.html'
9+
10+
self.process(@name)
11+
self.read_yaml(File.join(base, '_layouts'), 'tag_index.html')
12+
self.data['tag'] = tag
13+
end
14+
end
15+
16+
class TagGenerator < Generator
17+
safe true
18+
19+
def generate(site)
20+
if site.layouts.key? 'tag_index'
21+
dir = 'tags'
22+
site.tags.keys.each do |tag|
23+
write_tag_index(site, File.join(dir, tag), tag)
24+
end
25+
end
26+
end
27+
28+
def write_tag_index(site, dir, tag)
29+
index = TagIndex.new(site, site.source, dir, tag)
30+
index.render(site.layouts, site.site_payload)
31+
index.write(site.dest)
32+
site.pages << index
33+
end
34+
end
35+
end

_plugins/tags_folder.rb

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module Jekyll
2+
3+
class TagList < Page
4+
def initialize(site, base, dir)
5+
@site = site
6+
@base = base
7+
@dir = dir
8+
@name = 'index.html'
9+
10+
self.process(@name)
11+
self.read_yaml(File.join(base, '_layouts'), 'tags_folder_index.html')
12+
end
13+
end
14+
15+
class TagListGenerator < Generator
16+
safe true
17+
18+
def generate(site)
19+
if site.layouts.key? 'tags_folder_index'
20+
site.pages << TagList.new(site, site.source, 'tags')
21+
end
22+
end
23+
end
24+
end

_posts/2017-01-08-2016-a-year-dedicated-to-python-workshops.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
---
22
layout: post
33
title: 2016 A year dedicated to Python Workshops
4-
tag: pythonworkshop
4+
tag:
5+
- python
6+
- workshop
7+
- pythonexpress
58
excerpt: >
69
Beautiful 2017 has already started. While everybody is busy with preparing
710
resolutions for their new year I decided to look back and share my journey

_posts/2017-02-28-book-review-introduction-to-the-commandline.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
layout: post
33
categories: book review
44
title: Book review 'Introduction to the Command Line'
5-
tag: books linux programming
5+
tag:
6+
- books
7+
- linux
8+
- programming
69
excerpt: >
710
Every chapter will introduce a bunch of comands and will point to its
811
respective documentation for further learning. You should expect chapters

_posts/2017-03-14-pycon-pune-2017-a-wonderful-python-conference.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
layout: post
33
title: "Pycon Pune 2017: A wonderful Python conference"
44
date: "2017-03-14 18:18:02 +0530"
5-
tag: python conference
5+
tag:
6+
- python
7+
- conference
68
excerpt: >
79
The conference is worth attending if you are a student, programmer or a
810
hobbyist. If you are a swag-hungry then don't expect much as a swag from this

_posts/2017-04-10-goyo-doc-vim-helpfile-for-goyo-plugin.md

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
layout: post
33
title: "goyo-doc: Vim helpfile for goyo.vim plugin"
44
date: "2017-04-10 17:51:48 +0530"
5+
tags:
6+
- vim
7+
- goyo_doc
58
excerpt: >
69
Goyo is the vim plugin which allows writers to focus on their writing while
710
they are writing. The plugin deactivates not required fancy windows which are

0 commit comments

Comments
 (0)