summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorIwanIDev <iwan@iwani.dev>2026-03-21 15:50:35 +0000
committerIwanIDev <iwan@iwani.dev>2026-03-21 15:50:35 +0000
commit76da48766c562c43a65db4e25030ea3acb16d34c (patch)
treedff686cc20b536e0aef90485648e676e23035430 /scripts
parent42ca90ee1f0aadaa09888f1c9627657abcd866b2 (diff)
feat: integrate Openring for webring section and update related files
Diffstat (limited to 'scripts')
-rw-r--r--scripts/generate-openring.mjs56
1 files changed, 56 insertions, 0 deletions
diff --git a/scripts/generate-openring.mjs b/scripts/generate-openring.mjs
new file mode 100644
index 0000000..7400831
--- /dev/null
+++ b/scripts/generate-openring.mjs
@@ -0,0 +1,56 @@
+import { mkdir, readFile, writeFile } from "node:fs/promises";
+import path from "node:path";
+import { fileURLToPath } from "node:url";
+import { spawnSync } from "node:child_process";
+
+const __filename = fileURLToPath(import.meta.url);
+const __dirname = path.dirname(__filename);
+const repoRoot = path.resolve(__dirname, "..");
+
+const openringDir = path.join(repoRoot, "openring");
+const feedsPath = path.join(openringDir, "feeds.txt");
+const templatePath = path.join(openringDir, "template.html");
+const outPath = path.join(openringDir, "out.html");
+
+const fallbackHtml = `<section class="space-y-2">
+ <h2 class="text-2xl font-bold">Around the web</h2>
+ <p class="text-sm text-muted-foreground">Install <code>openring</code> and run <code>bun run openring:generate</code> to render this section.</p>
+</section>
+`;
+
+await mkdir(openringDir, { recursive: true });
+
+try {
+ const template = await readFile(templatePath, "utf8");
+
+ const result = spawnSync("openring", ["-S", feedsPath], {
+ input: template,
+ encoding: "utf8",
+ maxBuffer: 10 * 1024 * 1024,
+ });
+
+ if (result.error) {
+ if (result.error.code === "ENOENT") {
+ console.warn("[openring] binary not found; writing fallback HTML.");
+ await writeFile(outPath, fallbackHtml, "utf8");
+ process.exit(0);
+ }
+ throw result.error;
+ }
+
+ if (result.status !== 0) {
+ console.warn(`[openring] command failed (exit ${result.status}); writing fallback HTML.`);
+ if (result.stderr) {
+ console.warn(result.stderr.trim());
+ }
+ await writeFile(outPath, fallbackHtml, "utf8");
+ process.exit(0);
+ }
+
+ await writeFile(outPath, result.stdout, "utf8");
+ console.log("[openring] generated openring/out.html");
+} catch (error) {
+ console.warn("[openring] unexpected error; writing fallback HTML.");
+ console.warn(error instanceof Error ? error.message : String(error));
+ await writeFile(outPath, fallbackHtml, "utf8");
+}