diff --git a/src/quantecon_book_theme/assets/scripts/index.js b/src/quantecon_book_theme/assets/scripts/index.js index 2f28dd6..9b35742 100644 --- a/src/quantecon_book_theme/assets/scripts/index.js +++ b/src/quantecon_book_theme/assets/scripts/index.js @@ -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 */ diff --git a/src/quantecon_book_theme/theme/quantecon_book_theme/layout.html b/src/quantecon_book_theme/theme/quantecon_book_theme/layout.html index 5532d52..93975be 100644 --- a/src/quantecon_book_theme/theme/quantecon_book_theme/layout.html +++ b/src/quantecon_book_theme/theme/quantecon_book_theme/layout.html @@ -85,9 +85,14 @@
- + {%- if pagename in theme_redirects %} +
+ {%- endif %}
- +
@@ -99,8 +104,6 @@ On this page
{%- endif %} - -