First attempt to support Stackexchange links

Former-commit-id: dcc10e677e96be2748371b82780bb1b0e250290e [formerly 0ccd9321cf071e480335c69075f234b6c2dce8bf]
Former-commit-id: dcfa5ab5e77ec6a77acaadc096419b2a3f96411e
This commit is contained in:
Jaifroid 2017-12-13 14:12:03 +00:00
parent d3d8da669d
commit b0ac8218fa
2 changed files with 12 additions and 15 deletions

View File

@ -1783,19 +1783,15 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'abstractFile
// Add an onclick event to go to this article
// instead of following the link
if (url.substring(0, 2) === "./") {
url = url.substring(2);
}
// Remove the initial slash if it's an absolute URL
else if (url.substring(0, 1) === "/") {
url = url.substring(1);
}
//Supports stackexchange
else if (url.substring(0, 6) == "../../") {
url = url.substring(6);
//This should match a stackexchange URL and replace with short form
url = url.replace(/([^/]+\/\d+)\/[^/]+(\.html?)/, "$1$2");
}
//Get rid of any absolute or relative prefixes (../, ./../, /../.., etc.)
url = url.replace(/^[.\/]*([\S\s]+)$/, "$1");
//Add namespace if there is an intermedial slash (supports Stackexchange)
//url = url.replace(/^([^\/]+\/[^\/]+[\S\s]+)$/, "A/$1");
//This experimentally shortens the URL for Stackexchange, but I'm not sure it's necessary...
//url = url.replace(/([^/]+\/\d+)\/[^/]+(\.html?)/, "A/$1$2");
$(this).on('click', function (e) {
clearFindInArticle();
//Re-enable top-level scrolling
@ -2284,7 +2280,7 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'abstractFile
selectedArchive.getDirEntryByTitle(title).then(function(dirEntry) {
if (dirEntry === null || dirEntry === undefined) {
$("#readingArticle").hide();
alert("Article with title " + title + " not found in the archive");
console.error("Article with title " + title + " not found in the archive");
}
else {
$("#articleName").html(title);

View File

@ -245,7 +245,8 @@ define(['zimfile', 'zimDirEntry', 'util', 'utf8'],
});
};
var regexpTitleWithoutNameSpace = /^[^\/]+$/;
//Supports Stackexchange [kiwix-js #205]
var regexpTitleWithoutNameSpace = /^(?![\w-]\/[^\/]+?)/;
/**
* Searches a DirEntry (article / page) by its title.