summaryrefslogtreecommitdiff
path: root/src/routes/api/cv.json/+server.ts
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/cv.json/+server.ts
initial commitHEADprimary
Diffstat (limited to 'src/routes/api/cv.json/+server.ts')
-rw-r--r--src/routes/api/cv.json/+server.ts75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/routes/api/cv.json/+server.ts b/src/routes/api/cv.json/+server.ts
new file mode 100644
index 0000000..956525f
--- /dev/null
+++ b/src/routes/api/cv.json/+server.ts
@@ -0,0 +1,75 @@
+
+
+
+/*** IMPORT ------------------------------------------- ***/
+
+import { error, json } from "@sveltejs/kit";
+
+/*** EXPORT ------------------------------------------- ***/
+
+export const POST = async({ fetch, request }) => {
+ try {
+ const response = await fetch("https://cv.webb.page", {
+ headers: { "Content-Type": "text/plain" },
+ method: "GET"
+ });
+
+ const content = await response.text();
+ return json({ content: processCV(content) });
+ } catch(welp) {
+ console.error(`Error fetching CV: ${String(welp)}`);
+ return error(500);
+ }
+};
+
+/*** HELPER ------------------------------------------- ***/
+
+function processCV(text) {
+ const sections = text.split(/(^░▒▓[\s\S]*?^---$)/m);
+ const intro = sections[1];
+ const body = sections[2];
+ const lines = body.split(/\n{2,}/);
+ const table = processTable(body);
+
+ const processedLines = lines.map(line => {
+ if (line.includes("Proficiency") && line.includes("Notes"))
+ return table.join("").trim();
+
+ return line.replace(/\s+/g, " ");
+ });
+
+ return intro + processedLines.join("\n\n") + "\n\n\n";
+}
+
+function processTable(text) {
+ const lines = text.split(/\r?\n/);
+ const tableStartIndex = lines.findIndex(line => line.includes("|"));
+
+ if (tableStartIndex === -1)
+ return null;
+
+ const separatorLineIndex = lines.findIndex((line, index) => index > tableStartIndex && line.includes("|-") || line.includes("| -"));
+
+ if (separatorLineIndex === -1)
+ return null;
+
+ let tableEndIndex = separatorLineIndex + 1;
+
+ while (tableEndIndex < lines.length && lines[tableEndIndex].includes("|")) {
+ tableEndIndex++;
+ }
+
+ const contentRows = lines.slice(separatorLineIndex + 1, tableEndIndex);
+
+ return contentRows.map(row => {
+ let cells = row.split("|").map(cell => cell.trim());
+
+ if (cells[0] === "")
+ cells.shift();
+
+ if (cells[cells.length - 1] === "")
+ cells.pop();
+
+ return cells.join(" / ") + "\n";
+ });
+}