Skip to content

Commit

Permalink
added ability to redirect to external pages
Browse files Browse the repository at this point in the history
  • Loading branch information
AakashGfude committed Mar 17, 2024
1 parent 555f1c8 commit f107cc4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
38 changes: 38 additions & 0 deletions src/quantecon_book_theme/assets/scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,44 @@ document.addEventListener("DOMContentLoaded", function () {
);
})();

/**
* Redirect to a URL and paste the content in admonition
*/
(function () {
let redirect = document.getElementById("redirect");
console.log(redirect, "redirect url");
if (redirect) {
window.location.href =
redirect.getAttribute("data-url") +
"?redirected_from=" +
window.location.pathname +
"&content=" +
redirect.getAttribute("data-content");
}
})();

/**
* Get the path redirected from
*/
(function () {
let redirectedFrom = window.location.search;
if (redirectedFrom.includes("redirected_from")) {
// Create a URLSearchParams object from the query string
var searchParams = new URLSearchParams(redirectedFrom);
// Get the value of a particular variable from the query string
var redirectedFromUrl = searchParams.get("redirected_from");
var redirectedFromContent = searchParams.get("content");
if (redirectedFromContent) {
var admonition = document.getElementsByClassName(
"redirect-admonition",
)[0];
admonition.classList.remove("hidden");
var para = admonition.getElementsByTagName("p")[1];
para.innerHTML = redirectedFromContent;
}
}
})();

/**
* Add authors to the heading of toc page
*/
Expand Down
11 changes: 7 additions & 4 deletions src/quantecon_book_theme/theme/quantecon_book_theme/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,14 @@
<div class="qe-wrapper">

<div class="qe-main">

{%- if pagename in theme_redirects %}
<div id="redirect" data-url="{{theme_redirects[pagename]['url']}}" data-content="{{theme_redirects[pagename]['redirect_text']}}"></div>
{%- endif %}
<div class="qe-page" id={{pagename}}>

<div class="redirect-admonition warning admonition hidden">
<p class="admonition-title">Redirected Page</p>
<p></p>
</div>
<div class="qe-page__toc">

<div class="inner">
Expand All @@ -99,8 +104,6 @@
On this page
</div>
{%- endif %}


<nav id="bd-toc-nav" class="qe-page__toc-nav">
{{ page_toc }}
<p class="logo">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ persistent_sidebar = False
dark_logo =
authors =
mainpage_author_fontsize = 18
redirects =

0 comments on commit f107cc4

Please sign in to comment.