jordan gist felülvizsgálása 4 hours ago. Revízióhoz ugrás
1 file changed, 12 insertions
wikitxt.ts(fájl létrehozva)
| @@ -0,0 +1,12 @@ | |||
| 1 | + | import { fetch } from "https://esm.town/v/std/fetch"; | |
| 2 | + | import { fold } from "https://esm.town/v/jordan/fold"; | |
| 3 | + | ||
| 4 | + | export const wikitxt = async (req: Request) => { | |
| 5 | + | const url = new URL(req.url), article = url.pathname.replace("/", ""), width = parseInt(url.searchParams.get("width")); | |
| 6 | + | const wiki = await fetch(`https://en.wikipedia.org/w/api.php?action=query&format=json&titles=${article}&prop=extracts&explaintext`).then(res => res.json()); | |
| 7 | + | if (!wiki.query) return new Response("Please input a correct title") | |
| 8 | + | const pages = wiki.query.pages; | |
| 9 | + | const txt = pages[Object.keys(pages)[0]].extract; | |
| 10 | + | const res = width ? fold(txt, width) : fold(txt); | |
| 11 | + | return new Response(res); | |
| 12 | + | } | |
Újabb
Régebbi