From 486daadaf8f5163e372f1d85ea119487149d9a3c Mon Sep 17 00:00:00 2001
From: tezlm
Date: Wed, 9 Oct 2024 14:42:40 -0700
Subject: [PATCH] add extremely janky blog system
---
assets/style2.css | 3 +-
blog/feed.xml | 18 ++++++++
rss.xsl => blog/feed.xsl | 6 +--
blog/genfeed.ts | 93 ++++++++++++++++++++++++++++++++++++++++
blog/hello.html | 20 +++++++++
blog/hello.md | 3 ++
blog/index.html | 22 ++++++++++
rss.xml => rss-old.xml | 0
rss.css | 1 -
9 files changed, 160 insertions(+), 6 deletions(-)
create mode 100644 blog/feed.xml
rename rss.xsl => blog/feed.xsl (95%)
create mode 100644 blog/genfeed.ts
create mode 100644 blog/hello.html
create mode 100644 blog/hello.md
create mode 100644 blog/index.html
rename rss.xml => rss-old.xml (100%)
delete mode 100644 rss.css
diff --git a/assets/style2.css b/assets/style2.css
index 8f12cc7..d11f24d 100644
--- a/assets/style2.css
+++ b/assets/style2.css
@@ -13,7 +13,7 @@ body {
margin: 0;
}
-header, section, main {
+header, section, main, article {
padding: 16px max(calc(50vw - 300px), 16px);
}
@@ -101,7 +101,6 @@ kbd {
box-shadow: 1px 1px #2f2f2f;
}
-
article h1, article h2, article h3, article h4 {
padding-top: 0;
}
diff --git a/blog/feed.xml b/blog/feed.xml
new file mode 100644
index 0000000..f6767f5
--- /dev/null
+++ b/blog/feed.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+ celery rss
+ https://celery.eu.org/blog/feed.xml
+ rss feed for celery.eu.org
+-
+
Hello, world!
+ hello.md
+ https://celery.eu.org/blog/hello.md
+ Hello, world!
+This is a test blog entry for my new blog system.
+
+ 2024-10-09T21:36:44.914Z
+
+
\ No newline at end of file
diff --git a/rss.xsl b/blog/feed.xsl
similarity index 95%
rename from rss.xsl
rename to blog/feed.xsl
index e117b0f..829efea 100644
--- a/rss.xsl
+++ b/blog/feed.xsl
@@ -31,11 +31,11 @@
- Published
+ updated
-
+
-
+
diff --git a/blog/genfeed.ts b/blog/genfeed.ts
new file mode 100644
index 0000000..4eeb42a
--- /dev/null
+++ b/blog/genfeed.ts
@@ -0,0 +1,93 @@
+import { Marked } from "npm:marked@11.1.1";
+import hljs from "npm:highlight.js@11.5.1";
+import { markedHighlight } from "npm:marked-highlight@2.1.0";
+
+const marked = new Marked(
+ markedHighlight({
+ langPrefix: 'hljs language-',
+ highlight(code: string, lang: string) {
+ const language = hljs.getLanguage(lang) ? lang : 'plaintext';
+ return hljs.highlight(code, { language }).value;
+ },
+ })
+)
+
+type Item = {
+ path: string,
+ title: string,
+ content: string,
+ mtime: Date,
+}
+
+const renderMarkdown = (item: Item) => `
+
+
+
+ ${item.title}
+
+
+
+
+
+
+
+
+
+ ${marked.parse(item.content.split("\n").slice(2).join("\n"))}
+
+
+`.trim();
+
+const renderIndex = (entries: Array- ) => {
+ const a = [...entries];
+ a.sort((a, b) => +b.mtime - +a.mtime);
+ return renderMarkdown({
+ title: "index",
+ mtime: new Date(),
+ path: "/index.html",
+ content: "\n\n" + a.map(i => `- [${i.title}](${i.path})`).join("\n"),
+ });
+}
+
+const renderItem = (item: Item) => `
+
-
+
${item.title}
+ ${item.path}
+ https://celery.eu.org/blog/${item.path}
+ ${marked.parse(item.content)}
+ ${item.mtime.toISOString()}
+
+`.trim();
+
+const renderFeed = (entries: Array- ) => `
+
+
+
+
+
+ celery rss
+ https://celery.eu.org/blog/feed.xml
+ rss feed for celery.eu.org
+${entries.map(renderItem)}
+
+`.trim();
+
+const fileNames = [...Deno.readDirSync(".")].filter(i => i.name.endsWith(".md") && i.isFile).map(i => i.name);
+const files: Array- = fileNames.map(i => {
+ const stat = Deno.statSync(i);
+ const text = Deno.readTextFileSync(i);
+ return {
+ title: text.split("\n")[0].slice("# ".length),
+ mtime: stat.mtime!,
+ content: text,
+ path: i,
+ }
+});
+
+Deno.writeTextFileSync("feed.xml", renderFeed(files));
+Deno.writeTextFileSync("index.html", renderIndex(files));
+for (const file of files) {
+ Deno.writeTextFileSync(file.path.replace(/\.md$/, ".html"), renderMarkdown(file));
+}
diff --git a/blog/hello.html b/blog/hello.html
new file mode 100644
index 0000000..23aac74
--- /dev/null
+++ b/blog/hello.html
@@ -0,0 +1,20 @@
+
+
+
+
Hello, world!
+
+
+
+
+
+
+
+
+
+ This is a test blog entry for my new blog system.
+
+
+
+
\ No newline at end of file
diff --git a/blog/hello.md b/blog/hello.md
new file mode 100644
index 0000000..4bf335d
--- /dev/null
+++ b/blog/hello.md
@@ -0,0 +1,3 @@
+# Hello, world!
+
+This is a test blog entry for my new blog system.
diff --git a/blog/index.html b/blog/index.html
new file mode 100644
index 0000000..ae3cca4
--- /dev/null
+++ b/blog/index.html
@@ -0,0 +1,22 @@
+
+
+
+ index
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/rss.xml b/rss-old.xml
similarity index 100%
rename from rss.xml
rename to rss-old.xml
diff --git a/rss.css b/rss.css
deleted file mode 100644
index 8b13789..0000000
--- a/rss.css
+++ /dev/null
@@ -1 +0,0 @@
-