-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Bump actions, pmap genPng, fix nodejs version, fix issues with node 14.17 #7482
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
Merged
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2851224
Update gen-og-images.mjs
alex-page 2a765d4
Update gen-og-images.mjs
alex-page f337b0c
Use node-version and bump action versions
alex-page 1fcdcc8
Add p-map
alex-page c0748a9
CI version updates
alex-page 7c775aa
Create swift-shoes-beam.md
alex-page c6a1d29
Update gen-og-images.mjs
alex-page f3058c8
NodeJS 14 support
alex-page ea4317c
rm node:
alex-page d884197
Rm .at(-1) 😭
alex-page 8ab19f3
"Rm .at(-1) 😭"
alex-page a70acd6
Update gen-og-images.mjs
alex-page 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'polaris.shopify.com': patch | ||
| --- | ||
|
|
||
| Bump GitHub action versions and add p-map for gen-og-images CI failure |
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
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
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 |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ import matter from 'gray-matter'; | |
| import {existsSync} from 'fs'; | ||
| import path from 'path'; | ||
| import {writeFile, readFile, mkdir, rm} from 'fs/promises'; | ||
| import pMap from 'p-map'; | ||
|
|
||
| const sitemapPath = path.join(process.cwd(), 'public/sitemap.xml'); | ||
| const imgDir = path.join(process.cwd(), 'public/og-images'); | ||
|
|
@@ -152,21 +153,6 @@ const generateHTML = async (url, slug) => { | |
| return Buffer.from(html).toString('base64'); | ||
| }; | ||
|
|
||
| const getPNG = async (url, browser) => { | ||
| const slug = url === '' ? 'home' : url.split('/').at(-1); | ||
| const imgPath = | ||
| url.split('/').length > 1 ? url.split('/').slice(0, -1).join('/') : url; | ||
| const html = await generateHTML(url, slug); | ||
| const encodedUrl = `data:text/html;charset=utf-8;base64,${html}`; | ||
| const page = await browser.newPage(); | ||
| await page.goto(encodedUrl, {waitUntil: 'networkidle0'}); | ||
| const image = await page.screenshot(); | ||
| if (!existsSync(`${imgDir}${imgPath}`)) { | ||
| await mkdir(`${imgDir}${imgPath}`, {recursive: true}); | ||
| } | ||
| await writeFile(`${imgDir}${imgPath}/${slug}.png`, image); | ||
| }; | ||
|
|
||
| const genOgImages = async () => { | ||
| if (existsSync(imgDir)) await rm(imgDir, {recursive: true}); | ||
| await mkdir(imgDir, {recursive: true}); | ||
|
|
@@ -181,7 +167,31 @@ const genOgImages = async () => { | |
| args: ['--no-sandbox', '--disable-setuid-sandbox'], | ||
| }); | ||
|
|
||
| const generateImages = urls.map((url) => getPNG(url, browser)); | ||
| const getPNG = async (url) => { | ||
| try { | ||
| const slug = url === '' ? 'home' : url.split('/').pop(); | ||
| const imgPath = | ||
| url.split('/').length > 1 ? url.split('/').slice(0, -1).join('/') : url; | ||
| const html = await generateHTML(url, slug); | ||
| const encodedUrl = `data:text/html;charset=utf-8;base64,${html}`; | ||
| const page = await browser.newPage(); | ||
| await page.goto(encodedUrl, {waitUntil: 'networkidle0'}); | ||
| const image = await page.screenshot(); | ||
| if (!existsSync(`${imgDir}${imgPath}`)) { | ||
| await mkdir(`${imgDir}${imgPath}`, {recursive: true}); | ||
| } | ||
| await writeFile(`${imgDir}${imgPath}/${slug}.png`, image); | ||
| await page.close(); | ||
|
Member
Author
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. Added |
||
|
|
||
| console.log(`✅ Successfuly generated png for ${url}`); | ||
| } catch (error) { | ||
| console.error(`❌ Failed to generate png for ${url}`); | ||
| throw new Error(error); | ||
| } | ||
| }; | ||
|
|
||
| const generateImages = await pMap(urls, getPNG, {concurrency: 30}); | ||
|
|
||
| await Promise.all(generateImages); | ||
|
|
||
| await browser.close(); | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -5658,6 +5658,14 @@ aggregate-error@^3.0.0: | |
| clean-stack "^2.0.0" | ||
| indent-string "^4.0.0" | ||
|
|
||
| aggregate-error@^4.0.0: | ||
| version "4.0.1" | ||
| resolved "https://registry.yarnpkg.com/aggregate-error/-/aggregate-error-4.0.1.tgz#25091fe1573b9e0be892aeda15c7c66a545f758e" | ||
| integrity sha512-0poP0T7el6Vq3rstR8Mn4V/IQrpBLO6POkUSrN7RhyY+GF/InCFShQzsQ39T25gkHhLgSLByyAz+Kjb+c2L98w== | ||
| dependencies: | ||
| clean-stack "^4.0.0" | ||
| indent-string "^5.0.0" | ||
|
|
||
| [email protected]: | ||
| version "1.0.2" | ||
| resolved "https://registry.yarnpkg.com/ahocorasick/-/ahocorasick-1.0.2.tgz#9eee93aef9d02bfb476d9b648d9b7a40ef2fd500" | ||
|
|
@@ -7668,6 +7676,13 @@ clean-stack@^3.0.1: | |
| dependencies: | ||
| escape-string-regexp "4.0.0" | ||
|
|
||
| clean-stack@^4.0.0: | ||
| version "4.2.0" | ||
| resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-4.2.0.tgz#c464e4cde4ac789f4e0735c5d75beb49d7b30b31" | ||
| integrity sha512-LYv6XPxoyODi36Dp976riBtSY27VmFo+MKqEU9QCCWyTrdEPDog+RWA7xQWHi6Vbp61j5c4cdzzX1NidnwtUWg== | ||
| dependencies: | ||
| escape-string-regexp "5.0.0" | ||
|
|
||
| cli-boxes@^1.0.0: | ||
| version "1.0.0" | ||
| resolved "https://registry.yarnpkg.com/cli-boxes/-/cli-boxes-1.0.0.tgz#4fa917c3e59c94a004cd61f8ee509da651687143" | ||
|
|
@@ -9586,6 +9601,11 @@ [email protected], escape-string-regexp@^4.0.0: | |
| resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34" | ||
| integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA== | ||
|
|
||
| [email protected], escape-string-regexp@^5.0.0: | ||
| version "5.0.0" | ||
| resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-5.0.0.tgz#4683126b500b61762f2dbebace1806e8be31b1c8" | ||
| integrity sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw== | ||
|
|
||
| escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5: | ||
| version "1.0.5" | ||
| resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" | ||
|
|
@@ -9596,11 +9616,6 @@ escape-string-regexp@^2.0.0: | |
| resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz#a30304e99daa32e23b2fd20f51babd07cffca344" | ||
| integrity sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w== | ||
|
|
||
| escape-string-regexp@^5.0.0: | ||
| version "5.0.0" | ||
| resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-5.0.0.tgz#4683126b500b61762f2dbebace1806e8be31b1c8" | ||
| integrity sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw== | ||
|
|
||
| escodegen@^2.0.0: | ||
| version "2.0.0" | ||
| resolved "https://registry.yarnpkg.com/escodegen/-/escodegen-2.0.0.tgz#5e32b12833e8aa8fa35e1bf0befa89380484c7dd" | ||
|
|
@@ -16878,6 +16893,13 @@ p-map@^4.0.0: | |
| dependencies: | ||
| aggregate-error "^3.0.0" | ||
|
|
||
| p-map@^5.5.0: | ||
| version "5.5.0" | ||
| resolved "https://registry.yarnpkg.com/p-map/-/p-map-5.5.0.tgz#054ca8ca778dfa4cf3f8db6638ccb5b937266715" | ||
| integrity sha512-VFqfGDHlx87K66yZrNdI4YGtD70IRyd+zSvgks6mzHPRNkoKy+9EKP4SFC77/vTTQYmRmti7dvqC+m5jBrBAcg== | ||
| dependencies: | ||
| aggregate-error "^4.0.0" | ||
|
|
||
| p-retry@^4.5.0: | ||
| version "4.6.2" | ||
| resolved "https://registry.yarnpkg.com/p-retry/-/p-retry-4.6.2.tgz#9baae7184057edd4e17231cee04264106e092a16" | ||
|
|
||
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.
Moved the
getPNGfunction insidegenOgImagesas the mapper function passed top-maphas one argument. This means we can use thebrowserwithout adding it to the URL array.