Skip to content

Commit 1b70ab2

Browse files
authored
feature: add redirect from old blog post location (#1209)
1 parent f9f8e3b commit 1b70ab2

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

src/posts/first-post.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ draft: false
55
description: Creating a blog!
66
tags:
77
- intro
8+
redirect_from:
9+
- /blog/first-post
810
---
911

1012
I have been building a [homelab](https://www.reddit.com/r/homelab/wiki/introduction) for the last few years, mostly to [self-host](https://www.reddit.com/r/selfhosted/) services securely at home without relying on the major cloud providers. I've learned a lot going through the experience and wanted to start sharing some of the knowledge back to the community outside of a few tiny pull requests that I've made. Look for more coming soon!

src/posts/moar-fediverse.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ tags:
88
- fediverse
99
- homelab
1010
- selfhosted
11+
redirect_from:
12+
- /blog/moar-fediverse
1113
---
1214

1315
I've been running a single user Mastodon instance for a few months now. It's been running smoothly and has let me interact with the exodus of users from the bird site. But it can be lonely on a single user instance. Discovery can be hard, following #hashtags only shows you posts from

src/posts/tailscale-hostnames-for-pi-hole-stats.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ tags:
77
- tailscale
88
- pi-hole
99
- magicdns
10+
redirect_from:
11+
- /blog/tailscale-hostnames-for-pi-hole-stats
1012
---
1113
[Tailscale](https://tailscale.com) is a fantastic secure mesh VPN that lets you connect all of your devices to each other, no matter where they are or if you've exposed them publicly to the internet. I use it extensively to use all my homelab services and run it on virtually every server. They have a very generous free tier and hope that enthusiasts enjoy it so much that they bring it to their workplace.
1214

src/redirect.njk

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---js
2+
{
3+
pagination: {
4+
data: "collections.all",
5+
size: 1,
6+
alias: "redirect",
7+
before: function (data) {
8+
return data.reduce((redirects, page) => {
9+
if (Array.isArray(page.data.redirect_from)) {
10+
for (let url of page.data.redirect_from) {
11+
redirects.push({ to: page.url, from: url });
12+
}
13+
} else if (typeof page.data.redirect_from === 'string') {
14+
redirects.push({ to: page.url, from: page.data.redirect_from });
15+
}
16+
return redirects;
17+
}, []);
18+
},
19+
addAllPagesToCollections: false,
20+
},
21+
permalink: "{{ redirect.from }}/index.html",
22+
eleventyExcludeFromCollections: true,
23+
}
24+
---
25+
<!DOCTYPE html>
26+
<html lang="en-US">
27+
<meta charset="utf-8" />
28+
<title>Redirecting&hellip;</title>
29+
<link rel="canonical" href="{{ redirect.to | url }}" />
30+
<script>
31+
location = '{{ redirect.to | url }}';
32+
</script>
33+
<meta http-equiv="refresh" content="0; url={{ redirect.to | url }}" />
34+
<meta name="robots" content="noindex" />
35+
<h1>Redirecting&hellip;</h1>
36+
<a href="{{ redirect.to | url }}">Click here if you are not redirected.</a>
37+
</html>

0 commit comments

Comments
 (0)