Back
Version 9
8/22/2023
async function wikitxt(article: string) {
try {
const wiki = await fetch(
`https://en.wikipedia.org/w/api.php?action=query&format=json&titles=${article}&prop=extracts&explaintext`,
).then((res) => res.json());
if (!wiki.query) {
throw new Error("Please input a correct title");
}
const pages = wiki.query.pages;
const txt = pages[Object.keys(pages)[0]].extract;
console.log(txt);
const res = me.fold(txt);
return new Response(res);
}
catch (error) {
throw new Error(`Wiki fetch failed: ${error}`);
}
}
Updated: October 23, 2023