|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Generate social card PNGs from template SVGs |
| 4 | +# Requires: |
| 5 | +# - librsvg (install with: brew install librsvg) |
| 6 | +# - zopfli (install with: brew install zopfli) |
| 7 | +# - Mona Sans font (install with: brew install --cask font-mona-sans) |
| 8 | + |
| 9 | +set -e |
| 10 | + |
| 11 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 12 | + |
| 13 | +# Check for required CLI tools |
| 14 | +if ! command -v rsvg-convert &> /dev/null; then |
| 15 | + echo "Error: rsvg-convert not found. Install with: brew install librsvg" |
| 16 | + exit 1 |
| 17 | +fi |
| 18 | + |
| 19 | +if ! command -v zopflipng &> /dev/null; then |
| 20 | + echo "Error: zopflipng not found. Install with: brew install zopfli" |
| 21 | + exit 1 |
| 22 | +fi |
| 23 | + |
| 24 | +# Check for Mona Sans font |
| 25 | +if ! fc-list | grep -qi "Mona Sans"; then |
| 26 | + echo "Error: Mona Sans font not found. Install with: brew install --cask font-mona-sans" |
| 27 | + exit 1 |
| 28 | +fi |
| 29 | + |
| 30 | +# Labels to generate from template (filename:Label Text) |
| 31 | +LABELS=( |
| 32 | + "account-and-profile:Account" |
| 33 | + "actions:Actions" |
| 34 | + "admin:Admin" |
| 35 | + "apps:Apps" |
| 36 | + "authentication:Auth" |
| 37 | + "billing:Billing" |
| 38 | + "code-security:Security" |
| 39 | + "codespaces:Codespaces" |
| 40 | + "communities:Community" |
| 41 | + "contributing:Contributing" |
| 42 | + "copilot:Copilot" |
| 43 | + "desktop:Desktop" |
| 44 | + "discussions:Discussions" |
| 45 | + "education:Education" |
| 46 | + "enterprise-onboarding:Enterprise" |
| 47 | + "get-started:Get Started" |
| 48 | + "github-cli:GitHub CLI" |
| 49 | + "github-models:Models" |
| 50 | + "graphql:GraphQL" |
| 51 | + "integrations:Integrations" |
| 52 | + "issues:Issues" |
| 53 | + "migrations:Migrations" |
| 54 | + "nonprofit:Nonprofit" |
| 55 | + "organizations:Orgs" |
| 56 | + "packages:Packages" |
| 57 | + "pages:Pages" |
| 58 | + "pull-requests:Pull requests" |
| 59 | + "repositories:Repositories" |
| 60 | + "rest:REST" |
| 61 | + "search-github:Search" |
| 62 | + "site-policy:Site Policy" |
| 63 | + "sponsors:Sponsors" |
| 64 | + "subscriptions-and-notifications:Account" |
| 65 | + "support:Support" |
| 66 | + "webhooks:Webhooks" |
| 67 | +) |
| 68 | + |
| 69 | +# Generate default.png from _default.svg |
| 70 | +echo "Converting _default.svg to default.png..." |
| 71 | +rsvg-convert -w 1200 -h 628 "$SCRIPT_DIR/_default.svg" -o "$SCRIPT_DIR/default.png" |
| 72 | +echo "Optimizing default.png with zopflipng..." |
| 73 | +zopflipng -y "$SCRIPT_DIR/default.png" "$SCRIPT_DIR/default.png" |
| 74 | + |
| 75 | +# Generate labeled PNGs from _template.svg |
| 76 | +for entry in "${LABELS[@]}"; do |
| 77 | + filename="${entry%%:*}" |
| 78 | + label="${entry##*:}" |
| 79 | + png="$SCRIPT_DIR/$filename.png" |
| 80 | + |
| 81 | + echo "Generating $filename.png with label \"$label\"..." |
| 82 | + sed "s/{{LABEL}}/$label/g" "$SCRIPT_DIR/_template.svg" | rsvg-convert -w 1200 -h 628 -o "$png" |
| 83 | + echo "Optimizing $filename.png with zopflipng..." |
| 84 | + zopflipng -y "$png" "$png" |
| 85 | +done |
| 86 | + |
| 87 | +echo "Done!" |
0 commit comments