From cada10189147b32539311b325f08ace0f7647230 Mon Sep 17 00:00:00 2001 From: madrilene Date: Fri, 7 Mar 2025 17:52:51 +0100 Subject: [PATCH] redirects same line, use in example post --- src/common/_redirects.njk | 16 +++++++--------- .../2022/2022-08-28-post-with301-redirects.md | 1 + 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/common/_redirects.njk b/src/common/_redirects.njk index a2957b5..b4ac56b 100644 --- a/src/common/_redirects.njk +++ b/src/common/_redirects.njk @@ -3,12 +3,10 @@ permalink: /_redirects eleventyExcludeFromCollections: true excludeFromSitemap: true --- - -{% for page in collections.all %} - {% if page.url and page.data.redirectFrom %} - {% for oldUrl in page.data.redirectFrom %} - {{ oldUrl }} - {{ page.url }} - {% endfor %} - {% endif %} -{% endfor %} +{%- for page in collections.all -%} +{%- if page.url and page.data.redirectFrom -%} +{%- for oldUrl in page.data.redirectFrom %} +{{ oldUrl }} {{ page.url }} +{%- endfor %} +{%- endif -%} +{%- endfor -%} \ No newline at end of file diff --git a/src/posts/2022/2022-08-28-post-with301-redirects.md b/src/posts/2022/2022-08-28-post-with301-redirects.md index 40eadea..2ff93e1 100644 --- a/src/posts/2022/2022-08-28-post-with301-redirects.md +++ b/src/posts/2022/2022-08-28-post-with301-redirects.md @@ -3,6 +3,7 @@ title: 'Post with 301 redirects' description: 'A 301 is used when a page has permanently changed location. Informing about this change is indispensable if you want to keep a positioning. Aleksandr Hovhannisyan came up with an elegant solution for Eleventy and Netlify.' date: 2022-08-28 tags: ['redirects', 'feature'] +redirectFrom: ['/old-route/', '/optionally-another-old-route/'] --- URLs usually change over time, as you use another CMS or optimize your file structure.