mirror of
https://github.com/kiwix/kiwix-js.git
synced 2025-09-23 12:36:21 -04:00
Redirect links to other languages of the article to the online version of wikipedia
Fixes #15
This commit is contained in:
parent
97dadfdd76
commit
76e6fdcd6e
@ -201,6 +201,7 @@ define(function(require) {
|
|||||||
$('#articleContent').html(htmlArticle);
|
$('#articleContent').html(htmlArticle);
|
||||||
|
|
||||||
// Convert links into javascript calls
|
// Convert links into javascript calls
|
||||||
|
var regex = /^\.?\/?\.\.\/([^\/]+)\/(.*)/;
|
||||||
$('#articleContent').find('a').each(function(){
|
$('#articleContent').find('a').each(function(){
|
||||||
// Store current link's url
|
// Store current link's url
|
||||||
var url = $(this).attr("href");
|
var url = $(this).attr("href");
|
||||||
@ -212,7 +213,10 @@ define(function(require) {
|
|||||||
// It's an external link : do nothing
|
// It's an external link : do nothing
|
||||||
}
|
}
|
||||||
else if (url.substring(0,2) === ".." || url.substring(0,4) === "./..") {
|
else if (url.substring(0,2) === ".." || url.substring(0,4) === "./..") {
|
||||||
// It's a link to another language : TODO redirect to the online article?
|
// It's a link to another language : change the URL to the online version of wikipedia
|
||||||
|
// The regular expression extracts $1 as the language, and $2 as the title name
|
||||||
|
var onlineWikipediaUrl = url.replace(regex, "https://$1.wikipedia.org/wiki/$2");
|
||||||
|
$(this).attr("href",onlineWikipediaUrl);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// It's a link to another article : add an onclick event to go to this article
|
// It's a link to another article : add an onclick event to go to this article
|
||||||
|
Loading…
x
Reference in New Issue
Block a user