-
Notifications
You must be signed in to change notification settings - Fork 18
Fix handbook Slack unfurl with dynamic OG images #4432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dimitrieh
wants to merge
18
commits into
main
Choose a base branch
from
fix/handbook-slack-unfurl
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
bf6b217
Fix handbook Slack unfurl with better meta tags
dimitrieh 8bfce71
Add dynamic OG image generation for handbook pages
dimitrieh 145feb2
Fix date formatting errors in templates by ensuring Date objects
dimitrieh a3eda3c
Remove article date metadata from handbook pages
dimitrieh 620280a
Add headers configuration for OG image endpoint
dimitrieh 7720a2c
Use Heebo font and brand colors in OG images
dimitrieh a63af4f
Fix edge function import for og-edge
dimitrieh cc96138
Load Heebo font properly in OG image edge function
dimitrieh 10509de
Fix Google Fonts API syntax to load single weight
dimitrieh a554057
Load both regular and semibold Heebo font weights
dimitrieh 9b7c71a
Rename og-image.jsx to og-image.tsx
dimitrieh a6c26a5
Merge branch 'main' into fix/handbook-slack-unfurl
dimitrieh ebae57b
Fix OG image edge function Satori compatibility
dimitrieh a9f21b6
Merge branch 'main' into fix/handbook-slack-unfurl
dimitrieh 241b8fe
Extract first paragraph from markdown for og:description
dimitrieh 763c48d
og-image: use path-based title and first paragraph as description
dimitrieh 5897474
Fix link rewriting bug causing malformed HTML
dimitrieh a2f961d
Add trailing slashes when stripping .md extensions
dimitrieh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| import React from "https://esm.sh/react@18.2.0"; | ||
| import { ImageResponse } from "https://deno.land/x/og_edge/mod.ts"; | ||
|
|
||
| async function loadGoogleFont(font: string, text: string) { | ||
| const url = `https://fonts.googleapis.com/css2?family=${font}&text=${encodeURIComponent(text)}`; | ||
| const css = await (await fetch(url)).text(); | ||
| const resource = css.match(/src: url\((.+)\) format\('(opentype|truetype)'\)/); | ||
|
|
||
| if (resource) { | ||
| const response = await fetch(resource[1]); | ||
| if (response.status == 200) { | ||
| return await response.arrayBuffer(); | ||
| } | ||
| } | ||
|
|
||
| throw new Error('failed to load font data'); | ||
| } | ||
|
|
||
| export default async (request: Request) => { | ||
| const { searchParams } = new URL(request.url); | ||
|
|
||
| // Get parameters from URL | ||
| const title = searchParams.get('title') || 'Handbook'; | ||
| const description = searchParams.get('description') || ''; | ||
| const section = searchParams.get('section') || ''; | ||
|
|
||
| // Combine all text for font loading | ||
| const allText = `${title} ${description} ${section} Handbook •`; | ||
|
|
||
| // Load Heebo fonts (regular and semibold) | ||
| const heeboRegular = await loadGoogleFont('Heebo:wght@400', allText); | ||
| const heeboSemibold = await loadGoogleFont('Heebo:wght@600', allText); | ||
|
|
||
| return new ImageResponse( | ||
| ( | ||
| <div | ||
| style={{ | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| width: '100%', | ||
| height: '100%', | ||
| backgroundColor: '#ffffff', | ||
| padding: '60px', | ||
| fontFamily: 'Heebo', | ||
| }} | ||
| > | ||
| {/* Header with logo and badge */} | ||
| <div | ||
| style={{ | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| gap: '20px', | ||
| marginBottom: '40px', | ||
| }} | ||
| > | ||
| {/* FlowFuse Logo */} | ||
| <img | ||
| src="https://flowfuse.com/handbook/images/logos/ff-icon--light.png" | ||
| width="80" | ||
| height="80" | ||
| /> | ||
|
|
||
| {/* Handbook badge with section */} | ||
| <div | ||
| style={{ | ||
| fontSize: '48px', | ||
| color: '#6B7280', | ||
| fontWeight: '600', | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| gap: '16px', | ||
| }} | ||
| > | ||
| <span style={{ color: '#111827' }}>Handbook</span> | ||
| {section && ( | ||
| <div style={{ display: 'flex', alignItems: 'center', gap: '16px' }}> | ||
| <span style={{ color: '#D1D5DB' }}>•</span> | ||
| <span style={{ textTransform: 'capitalize', color: '#9CA3AF' }}>{section}</span> | ||
| </div> | ||
| )} | ||
| </div> | ||
| </div> | ||
|
|
||
| {/* Title */} | ||
| <div | ||
| style={{ | ||
| fontSize: '64px', | ||
| fontWeight: 'bold', | ||
| color: '#111827', | ||
| lineHeight: 1.1, | ||
| marginBottom: '30px', | ||
| maxWidth: '100%', | ||
| overflow: 'hidden', | ||
| textOverflow: 'ellipsis', | ||
| lineClamp: 2, | ||
| display: 'flex', | ||
| }} | ||
| > | ||
| {title} | ||
| </div> | ||
|
|
||
| {/* Description with fade effect */} | ||
| {description && ( | ||
| <div | ||
| style={{ | ||
| position: 'relative', | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| maxWidth: '100%', | ||
| overflow: 'hidden', | ||
| maxHeight: '270px', | ||
| }} | ||
| > | ||
| <div | ||
| style={{ | ||
| fontSize: '38px', | ||
| color: '#6B7280', | ||
| lineHeight: 1.4, | ||
| maxWidth: '100%', | ||
| overflow: 'hidden', | ||
| textOverflow: 'ellipsis', | ||
| lineClamp: 5, | ||
| display: 'flex', | ||
| }} | ||
| > | ||
| {description} | ||
| </div> | ||
| {/* Fade gradient overlay */} | ||
| <div | ||
| style={{ | ||
| position: 'absolute', | ||
| bottom: 0, | ||
| left: 0, | ||
| right: 0, | ||
| height: '80px', | ||
| backgroundImage: 'linear-gradient(to bottom, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 100%)', | ||
| }} | ||
| /> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ), | ||
| { | ||
| width: 1200, | ||
| height: 630, | ||
| fonts: [ | ||
| { | ||
| name: 'Heebo', | ||
| data: heeboRegular, | ||
| weight: 400, | ||
| style: 'normal', | ||
| }, | ||
| { | ||
| name: 'Heebo', | ||
| data: heeboSemibold, | ||
| weight: 600, | ||
| style: 'normal', | ||
| }, | ||
| ], | ||
| headers: { | ||
| 'Cache-Control': 'public, max-age=604800, immutable', // 1 week cache | ||
| }, | ||
| } | ||
| ); | ||
| }; | ||
|
|
||
| export const config = { | ||
| path: "/og-image", | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -130,15 +130,24 @@ eleventyComputed: | |
| <meta property="article:section" content="{{ nav }}" /> | ||
| {% endif %} | ||
|
|
||
| <!-- Open Graph Type --> | ||
| {% if page.url and page.url.match('\/handbook\/.+') %} | ||
| <meta property="og:type" content="article" /> | ||
| {% elif type == 'post' %} | ||
| <meta property="og:type" content="article" /> | ||
| {% else %} | ||
| <meta property="og:type" content="website" /> | ||
|
Comment on lines
+134
to
+139
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So only if the url isn't |
||
| {% endif %} | ||
|
|
||
| {% if type == 'post' %} | ||
| <!-- Article dates --> | ||
| {% if date %} | ||
| <meta property="article:published_time" content="{{ date | dateToRfc3339 }}" /> | ||
| <meta property="article:published_time" content="{{ date | toDate | dateToRfc3339 }}" /> | ||
| {% endif %} | ||
| {% if lastUpdated %} | ||
| <meta property="article:modified_time" content="{{ lastUpdated | dateToRfc3339 }}" /> | ||
| <meta property="article:modified_time" content="{{ lastUpdated | toDate | dateToRfc3339 }}" /> | ||
| {% elif date %} | ||
| <meta property="article:modified_time" content="{{ date | dateToRfc3339 }}" /> | ||
| <meta property="article:modified_time" content="{{ date | toDate | dateToRfc3339 }}" /> | ||
| {% endif %} | ||
| {% endif %} | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So for each page we create an image, on demand and cache if for the maximum duration possible. That seems fair, though a week I think might be better?