summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUser Mms <mms@voyager.local>2024-10-26 00:29:30 +0200
committerUser Mms <mms@voyager.local>2024-10-26 00:29:30 +0200
commitc661a9b52905b32b836bb17efd07dea523e54cb0 (patch)
tree09266f357adc4853cba5cbbf246218f55ba0b7a0
parentc6ec3365c880da134c35e6552642535e822604e6 (diff)
feat(blog): moving pages
-rw-r--r--content-org/blog.org41
-rw-r--r--content/blog/2024/moving-pages-in-hugo.md43
2 files changed, 83 insertions, 1 deletions
diff --git a/content-org/blog.org b/content-org/blog.org
index 65d7748..9bbd31e 100644
--- a/content-org/blog.org
+++ b/content-org/blog.org
@@ -8,7 +8,7 @@
#+HUGO_SECTION: blog
-* 2024 [85/87] :@blog:
+* 2024 [86/88] :@blog:
:PROPERTIES:
:EXPORT_HUGO_SECTION: blog/2024
:EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :image_dir "blog/images" :image_max_width 600
@@ -122,6 +122,45 @@ It's small annoyance, but it shows the general direction.
Microsoft GitHub is still not near the biggest sin an Open Source can commit when it comes to cooperation (that crown still goes to using Discord), but it's far from being "Open".
+** DONE Moving pages in Hugo
+CLOSED: [2024-10-26 Sat 00:29]
+:PROPERTIES:
+:EXPORT_FILE_NAME: moving-pages-in-hugo
+:EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :Abstract How to move pages without annoying everyone
+:EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :Listening Moonspell - Alma Matter
+:END:
+
+Moving =.html= files around is great fun, but can annoy visitors.
+Linkrot is a nightmare, and =Hugo= has terrible idea on what an =guid= of a page is.
+
+First, =RSS=.
+By default, Hugo uses the =permalink= as =id= of each item.
+So, when we move a file, the id changes, and RSS readers will treat it a new file.
+To fix this, we need to have our own rss layout.
+Grab the original one from [[https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/_default/rss.xml][Microsoft GitHub]] and create a new layout file =rss.xml=.
+Then, adjust =channel.item.guid= (line 54 as of this moment) and put something unique there.
+I use Publishing date:
+
+#+begin_src xml
+<guid>{{ crypto.MD5 .Date }}</guid>
+#+end_src
+
+Now, moving pages will be invisible to RSS readers.
+But then we've got the old links.
+What we want is to have automatic redirects to new locations.
+Hugo has it built in as [[https://gohugo.io/methods/page/aliases/][aliases]].
+You can add =aliases= key in front matter of any page.
+Hugo will create an .html file with redirect in place of each alias you define
+
+#+begin_src md
+...
+aliases = ["/contact/", "/me/contact/", "/blog/contact/"]
+...
+#+end_src
+
+Note, that aliases work only for =single= pages.
+If you want an =list= to redirect to a new location, you need to use something external, like nginx redirects.
+
** DONE Docker free since 2024
CLOSED: [2024-10-25 Fri 23:24]
:PROPERTIES:
diff --git a/content/blog/2024/moving-pages-in-hugo.md b/content/blog/2024/moving-pages-in-hugo.md
new file mode 100644
index 0000000..942df70
--- /dev/null
+++ b/content/blog/2024/moving-pages-in-hugo.md
@@ -0,0 +1,43 @@
++++
+title = "Moving pages in Hugo"
+author = ["MichaƂ Sapka"]
+date = 2024-10-26T00:29:00+02:00
+categories = ["blog"]
+draft = false
+weight = 2001
+image_dir = "blog/images"
+image_max_width = 600
+Abstract = "How to move pages without annoying everyone"
+Listening = "Moonspell - Alma Matter"
++++
+
+Moving `.html` files around is great fun, but can annoy visitors.
+Linkrot is a nightmare, and `Hugo` has terrible idea on what an `guid` of a page is.
+
+First, `RSS`.
+By default, Hugo uses the `permalink` as `id` of each item.
+So, when we move a file, the id changes, and RSS readers will treat it a new file.
+To fix this, we need to have our own rss layout.
+Grab the original one from [Microsoft GitHub](https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/_default/rss.xml) and create a new layout file `rss.xml`.
+Then, adjust `channel.item.guid` (line 54 as of this moment) and put something unique there.
+I use Publishing date:
+
+```xml
+<guid>{{ crypto.MD5 .Date }}</guid>
+```
+
+Now, moving pages will be invisible to RSS readers.
+But then we've got the old links.
+What we want is to have automatic redirects to new locations.
+Hugo has it built in as [aliases](https://gohugo.io/methods/page/aliases/).
+You can add `aliases` key in front matter of any page.
+Hugo will create an .html file with redirect in place of each alias you define
+
+```md
+...
+aliases = ["/contact/", "/me/contact/", "/blog/contact/"]
+...
+```
+
+Note, that aliases work only for `single` pages.
+If you want an `list` to redirect to a new location, you need to use something external, like nginx redirects.