summaryrefslogtreecommitdiff
path: root/src/routes/api/blog.json
diff options
context:
space:
mode:
authornetop://ウィビ <paul@webb.page>2026-04-11 14:42:43 -0700
committernetop://ウィビ <paul@webb.page>2026-04-11 14:42:43 -0700
commitb052f741d935abd2f51423abf3fcda9157844b5c (patch)
treed01d9db0e4c4f4f9093662a049db366b8b2301af /src/routes/api/blog.json
initial commitHEADprimary
Diffstat (limited to 'src/routes/api/blog.json')
-rw-r--r--src/routes/api/blog.json/+server.ts51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/routes/api/blog.json/+server.ts b/src/routes/api/blog.json/+server.ts
new file mode 100644
index 0000000..f416647
--- /dev/null
+++ b/src/routes/api/blog.json/+server.ts
@@ -0,0 +1,51 @@
+
+
+
+/*** IMPORT ------------------------------------------- ***/
+
+import { error, json } from "@sveltejs/kit";
+
+/*** EXPORT ------------------------------------------- ***/
+
+export const POST = async({ fetch, request }) => {
+ try {
+ const { filename } = await request.json();
+
+ const response = await fetch(`https://blog.webb.page/${String(filename)}`, {
+ headers: { "Content-Type": "text/plain" },
+ method: "GET"
+ });
+
+ const memo = parseMemo(await response.text());
+ memo.push(` <span class="special-char">[</span><a href="https://blog.webb.page/${String(filename).split(".txt")[0]}">READ</a><span class="special-char">]</span>`, "\n");
+
+ return json({ content: memo.join("\n") });
+ } catch(welp) {
+ console.error(`Error fetching memo: ${String(welp)}`);
+ return error(500);
+ }
+};
+
+/*** HELPER ------------------------------------------- ***/
+
+function parseMemo(text: string): string {
+ const intro = text.split(/^Body$/m)[0];
+ const lines = intro.split("\n").filter(Boolean);
+ const format = [""];
+ let firstLine = "";
+
+ lines.map((line, index) => {
+ if (index === 1)
+ firstLine = " " + line.split(/\s+\B/)[1].trim();
+
+ if (index === 2) {
+ firstLine += ` • ${line.trim()}`;
+ format.push(firstLine);
+ }
+
+ if (index === 4)
+ format.push(" " + line.trim());
+ });
+
+ return format;
+}