Commit d1786645 authored by Jacek Lebioda's avatar Jacek Lebioda
Browse files

fix: corrected router's code

parent bb4365ec
......@@ -15,54 +15,69 @@
});
}
// define URLs
var internalURL = 'https://r3-core.pages.uni.lu/howto-cards-internal';
var externalURL = 'https://r3.pages.uni.lu/howto-cards';
UrlExists(internalURL+'/index.html', function(status){
function GetShortcutDestination() {
var s = window.location.href;
var pathArray = s.split('?');
// cut the query if it exists
// Cut the query if it exists
if (pathArray.length > 1) {
sub = pathArray[1];
return pathArray[1];
} else {
sub = '';
return '';
}
}
// Pick the shortcut link destination from URL, like: `category:subcategory:card-name`
var sub = GetShortcutDestination();
// Define URLs
var internalPortalURL = 'https://r3-core.pages.uni.lu/howto-cards-internal';
var externalPortalURL = 'https://r3.pages.uni.lu/howto-cards';
// First, check whether internal pages are accessible...
var internalIndexURL = internalPortalURL + '/index.html';
UrlExists(internalIndexURL, function(status){
if(status === 200){
// internal pages
// If the internal pages are accessible, try to redirect into correct page
if (sub.length > 0) {
UrlExists(internalURL+'/stable/internal/'+sub, function(status){
if (status == 200) { // if sub-card is internal in the internal directory and exists
window.location.href = internalURL+'/stable/internal/cards/'+sub;
var internalCardURL = internalPortalURL + '/stable/internal/cards/' + sub;
UrlExists(internalCardURL, function(status){
if (status == 200) { // The sub-card is internal, and is accessible
window.location.href = internalCardURL;
} else {
UrlExists(internalURL+'/stable/external/'+sub, function(status){
UrlExists(internalPortalURL + '/stable/external/' + sub, function(status){
if (status == 200) { // if sub-card is internal in the external directory and exists
window.location.href = internalURL+'/stable/external/cards/'+sub;
window.location.href = internalPortalURL + '/stable/external/cards/' + sub;
} else {
window.location.href = internalURL+'/stable/404.html';
window.location.href = internalPortalURL + '/stable/404.html';
}
});
}
});
} else {
UrlExists(internalURL+'/stable', function(status){
if (status == 200) { // if card is internal and exists
window.location.href = internalURL+'/stable';
} else {
// The user did not request specific card, redirect him just to the stable index
var internalPortalIndexURL = internalPortalURL + '/stable';
var internalPortal404URL = internalPortalURL + '/stable/404.html';
UrlExists(internalPortalIndexURL, function(status){
if (status == 200) { // if page is accessible
window.location.href = internalPortalIndexURL;
} else {
window.location.href = internalURL+'/stable/404.html';
window.location.href = internalPortal404URL;
}
});
}
// external pages
} else {
if (sub.length > 0) { sub = 'external/'+sub; }
UrlExists(externalURL+'/stable/cards/'+sub, function(status){
// The internal pages are not accessible, therefore the user is redirected into correct external page
if (sub.length > 0) {
sub = 'external/cards/' + sub;
}
var externalPortalCardURL = externalPortalURL + '/stable/' + sub;
var externalPortal404URL = externalPortalURL + '/stable/404.html';
UrlExists(externalPortalURL + '/stable/' + sub, function(status){
if (status == 200) { // if sub-card is internal and exists
window.location.href = externalURL+'/stable/cards/'+sub;
window.location.href = externalPortalCardURL;
} else {
window.location.href = externalURL+'/stable/404.html';
window.location.href = externalPortal404URL;
}
});
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment