https://github.com/cmdr-nova/jekyll-tag-generator
A python script to use when running your blog locally, in order to generate tags.
https://github.com/cmdr-nova/jekyll-tag-generator
blog gen generator jekyll python tagpage tags
Last synced: 7 months ago
JSON representation
A python script to use when running your blog locally, in order to generate tags.
- Host: GitHub
- URL: https://github.com/cmdr-nova/jekyll-tag-generator
- Owner: cmdr-nova
- Created: 2024-11-20T04:21:05.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-11-20T04:32:01.000Z (11 months ago)
- Last Synced: 2025-03-10T19:45:21.142Z (7 months ago)
- Topics: blog, gen, generator, jekyll, python, tagpage, tags
- Language: Python
- Homepage: https://nova.mkultra.monster/pages/archives/
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Jekyll-Tag-Generator
Do you run a Jekyll blog? Do you use tags to add hashtags to your posts, which, in-turn, creates a sort of archive for your visitors to read through? Are you tired of having to make those tag pages manually, with your fingers and a keybaord, like a *caveman*?Well, buddy, do I have the solution for you!
In your setup, in order for this to work, you should be using a tagpage.html in your _layouts directory that looks something like this:
```
---
layout: default
---
{% for post in site.tags[page.tag] %}
{{ post.title }} ({{ post.date | date_to_string }})
{{ post.description }}
{% endfor %}{% include archive.html %}
```
Obviously, you'll want to change this to reflect your CSS elements properly, and rename things if you like.You should also have a collecttags.html in your _includes directory, that looks like this:
```
{% 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 site.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 %}
```
In head.html in the _includes directory, add this:
```
{% if site.tags != "" %}
{% include collecttags.html %}
{% endif %}
```
Finally, create an archive.html where all of your tags can be viewed, and put it in your _includes directory:
```
{% capture temptags %}
{% for tag in site.tags %}
{{ tag[1].size | plus: 1000 }}#{{ tag[0] }}#{{ tag[1].size }}
{% endfor %}
{% endcapture %}
{% assign sortedtemptags = temptags | split:' ' | sort | reverse %}
{% for temptag in sortedtemptags %}
{% assign tagitems = temptag | split: '#' %}
{% capture tagname %}{{ tagitems[1] }}{% endcapture %}
{{ tagname }}
{% endfor %}
```
Now, take both scripts in this repository and put them in your jekyll blog's root directory, and in terminal run:
```
./serve.sh
```
(of course, only run this while you're building locally, and/or writing new posts, so that the python script creates new tag pages based on tags you're using in your posts)In order for the script to grab tags, a post's front matter should include:
```
tag: [example_tag, tag2]
```
And, of course! Add both generate_tags.py and serve.sh to your .gitignore file, because you have no reason to upload these to your website, or Github Pages. And that's it! Voila!