1
0

Add recent posts & tracks to homepage

This commit is contained in:
Ryan Fox 2020-07-22 17:43:20 +00:00
parent ca5c8a5bdc
commit d8bf19e868
Signed by: flewkey
GPG Key ID: 94F56ADFD848851E
7 changed files with 61 additions and 14 deletions

View File

@ -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.
<div>
{blog_list}
</div>
---
## Recent tracks
<div>
{music_list}
</div>

View File

@ -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)

View File

@ -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"] = "<span>Part of "+track["group"]+"</span><br/>"
items += template("", sys.argv[2], ext, track)
i += 1
if limit >= 0 and i >= limit:
break;
return items
def main():

View File

@ -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<link rel=\"canonical\" href=\""+meta["base"]+meta["full_path"]+"\"/>"
meta["content"] = content.format_map(meta)
if "description" not in meta and meta["ext"] == ".html":

View File

@ -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;
}

View File

@ -0,0 +1,5 @@
<div class="block-small">
<a href="{full_path}"><h3>{title}</h3></a>
<p>{auto_description}</p>
<a href="{full_path}">Read more</a>
</div>

View File

@ -0,0 +1,4 @@
<div id="audio_{id}" class="player block-small">
<h4>{name}</h4>
<audio controls style="width: 100%"><source src="{id}.mp3" type="audio/mpeg"/></audio>
</div>