diff --git a/scripts/wikipedia.js b/scripts/wikipedia.js index 46e3ff8..af06413 100644 --- a/scripts/wikipedia.js +++ b/scripts/wikipedia.js @@ -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 = `