From d8bf19e8688c70df3f723ce02055c2fd9c4ef323 Mon Sep 17 00:00:00 2001 From: Ryan Fox Date: Wed, 22 Jul 2020 17:43:20 +0000 Subject: [PATCH] Add recent posts & tracks to homepage --- pages/index.md | 23 +++++++++++++++-------- scripts/gen_blog.py | 11 ++++++++--- scripts/gen_music.py | 8 ++++++-- scripts/template.py | 11 +++++++++++ static/style.css | 13 ++++++++++++- templates/post_preview_mini.html | 5 +++++ templates/track_preview_mini.html | 4 ++++ 7 files changed, 61 insertions(+), 14 deletions(-) create mode 100644 templates/post_preview_mini.html create mode 100644 templates/track_preview_mini.html diff --git a/pages/index.md b/pages/index.md index 09c34c7..911cbfd 100644 --- a/pages/index.md +++ b/pages/index.md @@ -1,19 +1,26 @@ template: page title: Homepage -license: CC-BY +blog_list_limit: 2 +music_list_limit: 2 # Homepage Ahoy, my name is Ryan Fox. I am a Canadian guy who likes programming and music. -Have you come to [read about me]({root}about{ext})? - -If not, feel free to [read some blog posts]({root}blog/) or -[listen to my music]({root}music/). +Feel free to click on the links in the header to browse this website! --- -## Projects +## Recent posts -* [flewkey-overlay](https://git.sdf.org/flewkey/flewkey-overlay) - My personal Gentoo overlay. -* [minecraft-tweaks-2a03](https://git.sdf.org/flewkey/minecraft-tweaks-2a03) - A basic Minecraft mod. +
+{blog_list} +
+ +--- + +## Recent tracks + +
+{music_list} +
diff --git a/scripts/gen_blog.py b/scripts/gen_blog.py index 1da213c..594ee66 100755 --- a/scripts/gen_blog.py +++ b/scripts/gen_blog.py @@ -3,19 +3,24 @@ import os import sys import markdown -from template import template -def gen_list(files, ext): +def gen_list(files, ext, limit=-1, mini=False): + from template import template md = markdown.Markdown(extensions = ["meta", "extra"]) items = "" + i = 0 for post in files: with open("posts/"+post, "r", encoding="utf-8") as file_in: html = md.convert(file_in.read()) - md.Meta["template"] = "post_preview" + md.Meta["template"] = "post_preview" if not mini else "post_preview_mini" items += template(html, "blog/"+post[:-3]+ext, ext, md.Meta) + i += 1 + if limit >= 0 and i >= limit: + break; return items def main(): + from template import template meta = {"template": "post_list"} ext = "."+sys.argv[2].split(".")[-1] files = sorted(os.listdir(sys.argv[1]), reverse=True) diff --git a/scripts/gen_music.py b/scripts/gen_music.py index ae61b93..00d4147 100755 --- a/scripts/gen_music.py +++ b/scripts/gen_music.py @@ -5,14 +5,18 @@ import sys import json from template import template -def gen_list(music, ext): +def gen_list(music, ext, limit=-1, mini=False): items = "" + i = 0 for track in music: - track["template"] = "track_preview" + track["template"] = "track_preview" if not mini else "track_preview_mini" track["file_size"] = str(os.path.getsize("music/"+track["id"]+".mp3")) if "group" in track: track["group_text"] = "Part of "+track["group"]+"
" items += template("", sys.argv[2], ext, track) + i += 1 + if limit >= 0 and i >= limit: + break; return items def main(): diff --git a/scripts/template.py b/scripts/template.py index aa4dcb1..5a167ed 100644 --- a/scripts/template.py +++ b/scripts/template.py @@ -87,6 +87,17 @@ def template(content, path, ext, meta): meta["date"] = datetime.fromtimestamp(int(meta["timestamp"])).isoformat().split("T")[0] if "pub_date" not in meta and "timestamp" in meta: meta["pub_date"] = utils.format_datetime(datetime.fromtimestamp(int(meta["timestamp"]))) + if "blog_list_limit" in meta: + import gen_blog + import os + files = sorted(os.listdir("posts"), reverse=True) + meta["blog_list"] = gen_blog.gen_list(files, ext, limit=int(meta["blog_list_limit"]), mini=True) + if "music_list_limit" in meta: + import gen_music + import json + with open("music.json", "r", encoding="utf-8") as file: + music = json.loads(file.read()) + meta["music_list"] = gen_music.gen_list(music, ext, limit=int(meta["music_list_limit"]), mini=True) meta["head"] += "\n" meta["content"] = content.format_map(meta) if "description" not in meta and meta["ext"] == ".html": diff --git a/static/style.css b/static/style.css index 98c3c51..d37cfd2 100644 --- a/static/style.css +++ b/static/style.css @@ -100,6 +100,11 @@ p { margin-bottom: 18px; } +div.block-small p { + margin-top: 9px; + margin-bottom: 9px; +} + h1, h2 { line-height: 1; margin-bottom: 32px; @@ -146,7 +151,13 @@ div.block { padding-bottom: 48px; border-top: solid 2px #AAAAAA; } -div.block:first-of-type { + +div.block-small { + padding-top: 32px; + padding-bottom: 32px; +} + +div.block:first-of-type, div.block-small { padding-top: 0; border-top: none; } diff --git a/templates/post_preview_mini.html b/templates/post_preview_mini.html new file mode 100644 index 0000000..9620707 --- /dev/null +++ b/templates/post_preview_mini.html @@ -0,0 +1,5 @@ +
+

{title}

+

{auto_description}

+ Read more +
diff --git a/templates/track_preview_mini.html b/templates/track_preview_mini.html new file mode 100644 index 0000000..04cc4ff --- /dev/null +++ b/templates/track_preview_mini.html @@ -0,0 +1,4 @@ +
+

{name}

+ +