summaryrefslogtreecommitdiff
path: root/scripts/build_page
diff options
context:
space:
mode:
authorSuleyman Farajli <suleyman@farajli.net>2025-06-24 19:46:28 +0400
committerSuleyman Farajli <suleyman@farajli.net>2025-06-24 19:48:08 +0400
commit6e77e0358abff4fe1997a9da882fae35c44a277a (patch)
tree336e795eeec04cf5e4a415c8fbddf22d74202352 /scripts/build_page
init: first commit
Diffstat (limited to 'scripts/build_page')
-rwxr-xr-xscripts/build_page45
1 files changed, 45 insertions, 0 deletions
diff --git a/scripts/build_page b/scripts/build_page
new file mode 100755
index 0000000..51be92c
--- /dev/null
+++ b/scripts/build_page
@@ -0,0 +1,45 @@
+#!/usr/bin/env python3
+
+import boiler
+from parse_frontmatter import parse_frontmatter
+from pathlib import Path
+import subprocess
+import sys
+
+script_dir = Path(__file__).resolve().parent
+filepath = Path(sys.argv[1]).resolve()
+
+# Parse frontmatter and skip draft posts
+frontmatter = parse_frontmatter(filepath)
+if frontmatter.get("draft"):
+ print(f"{filepath}: is draft", file=sys.stderr)
+ sys.exit(1)
+
+if not frontmatter.get("title"):
+ print(f"{filepath}: title is missing", file=sys.stderr)
+ sys.exit(1)
+
+boiler.print_html_head(frontmatter["title"], frontmatter.get("css"))
+
+# Read file contents and strip frontmatter manually
+inside_frontmatter = False
+content = []
+
+with open(filepath, encoding="utf-8") as f:
+ for line in f:
+ if line.strip() == "---":
+ inside_frontmatter = not inside_frontmatter
+ continue
+ if not inside_frontmatter:
+ content.append(line)
+
+# Convert Markdown to HTML using `smu`
+html = subprocess.run(
+ ["smu"],
+ input="".join(content),
+ text=True,
+ capture_output=True
+).stdout
+
+print(html, end="")
+boiler.print_html_tail()