Skip to content

Commit 6e5fae7

Browse files
author
Clemens Vasters
committed
Generate PNG social cards for LinkedIn compatibility
1 parent 0bfcd9a commit 6e5fae7

3 files changed

Lines changed: 18 additions & 6 deletions

File tree

.github/workflows/jekyll-gh-pages.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ jobs:
103103
104104
- name: Generate social cards for blog posts
105105
run: |
106+
sudo apt-get update
107+
sudo apt-get install -y librsvg2-bin
106108
chmod +x scripts/generate-social-cards.sh
107109
./scripts/generate-social-cards.sh
108110

_layouts/post.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77

88
{% seo %}
99

10-
{% assign social_card_path = "/social-cards/" | append: page.slug | append: ".svg" %}
10+
{% assign social_card_path = "/social-cards/" | append: page.slug | append: ".png" %}
1111

12-
<!-- Open Graph / Facebook -->
12+
<!-- Open Graph / Facebook / LinkedIn -->
1313
<meta property="og:type" content="article">
1414
<meta property="og:url" content="{{ page.url | absolute_url }}">
1515
<meta property="og:title" content="{{ page.title | escape }}">
1616
<meta property="og:description" content="{{ page.excerpt | default: page.content | strip_html | truncate: 200 | escape }}">
1717
<meta property="og:image" content="{{ social_card_path | absolute_url }}">
18+
<meta property="og:image:type" content="image/png">
1819
<meta property="og:image:width" content="1200">
1920
<meta property="og:image:height" content="630">
2021
<meta property="og:site_name" content="{{ site.title }}">

scripts/generate-social-cards.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,20 @@ for post_file in "$POSTS_DIR"/*.md; do
105105
title_escaped=$(echo "$title" | sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g')
106106

107107
# Generate SVG
108-
output_file="$SOCIAL_CARDS_DIR/${slug}.svg"
109-
read_template | sed "s/TITLE_PLACEHOLDER/$title_escaped/g" | sed "s/DATE_PLACEHOLDER/$formatted_date/g" > "$output_file"
108+
output_svg="$SOCIAL_CARDS_DIR/${slug}.svg"
109+
read_template | sed "s/TITLE_PLACEHOLDER/$title_escaped/g" | sed "s/DATE_PLACEHOLDER/$formatted_date/g" > "$output_svg"
110110

111-
echo "Generated: $output_file"
111+
echo "Generated: $output_svg"
112+
113+
# Convert SVG to PNG using rsvg-convert (if available)
114+
output_png="$SOCIAL_CARDS_DIR/${slug}.png"
115+
if command -v rsvg-convert &> /dev/null; then
116+
rsvg-convert -w 1200 -h 630 "$output_svg" -o "$output_png"
117+
echo "Generated: $output_png"
118+
else
119+
echo "Warning: rsvg-convert not found, skipping PNG generation for $slug"
120+
fi
112121
fi
113122
done
114123

115-
echo "Social card generation complete!"
124+
echo "Social card generation complete!"

0 commit comments

Comments
 (0)