Accounting for plus signs in Fextra article names + encoding article titles

pull/400/merge
Kevin Payravi 2024-01-07 05:57:25 -06:00
parent d30b8434de
commit f711d6f945
3 changed files with 28 additions and 2 deletions

View File

@ -310,6 +310,15 @@ async function main(url, tabId) {
// Replace underscores with spaces as that performs better in search
destinationArticle = destinationArticle.replaceAll('_', ' ');
// If a Fextralife wiki, replace plus signs with spaces
// When there are multiple plus signs together, this regex will only replace only the first
if (site['origin_base_url'].includes('.wiki.fextralife.com')) {
destinationArticle = destinationArticle.replace(/(?<!\+)\+/g, ' ');
}
// Encode article
destinationArticle = encodeURIComponent(destinationArticle);
let searchParams = '';
switch (site['destination_platform']) {
case 'mediawiki':

View File

@ -434,6 +434,15 @@ function main() {
// Replace underscores with spaces as that performs better in search
destinationArticle = destinationArticle.replaceAll('_', ' ');
// If a Fextralife wiki, replace plus signs with spaces
// When there are multiple plus signs together, this regex will only replace only the first
if (site['origin_base_url'].includes('.wiki.fextralife.com')) {
destinationArticle = destinationArticle.replace(/(?<!\+)\+/g, ' ');
}
// Encode article
destinationArticle = encodeURIComponent(destinationArticle);
let searchParams = '';
switch (site['destination_platform']) {
case 'mediawiki':
@ -443,8 +452,7 @@ function main() {
searchParams = 'start?do=search&q=' + destinationArticle;
break;
}
newURL = 'https://' + site["destination_base_url"] + site["destination_search_path"] + searchParams.replaceAll('+', '_');
// We replace plus signs with underscores since Fextralife uses pluses instead of spaces/underscores
newURL = 'https://' + site["destination_base_url"] + site["destination_search_path"] + searchParams;
} else {
newURL = 'https://' + site["destination_base_url"];
}

View File

@ -213,6 +213,15 @@ function replaceSearchResults(searchResultContainer, site, link) {
// Replace underscores with spaces as that performs better in search
destinationArticle = destinationArticle.replaceAll('_', ' ');
// If a Fextralife wiki, replace plus signs with spaces
// When there are multiple plus signs together, this regex will only replace only the first
if (site['origin_base_url'].includes('.wiki.fextralife.com')) {
destinationArticle = destinationArticle.replace(/(?<!\+)\+/g, ' ');
}
// Encode article
destinationArticle = encodeURIComponent(destinationArticle);
let searchParams = '';
switch (site['destination_platform']) {
case 'mediawiki':