Skip to content

Commit

Permalink
Add script to warmup URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
kamranahmedse committed May 13, 2024
1 parent 4a40d89 commit 22d4f18
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"best-practice-dirs": "node scripts/best-practice-dirs.cjs",
"best-practice-content": "node scripts/best-practice-content.cjs",
"generate:og": "node ./scripts/generate-og-images.mjs",
"warm:og": "sh ./scripts/warm-og.sh https://roadmap.sh/sitemap-0.xml",
"warm:urls": "sh ./scripts/warm-urls.sh https://roadmap.sh/sitemap-0.xml",
"compress:images": "tsx ./scripts/compress-images.ts",
"test:e2e": "playwright test"
},
Expand Down
12 changes: 9 additions & 3 deletions scripts/warm-og.sh → scripts/warm-urls.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

# Usage: warm-og.sh <sitemap-url>
# Example: warm-og.sh https://www.example.com/sitemap.xml
# Usage: warm-urls.sh <sitemap-url>
# Example: warm-urls.sh https://www.example.com/sitemap.xml

# Check if sitemap url is provided
if [ -z "$1" ]; then
Expand All @@ -19,9 +19,15 @@ for url in $urls; do
# Fetch the og:image URL from the meta tags
og_image_url=$(curl -s "$url" | grep -o "<meta property=\"og:image\" content=\"[^\"]*\"" | sed 's#<meta property="og:image" content="\([^"]*\)"#\1#')

# warm the URL
echo "Warming up URL: $url"
if ! curl -s -I "$url" > /dev/null; then
failed_urls+=("$url")
fi

# Warm up the og:image URL
if [ -n "$og_image_url" ]; then
echo "Warming up $og_image_url"
echo "Warming up OG: $og_image_url"
if ! curl -s -I "$og_image_url" > /dev/null; then
failed_urls+=("$og_image_url")
fi
Expand Down

0 comments on commit 22d4f18

Please sign in to comment.