mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-09-15 15:27:11 -04:00
First attempt to support Stackexchange links
Former-commit-id: dcc10e677e96be2748371b82780bb1b0e250290e [formerly 0ccd9321cf071e480335c69075f234b6c2dce8bf] Former-commit-id: dcfa5ab5e77ec6a77acaadc096419b2a3f96411e
This commit is contained in:
parent
d3d8da669d
commit
b0ac8218fa
@ -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);
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user