This workflow action helps in automatically creating archives for GitHub pages built with Jekyll.
_config.yml file to edit your configuration.# Archives
collections:
archives:
output: true
permalink: /archives/:path/
_archives folder_archives in your GitHub pages root.archivedata.txt with the below code.---
---
{
"categories": [
{%- for category in site.categories -%}
"{{ category[0]}}"{% unless forloop.last %},{% endunless %}
{%- endfor -%}
],
"tags": [
{%- for tag in site.tags -%}
"{{ tag[0] }}"{% unless forloop.last %},{% endunless %}
{%- endfor -%}
],
"years": [
{%- for post in site.posts -%}
"{{ post.date | date: "%Y" }}"{% unless forloop.last %},{% endunless %}
{%- endfor -%}
]
}
Build your site and see if you can see the archive data by navigating to your site. (yoursite.com/archives/archivedata)
You should see a json structure like the below one.
{
"categories": [
"Software Testing",
"Excel",
"Blogging",
"Programming",
"Quiz",
"Photography",
"RPA"
],
"tags": [
"Automation Testing",
"UFT",
"QTP",
"Excel VBA"
],
"years": [
"2020",
"2020",
"2019",
"2018",
"2017"
]
}
File was formatted for better reading. This will appear minified on your site.
_layouts folder_layouts folder.archive-categories.htmlarchive-tags.htmlarchive-years.htmlSample layouts and files are present in the folder
blog-filesof this repository. If you are using it make sure to include a file from_includesfolder too.
Do not rename the files in the
_layoutsfolder.
.github and create workflows folder inside it if it doesn't exist.add_archives.yml in the workflows folder. You can name it anything you want.name: Generate Jekyll Archives
# description: Generate categories, tags and years archive files.
on:
workflow_dispatch:
push:
paths:
- "_posts/**"
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Jekyll Blog Archive
uses: kannansuresh/[email protected]
with:
archive_url: "https://yoursite.com/archives/archivedata"
archive_folder_path: "_archives"
- name: setup git config
run: |
git config user.name "GitHub Actions Bot"
git config user.email "<>"
- name: commit
run: |
git add --all
git commit -m "Created and updated archive files." || echo "No changes to commit."
git push origin master || echo "No changes to push."
| Variable Name | Description | Required |
|---|---|---|
archive_url |
Your blog's archive data URL. e.g. yoursite.com/archives/archivedata |
Yes |
archive_folder_path |
Path to your _archives folder. Default value _archives |
Yes |
In the code above, make sure to change the variable
archive_urlto your site's archive data URL.
By default, the code pushes changes to
masterbranch. Change the code if you want the changes to be pushed to a different branch.
The action is set to run every time a commit happens in your
_postsfolder.
Actions tab.Generate Jekyll Archives.Run workflow and run it._archives folder and you will see the archive files generated.To view the archives on your site, use the following URLs.
yoursite.com/category/category_nameyoursite.com/tag/tag_nameyoursite.com/year/2020I have implemented this on my website Aneejian
See the below URLs.