summaryrefslogtreecommitdiff
path: root/scripts
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
init: first commit
Diffstat (limited to 'scripts')
-rw-r--r--scripts/boiler.py55
-rwxr-xr-xscripts/build_page45
-rwxr-xr-xscripts/filter_proper_md14
-rwxr-xr-xscripts/generate_post_index35
-rw-r--r--scripts/parse_frontmatter.py19
5 files changed, 168 insertions, 0 deletions
diff --git a/scripts/boiler.py b/scripts/boiler.py
new file mode 100644
index 0000000..b5d75f4
--- /dev/null
+++ b/scripts/boiler.py
@@ -0,0 +1,55 @@
+import textwrap
+
+def print_html_head(title, style=None):
+ print(textwrap.dedent(f"""\
+ <!DOCTYPE html>
+ <html lang="en">
+ <head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=1024">
+ <link rel='stylesheet' type='text/css' href="/style.css">
+ <link rel="icon" type="image/x-icon" href="/favicon.ico">
+ <title>{title}</title>"""))
+
+ if style:
+ print(textwrap.dedent(f"""\
+ <style>
+ {style}
+ </style>"""))
+
+ print(textwrap.dedent("""\
+ </head>
+ <body>
+ <table id="bar">
+ <tr>
+ <td id='header-name'>Suleyman Farajli</td>
+ <td id='quote'></td>
+ </tr>
+ </table>
+ <script>
+ let quotes = ["Uncensored", "Oh mamma mia!", "Memento Mori!", "Oh là là!", "C'est légal parce que je le veux", "Sweet Dreams Are Made of This"];
+ let randomQuote = quotes[Math.floor(Math.random() * quotes.length)];
+ document.getElementById("quote").innerText = randomQuote;
+ </script>
+
+ <hr class="separator">
+
+ <div class="menu">
+ <a class="menu_item" href="/home/index.html">Home/</a>
+ <a class="menu_item" href="/posts/index.html">Posts/</a>
+ <a class="menu_item" href="/archive/index.html">Archive/</a>
+ <a class="menu_item" href="/keys/index.html">Keys/</a>
+ <a class="menu_item right_menu_item" href="https://git.farajli.net">Git</a>
+ </div>
+ <div class="text">"""))
+
+def print_html_tail():
+ print(textwrap.dedent("""\
+ </div>
+ <p>
+ <a id="copyleft" href="https://creativecommons.org/licenses/by-sa/4.0/" target="_blank" rel="noopener noreferrer">
+ copyleft (c) 2024-2025 Suleyman Farajli
+ </a>
+ </p>
+ </body>
+ </html>"""))
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()
diff --git a/scripts/filter_proper_md b/scripts/filter_proper_md
new file mode 100755
index 0000000..ed1be7f
--- /dev/null
+++ b/scripts/filter_proper_md
@@ -0,0 +1,14 @@
+#!/usr/bin/env python3
+
+import sys
+from parse_frontmatter import parse_frontmatter
+from pathlib import Path
+
+def isproper(file):
+ frontmatter = parse_frontmatter(file)
+ if not frontmatter.get("draft"):
+ print(file)
+
+script_dir = Path(__file__).resolve().parent
+for arg in sys.argv[1:]:
+ isproper(arg)
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()
diff --git a/scripts/parse_frontmatter.py b/scripts/parse_frontmatter.py
new file mode 100644
index 0000000..2d5c60e
--- /dev/null
+++ b/scripts/parse_frontmatter.py
@@ -0,0 +1,19 @@
+import yaml
+
+def parse_frontmatter(filepath):
+ with open(filepath, 'r', encoding='utf-8') as f:
+ lines = f.readlines()
+
+ if not lines or lines[0].strip() != '---':
+ return {}
+
+ frontmatter_lines = []
+ for line in lines[1:]:
+ if line.strip() == '---':
+ break
+ frontmatter_lines.append(line)
+
+ frontmatter_str = ''.join(frontmatter_lines)
+ frontmatter = yaml.safe_load(frontmatter_str) or {}
+
+ return frontmatter