Skip to content

Commit 55960f8

Browse files
committed
feat(scripts): add GIF to WebM converter with markdown update
1 parent 2b26609 commit 55960f8

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"dev": "astro dev",
77
"build": "astro build && npx pagefind --site dist",
88
"preview": "astro preview",
9-
"astro": "astro"
9+
"astro": "astro",
10+
"convert-gif": "bash scripts/convert-gif.sh"
1011
},
1112
"dependencies": {
1213
"@astrojs/mdx": "^4.3.13",

scripts/convert-gif.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "Converting GIFs to WebM..."
5+
find public/img -name '*.gif' -print0 | while IFS= read -r -d '' gif; do
6+
webm="${gif%.gif}.webm"
7+
echo " $gif -> $webm"
8+
ffmpeg -y -i "$gif" -c:v libvpx-vp9 -crf 30 -b:v 0 "$webm" 2>/dev/null
9+
done
10+
11+
echo "Updating markdown files..."
12+
find src/content -name '*.md' -exec perl -i -pe '
13+
s/!\[([^\]]*)\]\(([^)]*?)\.gif\)/<video autoplay loop muted playsinline style="max-width:100%">\n <source src="$2.webm" type="video\/webm">\n<\/video>/g
14+
' {} \;
15+
16+
echo "Removing original GIFs..."
17+
find public/img -name '*.gif' -delete
18+
19+
echo "Done!"

0 commit comments

Comments
 (0)