From 592f8930a9c7c562b48e21f015faeb9b4b4570f1 Mon Sep 17 00:00:00 2001 From: Adaline Simonian Date: Sat, 24 Feb 2024 21:38:55 -0800 Subject: [PATCH] fix: url-er for innleggsbilete i feed.xml og og-metadata --- _includes/post-cards.html | 2 +- _layouts/post.html | 4 ++-- _plugins/modify_post_image_paths.rb | 26 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 _plugins/modify_post_image_paths.rb diff --git a/_includes/post-cards.html b/_includes/post-cards.html index 7f59de6..403b5f6 100644 --- a/_includes/post-cards.html +++ b/_includes/post-cards.html @@ -6,7 +6,7 @@
{{ post.image_alt | default: 'Bilete for innlegget' }} diff --git a/_layouts/post.html b/_layouts/post.html index 405e846..42a79d3 100644 --- a/_layouts/post.html +++ b/_layouts/post.html @@ -18,7 +18,7 @@

{{ page.title | escape }}
@@ -54,7 +54,7 @@

Relaterte innlegg

> Bilete for {{ related_post.title | escape }}
diff --git a/_plugins/modify_post_image_paths.rb b/_plugins/modify_post_image_paths.rb new file mode 100644 index 0000000..1784bcd --- /dev/null +++ b/_plugins/modify_post_image_paths.rb @@ -0,0 +1,26 @@ +module Jekyll + class ModifyPostImagePaths < Generator + priority :high + + def generate(site) + site.posts.docs.each do |post| + if post.data['image'] + # don't modify absolute URLs + if post.data['image'].start_with?('http') + next + end + + asset_dir = if post['draft'] + "assets/attachments/drafts/#{post['slug']}" + else + "assets/attachments/#{post['date'].strftime('%Y/%m/%d')}/#{post['slug']}" + end + + post.data['image'] = "/#{asset_dir}/#{post.data['image']}" + else + post.data['image'] = "/assets/img/card-image-placeholder.png" + end + end + end + end +end