Skip to content

Commit

Permalink
fix: url-er for innleggsbilete i feed.xml og og-metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
adalinesimonian committed Feb 25, 2024
1 parent 51067f5 commit 592f893
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion _includes/post-cards.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="d-none d-md-flex col-md-7 col-lg-6 col-xl-5">
<a href="{{ post.url | relative_url }}">
<img
src="{{ post.image | post_asset_path: post | fallback_path: '/assets/img/card-image-placeholder.png' | relative_url }}"
src="{{ post.image | relative_url }}"
class="rounded-start object-fit-cover w-100 h-100"
alt="{{ post.image_alt | default: 'Bilete for innlegget' }}"
>
Expand Down
4 changes: 2 additions & 2 deletions _layouts/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h1 class="post-title p-name" itemprop="name headline">{{ page.title | escape }}
<div class="position-relative popout-lg-medium popout-xl-large px-0 py-1 py-md-3 py-lg-3 py-xl-5 text-center">
<img
class="u-featured img-fluid"
src="{{ page.image | post_asset_path | fallback_path: '/assets/img/card-image-placeholder.png' | relative_url }}"
src="{{ page.image | relative_url }}"
alt=""
>
</div>
Expand Down Expand Up @@ -54,7 +54,7 @@ <h3>Relaterte innlegg</h3>
>
<img
class="card-img-top"
src="{{ related_post.image | post_asset_path | fallback_path: '/assets/img/card-image-placeholder.png' | relative_url }}"
src="{{ related_post.image | relative_url }}"
alt="Bilete for {{ related_post.title | escape }}"
>
<div class="card-body p-2">
Expand Down
26 changes: 26 additions & 0 deletions _plugins/modify_post_image_paths.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 592f893

Please sign in to comment.