-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
78 lines (61 loc) · 2 KB
/
Copy pathmain.py
File metadata and controls
78 lines (61 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from lib.runners_sh_website.solstice import *
from os import path
import os
from itertools import chain
pages_path = "pages"
blog_path = path.join(pages_path, "blog")
def generate_path_parts(p):
path_parts = []
acc = "/"
for part in path.split(p):
acc = path.join(acc, part)
path_parts.append((part, acc))
if path_parts[0][0] == "":
del path_parts[0]
return path_parts
def build_blog(ssg: SiteGenerator) -> list[dict]:
all_posts = []
for root, dirs, files in os.walk(blog_path):
output_root = path.relpath(root, pages_path)
posts = []
for file in files:
name, ext = path.splitext(file)
if ext not in [".md"]:
continue
src_path = path.join(root, file)
dist_path = path.join(output_root, name + ".html")
pg = MarkdownPage(ssg, "blog/post.jinja", src_path, dist_path)
pg.set_params(path_parts=generate_path_parts(output_root))
if not pg.meta.get("hidden", False):
posts.append(
pg.meta | {"url": "/" + dist_path.removesuffix(".html")}
)
pg.build()
all_posts += posts
if output_root != blog_path:
pg = Page(
ssg,
"blog/index.jinja",
path.join(output_root, "index.html"),
)
pg.set_params(
posts=posts, path_parts=generate_path_parts(output_root)
)
pg.build()
all_posts.sort(key=lambda x: x["date"], reverse=True)
ssg.page(
"blog/index.jinja",
posts=all_posts,
path_parts=generate_path_parts("blog"),
)
return all_posts
ssg = SiteGenerator()
@cli.entrypoint(ssg)
def build():
ssg.copy("public")
posts = build_blog(ssg)
index = Page(ssg, "index.jinja")
index_content, _, _ = ssg.load_md("pages/index.md")
index.set_params(content=index_content)
index.set_params(posts=posts[:3])
index.build()