Última atividade 4 hours ago

jordan's Avatar jordan revisou este gist 4 hours ago. Ir para a revisão

1 file changed, 12 insertions

wikitxt.ts(arquivo criado)

@@ -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 + }
Próximo Anterior