From 0c17ca3a5227f7d951f308cc5b19e01574e0fcbf Mon Sep 17 00:00:00 2001 From: Kilian Cavalotti Date: Wed, 17 Oct 2018 12:53:43 -0700 Subject: [PATCH 1/5] add support for redirects via metadata extension --- docs/extensions/metadata.md | 15 +++++++++++++++ src/main.html | 10 ++++++++++ 2 files changed, 25 insertions(+) diff --git a/docs/extensions/metadata.md b/docs/extensions/metadata.md index 1bf2205af..096240457 100644 --- a/docs/extensions/metadata.md +++ b/docs/extensions/metadata.md @@ -48,6 +48,21 @@ see on the current page when you scroll to the top. It's as simple as: ``` markdown hero: Metadata enables hero teaser texts ``` +### Redirects + +It's sometimes necessary to move documents around in the navigation tree and +redirect user from the old URL to the new one. The `redirect:` meta-tag allows +to create a redirection from the current document to the address specified in +the tag. + +For instance, if your document contains: + +``` markdown +redirect: /new/url + +``` +accessing that document's URL will automatically redirect to `/new/url`. + ### Linking sources diff --git a/src/main.html b/src/main.html index 588cdc78c..37a34506a 100644 --- a/src/main.html +++ b/src/main.html @@ -20,4 +20,14 @@ IN THE SOFTWARE. --> +{% if page.meta.redirect %} + + + +{% else %} + {% extends "base.html" %} + +{% endif %} From dcf6c34284a49db6f585c112738c8ee33fe0cd70 Mon Sep 17 00:00:00 2001 From: Kilian Cavalotti Date: Thu, 18 Oct 2018 08:38:41 -0700 Subject: [PATCH 2/5] redirect: use document.location.replace instead of location.href to avoid storing old URL in browser history --- src/main.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.html b/src/main.html index 37a34506a..df6f50dfe 100644 --- a/src/main.html +++ b/src/main.html @@ -22,7 +22,7 @@ {% if page.meta.redirect %} From 6d713cb8f5dd9c246972ba01cd371f7514d34478 Mon Sep 17 00:00:00 2001 From: Kilian Cavalotti Date: Mon, 26 Nov 2018 15:22:35 -0800 Subject: [PATCH 3/5] redirect: add support to redirect anchors eg. if url.md contains: "redirect: newurl/" //domain.tld/url#foo redirects to //domain.tld/newurl#foo --- src/main.html | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main.html b/src/main.html index df6f50dfe..28ce6c70b 100644 --- a/src/main.html +++ b/src/main.html @@ -22,12 +22,12 @@ {% if page.meta.redirect %} - - -{% else %} - -{% extends "base.html" %} - + + + {% endif %} +{% extends "base.html" %} From 05673a2de6e79a6876596faa52e4a6ea2cce7d1e Mon Sep 17 00:00:00 2001 From: Kilian Cavalotti Date: Tue, 4 Dec 2018 08:38:28 -0800 Subject: [PATCH 4/5] redirect: add metatag to prevent robot indexing --- src/main.html | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.html b/src/main.html index 28ce6c70b..5c5398aa6 100644 --- a/src/main.html +++ b/src/main.html @@ -29,5 +29,6 @@ + {% endif %} {% extends "base.html" %} From 59ce603ed8c6b03bc82b870dd5f20c91d43aa7ca Mon Sep 17 00:00:00 2001 From: squidfunk Date: Fri, 28 Dec 2018 15:09:11 +0100 Subject: [PATCH 5/5] Moved redirect code into main template --- CHANGELOG | 5 +++++ material/base.html | 7 ++++++- src/base.html | 15 ++++++++++++++- src/main.html | 11 ----------- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 51893f203..d0a74d50e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,8 @@ +mkdocs-material-3.2.0 (2018-12-28) + + * Added support for redirects using metadata refresh + * Fixed #921: Load Google Analytics snippet asynchronously + mkdocs-material-3.1.0 (2018-11-17) * Added support for Progressive Web App Manifest diff --git a/material/base.html b/material/base.html index c43facd30..51473e150 100644 --- a/material/base.html +++ b/material/base.html @@ -14,7 +14,12 @@ {% elif config.site_description %} {% endif %} - {% if page.canonical_url %} + {% if page and page.meta and page.meta.redirect %} + + + + + {% elif page.canonical_url %} {% endif %} {% if page and page.meta and page.meta.author %} diff --git a/src/base.html b/src/base.html index e26546293..21e8781b6 100644 --- a/src/base.html +++ b/src/base.html @@ -47,8 +47,21 @@ {% endif %} + + {% if page and page.meta and page.meta.redirect %} + + + + + + + - {% if page.canonical_url %} + {% elif page.canonical_url %} {% endif %} diff --git a/src/main.html b/src/main.html index 5c5398aa6..588cdc78c 100644 --- a/src/main.html +++ b/src/main.html @@ -20,15 +20,4 @@ IN THE SOFTWARE. --> -{% if page.meta.redirect %} - - - - - -{% endif %} {% extends "base.html" %}