From b7d8cb87f8d6e1cc8a5a586e3edce2a6def33b12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Bj=C3=B6rklund?= Date: Thu, 14 Nov 2024 21:58:39 +0100 Subject: [PATCH] [PUBLISHER] Merge #115 --- .../posts/publishing-this-blog-from-obsidian.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/content/posts/publishing-this-blog-from-obsidian.md b/content/posts/publishing-this-blog-from-obsidian.md index 662f457..8acb59c 100644 --- a/content/posts/publishing-this-blog-from-obsidian.md +++ b/content/posts/publishing-this-blog-from-obsidian.md @@ -43,6 +43,23 @@ And using this WikiLinks to MDLinks seems to work well. Then I do bit of a hackish solution so it can find the linked files `Pasted image 20241109091858.png` and push them directly to the `static` directory. +## Aaand a small patch for hugo +When using the Enveloppe plugin to export notes to Hugo in the way we are above, the `[[links]]` in our notes are converted to Markdown links without a leading `/`. This means that image paths generated for our content, like `![Image](image.png)`, are relative paths without the leading slash. + +In Hugo, when these relative image paths are rendered into HTML without a leading `/`, they become relative to the current page's URL. I.e it tries to find images under www.pbjorklund.com/post/our-post-name/image.png instead of directly under www.pbjorklund.com/image.png. + +So to "fix Hugo" to work with our wonky setup above we do this in the root of our hugo repo to create a new render hook: + +```bash +mkdir -p layouts/_default/_markup && cat > layouts/_default/_markup/render-image.html <<'EOF' +{{- $src := .Destination -}} +{{- if not (hasPrefix $src "/") -}} + {{- $src = printf "/%s" $src -}} +{{- end -}} +{{ .Text }} +EOF +``` + ## Actually writing posts Now for actually writing the posts I just create a new note in my blog folder and then insert my "hugo frontmatter template" like so: