From 3ce7e6c1555358aae5d9e96adec2c0410d7ccf84 Mon Sep 17 00:00:00 2001 From: d093w1z Date: Sat, 6 Dec 2025 20:15:18 +0530 Subject: [PATCH] feat: add word lists api endpoints - /api/v1/words.json for word list in JSON format - /api/v1/words.txt for word list in TEXT format --- src/pages/api/v1/words.json.js | 23 +++++++++++++++++++++++ src/pages/api/v1/words.txt.js | 20 ++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 src/pages/api/v1/words.json.js create mode 100644 src/pages/api/v1/words.txt.js diff --git a/src/pages/api/v1/words.json.js b/src/pages/api/v1/words.json.js new file mode 100644 index 0000000..d183c61 --- /dev/null +++ b/src/pages/api/v1/words.json.js @@ -0,0 +1,23 @@ +import { getCollection } from "astro:content"; + +/** + * Get a json file of all jargons (word) from the dictionary + * @param {import("astro").APIContext} context + */ +export async function GET() { + const dictionary = await getCollection("dictionary"); + const words = dictionary.map((word) => { + return word.data.title.toLowerCase(); + }); + const response = { + total: words.length, + words, + }; + + return new Response(JSON.stringify(response), { + status: 200, + headers: { + "Content-type": "application/json", + }, + }); +} diff --git a/src/pages/api/v1/words.txt.js b/src/pages/api/v1/words.txt.js new file mode 100644 index 0000000..cc74505 --- /dev/null +++ b/src/pages/api/v1/words.txt.js @@ -0,0 +1,20 @@ +import { getCollection } from "astro:content"; + +/** + * Get a text file of all jargons (word) from the dictionary + * @param {import("astro").APIContext} context + */ +export async function GET() { + const dictionary = await getCollection("dictionary"); + const words = dictionary.map((word) => { + return word.data.title.toLowerCase(); + }); + const response = "" + words.join("\n"); + + return new Response(response, { + status: 200, + headers: { + "Content-type": "application/txt", + }, + }); +}