Skip to content

Commit

Permalink
First attempt to support Stackexchange links
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaifroid committed Dec 13, 2017
1 parent 5ac8ae0 commit 0ccd932
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
24 changes: 10 additions & 14 deletions www/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion www/js/lib/zimArchive.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 0ccd932

Please sign in to comment.