Removing content prefix from main page redirects

pull/400/merge
Kevin Payravi 2024-01-07 04:18:55 -06:00
parent e314db56c9
commit 6519d31d52
3 changed files with 9 additions and 8 deletions

View File

@ -286,7 +286,7 @@ async function main(url, tabId) {
// We can't just take the last part of the path due to subpages;
// Instead, we take everything after the wiki's base URL + content path
let originArticle = decodeURIComponent(url.split(site['origin_base_url'] + site['origin_content_path'])[1] || '');
let destinationArticle = originArticle;
let destinationArticle = site['destination_content_prefix'] + originArticle;
// Set up URL to redirect user to based on wiki platform
let newURL = '';
if (originArticle) {
@ -307,7 +307,7 @@ async function main(url, tabId) {
let searchParams = '';
switch (site['destination_platform']) {
case 'mediawiki':
searchParams = '?search=' + site['destination_content_prefix'] + destinationArticle;
searchParams = '?search=' + destinationArticle;
break;
case 'doku':
searchParams = 'start?do=search&q=' + destinationArticle;

View File

@ -411,7 +411,7 @@ function main() {
// We can't just take the last part of the path due to subpages;
// Instead, we take everything after the wiki's base URL + content path:
let originArticle = decodeURIComponent(String(origin).split(site['origin_base_url'] + site['origin_content_path'])[1] || '');
let destinationArticle = originArticle;
let destinationArticle = site['destination_content_prefix'] + originArticle;
// Set up URL to redirect user to based on wiki platform:
let newURL = '';
if (originArticle) {
@ -432,7 +432,7 @@ function main() {
let searchParams = '';
switch (site['destination_platform']) {
case 'mediawiki':
searchParams = '?search=' + site['destination_content_prefix'] + destinationArticle;
searchParams = '?search=' + destinationArticle;
break;
case 'doku':
searchParams = 'start?do=search&q=' + destinationArticle;

View File

@ -196,7 +196,7 @@ function escapeRegex(string) {
function replaceSearchResults(searchResultContainer, site, link) {
// Build new URL:
let originArticle = decodeURIComponent((link.split(site['origin_base_url'] + site['origin_content_path'])[1] || '').split('#')[0].split('?')[0].split('&')[0]);
let destinationArticle = originArticle;
let destinationArticle = site['destination_content_prefix'] + originArticle;
let newURL = '';
if (originArticle) {
// Check if main page
@ -216,7 +216,7 @@ function replaceSearchResults(searchResultContainer, site, link) {
let searchParams = '';
switch (site['destination_platform']) {
case 'mediawiki':
searchParams = '?search=' + site['destination_content_prefix'] + destinationArticle;
searchParams = '?search=' + destinationArticle;
break;
case 'doku':
searchParams = 'start?do=search&q=' + destinationArticle;
@ -248,10 +248,11 @@ function replaceSearchResults(searchResultContainer, site, link) {
indieResultFaviconContainer.append(indieResultFavicon);
let indieResultText = document.createElement('span');
if (originArticle && originArticle !== site['origin_main_page']) {
destinationArticleTitle = destinationArticle.replace(site['destination_content_prefix'], '').replaceAll('_', ' ');
if (site['lang'] === 'EN' && link.match(/fandom\.com\/[a-z]{2}\/wiki\//)) {
indieResultText.innerText = 'Look up "' + decodeURIComponent(decodeURIComponent(destinationArticle.replaceAll('_', ' '))) + '" on ' + site.destination + ' (EN)';
indieResultText.innerText = 'Look up "' + decodeURIComponent(decodeURIComponent(destinationArticleTitle)) + '" on ' + site.destination + ' (EN)';
} else {
indieResultText.innerText = 'Look up "' + decodeURIComponent(decodeURIComponent(destinationArticle.replaceAll('_', ' '))) + '" on ' + site.destination;
indieResultText.innerText = 'Look up "' + decodeURIComponent(decodeURIComponent(destinationArticleTitle)) + '" on ' + site.destination;
}
} else {
if (site['lang'] === 'EN' && link.match(/fandom\.com\/[a-z]{2}\/wiki\//)) {