tag-wikipeida: apply url encoding on title and allow : inside title
This commit is contained in:
parent
99de73e1fb
commit
bec72b4c5f
1 changed files with 5 additions and 3 deletions
|
@ -6,7 +6,7 @@ function buildArgsHash(args) {
|
||||||
let argsHash = {};
|
let argsHash = {};
|
||||||
args.forEach(arg => {
|
args.forEach(arg => {
|
||||||
const params = arg.split(':');
|
const params = arg.split(':');
|
||||||
argsHash[params[0]] = params[1];
|
argsHash[params[0]] = params.slice(1).join(':');
|
||||||
});
|
});
|
||||||
|
|
||||||
return argsHash;
|
return argsHash;
|
||||||
|
@ -41,11 +41,12 @@ async function requestWikipediaDone(baseUrl) {
|
||||||
async function generatePrefetchedWikipediaTagHtml(args, content) {
|
async function generatePrefetchedWikipediaTagHtml(args, content) {
|
||||||
const argsHash = buildArgsHash(args);
|
const argsHash = buildArgsHash(args);
|
||||||
const title = argsHash['title'];
|
const title = argsHash['title'];
|
||||||
|
const escapedTitle = encodeURIComponent(title);
|
||||||
|
|
||||||
const lang = argsHash['lang'] !== undefined ? argsHash['lang'] : 'en';
|
const lang = argsHash['lang'] !== undefined ? argsHash['lang'] : 'en';
|
||||||
const baseUrl = `https://${lang}.wikipedia.org`;
|
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);
|
await requestWikipediaRequest(baseUrl);
|
||||||
let response = await axios.get(url, {
|
let response = await axios.get(url, {
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -76,11 +77,12 @@ async function generatePrefetchedWikipediaTagHtml(args, content) {
|
||||||
function generateWikipediaTagHtml(args, content) {
|
function generateWikipediaTagHtml(args, content) {
|
||||||
const argsHash = buildArgsHash(args);
|
const argsHash = buildArgsHash(args);
|
||||||
const title = argsHash['title'];
|
const title = argsHash['title'];
|
||||||
|
const escapedTitle = encodeURIComponent(title);
|
||||||
|
|
||||||
const lang = argsHash['lang'] !== undefined ? argsHash['lang'] : 'en';
|
const lang = argsHash['lang'] !== undefined ? argsHash['lang'] : 'en';
|
||||||
const baseUrl = `https://${lang}.wikipedia.org`;
|
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 tagId = "wikipedia-"+Math.round(Math.random() * 100000);
|
||||||
const embeddedScript = `
|
const embeddedScript = `
|
||||||
|
|
Loading…
Reference in a new issue