tag-wikipeida: apply url encoding on title and allow : inside title

This commit is contained in:
thisLight 2022-01-04 14:45:46 +08:00
parent 99de73e1fb
commit bec72b4c5f

View file

@ -6,7 +6,7 @@ function buildArgsHash(args) {
let argsHash = {};
args.forEach(arg => {
const params = arg.split(':');
argsHash[params[0]] = params[1];
argsHash[params[0]] = params.slice(1).join(':');
});
return argsHash;
@ -41,11 +41,12 @@ async function requestWikipediaDone(baseUrl) {
async function generatePrefetchedWikipediaTagHtml(args, content) {
const argsHash = buildArgsHash(args);
const title = argsHash['title'];
const escapedTitle = encodeURIComponent(title);
const lang = argsHash['lang'] !== undefined ? argsHash['lang'] : 'en';
const baseUrl = `https://${lang}.wikipedia.org`;
const url = `${baseUrl}/api/rest_v1/page/summary/${title}`;
const url = `${baseUrl}/api/rest_v1/page/summary/${escapedTitle}`;
await requestWikipediaRequest(baseUrl);
let response = await axios.get(url, {
headers: {
@ -76,11 +77,12 @@ async function generatePrefetchedWikipediaTagHtml(args, content) {
function generateWikipediaTagHtml(args, content) {
const argsHash = buildArgsHash(args);
const title = argsHash['title'];
const escapedTitle = encodeURIComponent(title);
const lang = argsHash['lang'] !== undefined ? argsHash['lang'] : 'en';
const baseUrl = `https://${lang}.wikipedia.org`;
const url = `${baseUrl}/api/rest_v1/page/summary/${title}?redirect=false`;
const url = `${baseUrl}/api/rest_v1/page/summary/${escapedTitle}?redirect=false`;
const tagId = "wikipedia-"+Math.round(Math.random() * 100000);
const embeddedScript = `