Support for destination suffixes
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.pull/607/head
parent
3e5a04b486
commit
cd7c4df9a7
|
@ -89,6 +89,7 @@ Entries are formatted as follows:
|
||||||
* `destination`: Name of the wiki being redirected to.
|
* `destination`: Name of the wiki being redirected to.
|
||||||
* `destination_base_url`: Fully qualified domain 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_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_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_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.
|
* `destination_main_page`: The title of the main page of the destination wiki.
|
||||||
|
|
|
@ -92,6 +92,7 @@ async function commonFunctionGetSiteDataByOrigin() {
|
||||||
"destination_base_url": site.destination_base_url,
|
"destination_base_url": site.destination_base_url,
|
||||||
"destination_search_path": site.destination_search_path,
|
"destination_search_path": site.destination_search_path,
|
||||||
"destination_content_prefix": origin.destination_content_prefix || site.destination_content_prefix || "",
|
"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_platform": site.destination_platform,
|
||||||
"destination_icon": site.destination_icon,
|
"destination_icon": site.destination_icon,
|
||||||
"destination_main_page": site.destination_main_page,
|
"destination_main_page": site.destination_main_page,
|
||||||
|
@ -143,7 +144,7 @@ function commonFunctionGetOriginArticle(originURL, matchingSite) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function commonFunctionGetDestinationArticle(matchingSite, article) {
|
function commonFunctionGetDestinationArticle(matchingSite, article) {
|
||||||
return matchingSite['destination_content_prefix'] + article;
|
return matchingSite['destination_content_prefix'] + article + matchingSite['destination_content_suffix'];
|
||||||
}
|
}
|
||||||
|
|
||||||
function commonFunctionGetNewURL(originURL, matchingSite) {
|
function commonFunctionGetNewURL(originURL, matchingSite) {
|
||||||
|
@ -162,7 +163,7 @@ function commonFunctionGetNewURL(originURL, matchingSite) {
|
||||||
destinationArticle = '';
|
destinationArticle = '';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
destinationArticle = matchingSite['destination_main_page'];
|
destinationArticle = matchingSite['destination_main_page'] + matchingSite['destination_content_suffix'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -154,6 +154,13 @@ function escapeRegex(string) {
|
||||||
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
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) {
|
function replaceSearchResults(searchResultContainer, site, link) {
|
||||||
let originArticle = commonFunctionGetOriginArticle(link, site);
|
let originArticle = commonFunctionGetOriginArticle(link, site);
|
||||||
let destinationArticle = commonFunctionGetDestinationArticle(site, originArticle);
|
let destinationArticle = commonFunctionGetDestinationArticle(site, originArticle);
|
||||||
|
@ -180,7 +187,7 @@ function replaceSearchResults(searchResultContainer, site, link) {
|
||||||
indieResultFaviconContainer.append(indieResultFavicon);
|
indieResultFaviconContainer.append(indieResultFavicon);
|
||||||
let indieResultText = document.createElement('span');
|
let indieResultText = document.createElement('span');
|
||||||
if (originArticle && originArticle !== site['origin_main_page']) {
|
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
|
// If a Fextralife wiki, replace plus signs with spaces
|
||||||
// When there are multiple plus signs together, this regex will only replace only the first
|
// When there are multiple plus signs together, this regex will only replace only the first
|
||||||
if (link.includes('.wiki.fextralife.com')) {
|
if (link.includes('.wiki.fextralife.com')) {
|
||||||
|
|
Loading…
Reference in New Issue