Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add plugin for generating tag pages automatically #84

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from

Conversation

borting
Copy link
Contributor

@borting borting commented Feb 20, 2021

This plugin automatically generates tags after saving posts if jekyll
server is running at background. The tag pages are stored in the tags/
dir, and you can add those pages to commits then push them to GitHub.

To enable this plugin, please do the following steps:

  1. Create a dir named 'tags' under the root dir.
  2. Create a layout, named _layouts/tag.html, for tag pages.
  3. Comment out the first return statement in the plugin.
  4. Update _layouts/post.html to show tag list on posts.

After enablinf this plugin, start jekyll server at local, and the server
will parse all posts and generate tag pages to the tags/ dir. The tag
pages are also generated on-the-fly after saving posts if jekyll server
is running at background.

This plugin automatically generates tags after saving posts if jekyll
server is running at background. The tag pages are stored in the tags/
dir, and you can add those pages to commits then push them to GitHub.

To enable this plugin, please do the following steps:
1. Create a dir named 'tags' under the root dir.
2. Create a layout, named `_layouts/tag.html,` for tag pages.
3. Comment out the first `return` statement in the plugin.
4. Update `_layouts/post.html` to show tag list on posts.

After enablinf this plugin, start jekyll server at local, and the server
will parse all posts and generate tag pages to the `tags/` dir. The tag
pages are also generated on-the-fly after saving posts if jekyll server
is running at background.

* Here is an example of `_layouts/tag.html` for tag page layout:
---
layout: default
---
<h1>
  Tag: {{ page.tag }}
</h1>
<ul>
  {% for post in site.posts %}
    {% if post.tags contains page.tag %}
      <li>
        <a href="{{ post.url }}">{{ post.title }}</a>
        ({{ post.date | date_to_string }})<br>
      </li>
    {% endif %}
  {% endfor %}
</ul>

* Here is an example of `_layouts/post.html` for showing tag list:
--- a/_layouts/post.html
+++ b/_layouts/post.html
@@ -30,6 +30,16 @@ layout: default
   {% endif %}
 </span>

+<span>
+  {% if page.tags != null %}
+    {% for tag in page.tags %}
+      {% capture tag_name %}{{ tag }}{% endcapture %}
+      <a href="/tag/{{ tag_name }}"><code class="highligher-rouge"><nobr>{{ tag_name }}</nobr></code></a>
+    {% endfor %}
+  {% endif %}
+</span>
+
 {% include social-sharing.html %}

 {% include related-posts.html %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant