diff options
author | Minteck <contact@minteck.org> | 2022-01-09 18:22:55 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-01-09 18:22:55 +0100 |
commit | 7d0d6272c8bf5260da53210c8ed327980e396397 (patch) | |
tree | 6812176231961767e9b7aa731193abb387bbc107 /update | |
parent | dc65563df84d80bcc0970febef6a5f9a7759bdcb (diff) | |
download | ponyfind-7d0d6272c8bf5260da53210c8ed327980e396397.tar.gz ponyfind-7d0d6272c8bf5260da53210c8ed327980e396397.tar.bz2 ponyfind-7d0d6272c8bf5260da53210c8ed327980e396397.zip |
Update
Diffstat (limited to 'update')
-rw-r--r-- | update/infobox.js | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/update/infobox.js b/update/infobox.js index faaf943..e27177e 100644 --- a/update/infobox.js +++ b/update/infobox.js @@ -14,7 +14,14 @@ console.log("Gathering infobox for each page..."); let mwextracts = (await axios.get("https://mlp.fandom.com/api.php?format=json&action=query&prop=extracts&exlimit=max&explaintext&exintro&titles=" + encodeURI(page.name) + "&redirects=")).data; let extracts = ""; try { - extracts = mwextracts.query.pages[Object.keys(mwextracts.query.pages)[0]].extract.replace(/(.*)\n(.*)/, "$2").replace(/(.*)\n\n(.*)/gm, "$2").replace(/([.?!])\s*(?=[A-Z])/g, "$1|").split("|")[0]; + sentences = mwextracts.query.pages[Object.keys(mwextracts.query.pages)[0]].extract.replace(/(.*)\n(.*)/, "$2").replace(/(.*)\n\n(.*)/gm, "$2").replace(/([.?!])\s*(?=[A-Z])/g, "$1|").split("|"); + extracts = sentences[0]; + if (extracts.length < 150 && sentences.length > 1) { + extracts = sentences[0] + " " + sentences[1]; + if (extracts.length < 150 && sentences.length > 2) { + extracts = sentences[0] + " " + sentences[1] + " " + sentences[2]; + } + } } catch (e) { extracts = ""; } |