Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Added ability to redirect to external pages #246

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
run: |
git clone https://github.com/executablebooks/sphinx-exercise.git
cd sphinx-exercise
python setup.py install
python -m pip install .
cd ../ && rm -rf sphinx-exercise
- name: Install Dependencies
shell: bash -l {0}
Expand Down
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 =
Loading