Skip to content

Commit 6c67897

Browse files
authored
fix(bluesky): pass embed metadata directly to avoid OG parsing issues (#3)
Adds optional embed_title, embed_description, and embed_image_url inputs to the bluesky-post workflow. When provided, these values are used directly instead of parsing OG tags from the URL. This fixes an issue where titles containing apostrophes (e.g., "It's") were being truncated due to the OG tag regex stopping at quote characters. Also fixes the OG tag regex to use backreferences for proper quote matching as a fallback when metadata is not provided.
1 parent 3b528e8 commit 6c67897

File tree

1 file changed

+44
-18
lines changed

1 file changed

+44
-18
lines changed

.github/workflows/bluesky-post.yml

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,19 @@ on:
88
required: true
99
type: string
1010
embed_url:
11-
description: 'Optional URL to create a website card embed from (fetches OG tags)'
11+
description: 'Optional URL to create a website card embed from'
12+
required: false
13+
type: string
14+
embed_title:
15+
description: 'Optional title for the embed card (avoids fetching from OG tags)'
16+
required: false
17+
type: string
18+
embed_description:
19+
description: 'Optional description for the embed card (avoids fetching from OG tags)'
20+
required: false
21+
type: string
22+
embed_image_url:
23+
description: 'Optional image URL for the embed card (avoids fetching from OG tags)'
1224
required: false
1325
type: string
1426
secrets:
@@ -25,6 +37,9 @@ jobs:
2537
env:
2638
POST_INPUT: ${{ toJSON(inputs.post_text) }}
2739
EMBED_URL: ${{ inputs.embed_url }}
40+
EMBED_TITLE: ${{ inputs.embed_title }}
41+
EMBED_DESCRIPTION: ${{ inputs.embed_description }}
42+
EMBED_IMAGE_URL: ${{ inputs.embed_image_url }}
2843
run: |
2944
# Authenticate with BlueSky
3045
echo "Authenticating with BlueSky..."
@@ -119,10 +134,17 @@ jobs:
119134
# Build embed if URL provided
120135
EMBED=""
121136
if [ -n "$EMBED_URL" ]; then
122-
echo "Fetching OG tags from: $EMBED_URL"
137+
# Use provided metadata or fetch from OG tags
138+
OG_TITLE="$EMBED_TITLE"
139+
OG_DESC="$EMBED_DESCRIPTION"
140+
OG_IMAGE="$EMBED_IMAGE_URL"
141+
142+
# Only fetch OG tags if we're missing required metadata
143+
if [ -z "$OG_TITLE" ] || [ -z "$OG_IMAGE" ]; then
144+
echo "Fetching OG tags from: $EMBED_URL"
123145
124-
# Fetch page and extract OG tags using Python
125-
EMBED_DATA=$(python3 << 'PYEOF'
146+
# Fetch page and extract OG tags using Python
147+
EMBED_DATA=$(python3 << 'PYEOF'
126148
import urllib.request
127149
import re
128150
import json
@@ -139,30 +161,34 @@ jobs:
139161
with urllib.request.urlopen(req, timeout=10) as response:
140162
html = response.read().decode('utf-8', errors='ignore')
141163
142-
# Extract OG tags
143-
og_title = re.search(r'<meta[^>]*property=["\']og:title["\'][^>]*content=["\']([^"\']+)["\']', html, re.I)
144-
og_title = og_title.group(1) if og_title else ''
164+
# Extract OG tags using backreferences to handle quotes in content
165+
og_title = re.search(r'<meta[^>]*property=["\']og:title["\'][^>]*content=(["\'])(.+?)\1', html, re.I)
166+
og_title = og_title.group(2) if og_title else ''
145167
146-
og_desc = re.search(r'<meta[^>]*property=["\']og:description["\'][^>]*content=["\']([^"\']+)["\']', html, re.I)
147-
og_desc = og_desc.group(1) if og_desc else ''
168+
og_desc = re.search(r'<meta[^>]*property=["\']og:description["\'][^>]*content=(["\'])(.+?)\1', html, re.I)
169+
og_desc = og_desc.group(2) if og_desc else ''
148170
149-
og_image = re.search(r'<meta[^>]*property=["\']og:image["\'][^>]*content=["\']([^"\']+)["\']', html, re.I)
150-
og_image = og_image.group(1) if og_image else ''
171+
og_image = re.search(r'<meta[^>]*property=["\']og:image["\'][^>]*content=(["\'])(.+?)\1', html, re.I)
172+
og_image = og_image.group(2) if og_image else ''
151173
152174
print(json.dumps({'title': og_title, 'description': og_desc, 'image': og_image}))
153175
except Exception as e:
154176
print(json.dumps({'error': str(e)}), file=sys.stderr)
155177
print(json.dumps({}))
156178
PYEOF
157-
)
179+
)
158180
159-
OG_TITLE=$(echo "$EMBED_DATA" | jq -r '.title // empty')
160-
OG_DESC=$(echo "$EMBED_DATA" | jq -r '.description // empty')
161-
OG_IMAGE=$(echo "$EMBED_DATA" | jq -r '.image // empty')
181+
# Use fetched values only for missing metadata
182+
[ -z "$OG_TITLE" ] && OG_TITLE=$(echo "$EMBED_DATA" | jq -r '.title // empty')
183+
[ -z "$OG_DESC" ] && OG_DESC=$(echo "$EMBED_DATA" | jq -r '.description // empty')
184+
[ -z "$OG_IMAGE" ] && OG_IMAGE=$(echo "$EMBED_DATA" | jq -r '.image // empty')
185+
else
186+
echo "Using provided embed metadata"
187+
fi
162188
163-
echo "OG Title: $OG_TITLE"
164-
echo "OG Description: $OG_DESC"
165-
echo "OG Image: $OG_IMAGE"
189+
echo "Embed Title: $OG_TITLE"
190+
echo "Embed Description: $OG_DESC"
191+
echo "Embed Image: $OG_IMAGE"
166192
167193
if [ -n "$OG_TITLE" ]; then
168194
# Upload image as blob if present

0 commit comments

Comments
 (0)