Skip to content

Commit

Permalink
Docs Refactor gen-og-images script to leverage satori over puppeteer
Browse files Browse the repository at this point in the history
### WHY are these changes introduced?

- Fixes Shopify/polaris-internal#1278

Our existing `gen-og-images` script creates an og-image layout using
HTML markup and then runs puppeteer to take snapshots of each generated
layout. This is relatively slow, this PR aims to swap this logic out for
[Satori](https://github.com/vercel/satori) vercel's library for doing
the exact same markup to og-image procedure but without having to spin
up a puppeteer instance.


### WHAT is this pull request doing?
* Convert our HTML markup to JSX 
* Convert `<style>` tag CSS to inline css for each of our JSX elements.
(This is a limitation of satori, in that it does not support global
<style> tags
* Remove puppeteer logic in favor of a single call to satori 
```tsx
satori(someMarkup, someConfig)
```
* Leverage [@inter-ui](https://www.npmjs.com/package/inter-ui) to
download non-variable versions of Inter for use in our generated layout.
(A limitation of the underlying library that Satori leverages for type
support (opentype.js) is that it does not support variable fonts)
* Leverage
[@napi-rs/image](https://www.npmjs.com/package/@napi-rs/image) to
convert our generated svg from satori into a png file for use as an
og-image.

---------

Co-authored-by: Jess Telford <jess.telford@shopify.com>
  • Loading branch information
gwyneplaine and jesstelford authored Dec 14, 2023
1 parent a49ce53 commit 1d20e1b
Show file tree
Hide file tree
Showing 7 changed files with 426 additions and 236 deletions.
1 change: 0 additions & 1 deletion polaris-icons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
"hast-util-select": "^3.0.0",
"js-yaml": "^4.0.0",
"rehype-parse": "^7.0.1",
"svgo": "^2.8.0",
"unified": "^9.2.1"
}
}
1 change: 0 additions & 1 deletion polaris.shopify.com/content/components/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
title: Components
order: 7
icon: AppsMajor
previewImg: /images/components.png
---

# {frontmatter.title}
Expand Down
6 changes: 4 additions & 2 deletions polaris.shopify.com/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"create-component": "generact --root src/components src/components/Template/Template.tsx",
"gen-sitemap": "yarn next-sitemap",
"get-props": "./scripts/get-props/src/get-props.ts",
"gen-assets": "yarn get-props && node scripts/gen-cache-json.mjs && ts-node scripts/gen-site-map.ts && ts-node scripts/gen-og-images.ts",
"gen-assets": "yarn get-props && node scripts/gen-cache-json.mjs && ts-node scripts/gen-site-map.ts && ts-node scripts/gen-og-images.tsx",
"gen-colors": "ts-node ./scripts/gen-colors.ts"
},
"dependencies": {
Expand Down Expand Up @@ -64,6 +64,7 @@
},
"devDependencies": {
"@esm2cjs/p-map": "^5.5.0",
"@napi-rs/image": "^1.7.0",
"@types/base-64": "^1.0.0",
"@types/gtag.js": "^0.0.10",
"@types/js-yaml": "^4.0.5",
Expand All @@ -84,15 +85,16 @@
"generact": "^0.4.0",
"get-site-urls": "3.0.0-alpha.1",
"globby": "^11.1.0",
"inter-ui": "3.19.3",
"is-ci": "^3.0.1",
"js-yaml": "^4.1.0",
"lodash.set": "^4.3.2",
"marked": "^4.0.16",
"ora": "^5.4.1",
"p-map": "^5.5.0",
"playroom": "^0.28.0",
"puppeteer": "^16.0.0",
"sass": "^1.49.9",
"satori": "^0.10.11",
"style-loader": "^3.3.1",
"ts-node": "^10.7.0",
"typescript": "^4.9.3"
Expand Down
200 changes: 0 additions & 200 deletions polaris.shopify.com/scripts/gen-og-images.ts

This file was deleted.

Loading

0 comments on commit 1d20e1b

Please sign in to comment.