diff --git a/README.md b/README.md index 9c7582b..98d6624 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,7 @@ Entries are formatted as follows: * `destination`: Name of the wiki being redirected to. * `destination_base_url`: Fully qualified domain name of the wiki being redirected to. * `destination_content_prefix`: A prefix that is prepended to article names before performing a search on the destination wiki. This can be useful if a wiki separates its content into different namespaces. For example, if we wanted to redirect a wiki about Super Mario Odyssey to a general Mario wiki that has Odyssey content in a namespace called `Odyssey`, we would set `destination_content_prefix` to `Odyssey:`. +* `destination_content_suffix`: A suffix that is added to the end of article names before performing a search on the destination wiki. This is typically used when a multilingual wiki separates its languages by suffixes (e.g. `/es`, `/pt`, etc.). Team Fortress Wiki is an example that uses this. * `destination_platform`: The wiki's software. The current supported options are `mediawiki` and `dokuwiki`. If you are contributing a wiki that is on another wiki platform, please open an issue so that support for the platform can be added. * `destination_icon`: The name of the wiki's favicon in the [favicons](favicons) folder. * `destination_main_page`: The title of the main page of the destination wiki. diff --git a/scripts/common-functions.js b/scripts/common-functions.js index 0e362e5..a5002e4 100644 --- a/scripts/common-functions.js +++ b/scripts/common-functions.js @@ -92,6 +92,7 @@ async function commonFunctionGetSiteDataByOrigin() { "destination_base_url": site.destination_base_url, "destination_search_path": site.destination_search_path, "destination_content_prefix": origin.destination_content_prefix || site.destination_content_prefix || "", + "destination_content_suffix": origin.destination_content_suffix || site.destination_content_suffix || "", "destination_platform": site.destination_platform, "destination_icon": site.destination_icon, "destination_main_page": site.destination_main_page, @@ -143,7 +144,7 @@ function commonFunctionGetOriginArticle(originURL, matchingSite) { } function commonFunctionGetDestinationArticle(matchingSite, article) { - return matchingSite['destination_content_prefix'] + article; + return matchingSite['destination_content_prefix'] + article + matchingSite['destination_content_suffix']; } function commonFunctionGetNewURL(originURL, matchingSite) { @@ -162,7 +163,7 @@ function commonFunctionGetNewURL(originURL, matchingSite) { destinationArticle = ''; break; default: - destinationArticle = matchingSite['destination_main_page']; + destinationArticle = matchingSite['destination_main_page'] + matchingSite['destination_content_suffix']; } } diff --git a/scripts/content-search-filtering.js b/scripts/content-search-filtering.js index 025eeda..ef3163f 100644 --- a/scripts/content-search-filtering.js +++ b/scripts/content-search-filtering.js @@ -154,6 +154,13 @@ function escapeRegex(string) { return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); } +function removeSubstringIfAtEnd(str, sub) { + if (sub && str.endsWith(sub)) { + return str.slice(0, -sub.length); + } + return str; +} + function replaceSearchResults(searchResultContainer, site, link) { let originArticle = commonFunctionGetOriginArticle(link, site); let destinationArticle = commonFunctionGetDestinationArticle(site, originArticle); @@ -180,7 +187,7 @@ 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('_', ' '); + let destinationArticleTitle = removeSubstringIfAtEnd(destinationArticle, site['destination_content_suffix']).replace(site['destination_content_prefix'], '').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 (link.includes('.wiki.fextralife.com')) {