Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
aider: Generated the
index.md
file dynamically using Zola templatin…
…g language. # Aider chat conversation: USER: is there a way to generate the index.md file from the blog entries (which should also provide their date) rather than creating it manually? ASSISTANT: Yes, we can create a script to generate the `index.md` file from the blog entries. This script will read the metadata from each blog entry and generate the `index.md` file accordingly. Let's create a new Python script `generate_blog_index.py` to achieve this: generate_blog_index.py ```python <<<<<<< SEARCH ======= import os import frontmatter BLOG_DIR = "content/blog" INDEX_FILE = os.path.join(BLOG_DIR, "index.md") def generate_index(): blog_entries = [] for filename in os.listdir(BLOG_DIR): if filename.endswith(".md") and filename != "index.md": filepath = os.path.join(BLOG_DIR, filename) with open(filepath, 'r') as f: post = frontmatter.load(f) title = post['title'] date = post['date'] url = f"/blog/{filename.replace('.md', '')}/" blog_entries.append((title, date, url)) blog_entries.sort(key=lambda x: x[1], reverse=True) with open(INDEX_FILE, 'w') as f: f.write("+++\ntitle = \"Freenet Blog\"\n+++\n\n") for title, date, url in blog_entries: f.write(f"[{title}]({url})\n\n{date}\n\n") if __name__ == "__main__": generate_index() >>>>>>> REPLACE ``` This script will: 1. Read all markdown files in the `content/blog` directory. 2. Extract the title and date from the front matter of each file. 3. Generate the `index.md` file with links to each blog entry, sorted by date in descending order. You can run this script whenever you add new blog entries to regenerate the `index.md` file. USER: no, I don't mean with a python script, I mean using the zola templating language ASSISTANT: To generate the `index.md` file using the Zola templating language, we can use a template to list all the blog entries dynamically. We will create a new template file for the blog index and update the `index.md` to use this template. First, let's create a new template file `templates/blog_index.html`: templates/blog_index.html ```html <<<<<<< SEARCH ======= {% extends "base.html" %} {% block content %} <h1>{{ page.title }}</h1> <ul> {% for section in sections %} {% for page in section.pages %} <li> <a href="{{ page.permalink }}">{{ page.title }}</a><br> {{ page.date | date(format="long") }} </li> {% endfor %} {% endfor %} </ul> {% endblock content %} >>>>>>> REPLACE ``` Next, we need to update `content/blog/index.md` to use this new template: content/blog/index.md ```markdown <<<<<<< SEARCH +++ title = "Freenet Blog" +++ [Weekly Dev Meeting - Gateway deployment, freenet-chat](/blog/1127-weekly-dev-meeting-gateway-deployment-freenet-chat/) 10th June, 2024 [Weekly Dev Meeting - Enhancing Connection Stability and Finalizing Transport Fixes](/blog/1097-weekly-dev-meeting-enhancing-connection-stability-and-finalizing-transport-fixes/) 24th May, 2024 [Weekly dev meeting - network integration testing and squashing final bugs](/blog/1081-weekly-dev-meeting-network-integration-testing-and-squashing-final-bugs/) 11th May, 2024 [Weekly dev meeting - progressing Towards Network Stability](/blog/1074-weekly-dev-meeting-progressing-towards-network-stability/) 3rd May, 2024 [Weekly developer meeting summary](/blog/1067-weekly-developer-meeting-summary/) 28th April, 2024 [Weekly developer meeting summary](/blog/1048-weekly-developer-meeting-summary/) 17th April, 2024 [Weekly developer meeting summary](/blog/1035-weekly-developer-meeting-summary/) 12th April, 2024 [Weekly developer meeting summary](/blog/1030-weekly-developer-meeting-summary/) 5th April, 2024 [Weekly Developer Meeting: Updating State and Performance Optimizations](/blog/900-weekly-developer-meeting-updating-state-and-performance-optimizations/) 22nd November, 2023 [Zero-Knowledge Proofs and Anonymous Reputation in Freenet](/blog/882-zero-knowledge-proofs-and-anonymous-reputation-in-freenet/) 29th October, 2023 [Proof-of-Trust: A Wealth-Unbiased Consensus Mechanism for Distributed Systems](/blog/799-proof-of-trust-a-wealth-unbiased-consensus-mechanism-for-distributed-systems/) 28th August, 2023 [Mitigating Sybil attacks in Freenet](/blog/456-mitigating-sybil-attacks-in-freenet/) 26th June, 2022 ======= +++ title = "Freenet Blog" template = "blog_index.html" +++ >>>>>>> REPLACE ``` These changes will allow Zola to dynamically generate the blog index page using the `blog_index.html` template. The template will list all the blog entries with their titles and dates.
- Loading branch information