diff options
author | Suleyman Farajli <suleyman@farajli.net> | 2025-06-24 18:37:57 +0400 |
---|---|---|
committer | Suleyman Farajli <suleyman@farajli.net> | 2025-06-24 18:37:57 +0400 |
commit | dd71f019de0314f7b3f2ae1e0aa920e49e9f2759 (patch) | |
tree | 5b8513c4f2e7959eb45de75d93f331506b1cbd43 /scripts/generate_post_index | |
parent | 014901951cc44a70ff3d4aaa4246592b08699d69 (diff) |
refactor: everything chageddev
Diffstat (limited to 'scripts/generate_post_index')
-rwxr-xr-x | scripts/generate_post_index | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/scripts/generate_post_index b/scripts/generate_post_index new file mode 100755 index 0000000..44aa756 --- /dev/null +++ b/scripts/generate_post_index @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 + +from parse_frontmatter import parse_frontmatter +from pathlib import Path + +def generate_post_index(): + script_dir = Path(__file__).parent.resolve() + posts_directory = script_dir / "../content/posts" + posts = [] + for file in posts_directory.iterdir(): + if file.is_file() and file.name != "index.md": + frontmatter=parse_frontmatter(file.resolve()) + frontmatter["filename"] = file.name + if frontmatter["draft"]: + continue + posts.append(frontmatter) + + sorted_posts = sorted(posts, key=lambda x: x["created"], reverse=True) + + for i in sorted_posts: + html_file = i['filename'].replace(".md", ".html") + print(f"<time>{i['created']}:</time> [{i['title']}](/posts/{html_file})\n") + +print("""--- +title: "Posts" +slug: "posts" +css: | + time { + font-size: 16px; + color: #bbbbbb; + padding-right: 0.5em; + } +---""") + +generate_post_index() |