-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add details to the automated content update PR (#467)
* Tools: Add puppeteer, update packages * Tools: Add screenshots to change notice PRs * Return the changed list and use it for the PR body
- Loading branch information
Showing
7 changed files
with
1,077 additions
and
1,653 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
/vendor | ||
*.map | ||
backstop_data | ||
artifacts | ||
|
||
# Allow local environment overrides. | ||
.wp-env.override.json | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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,90 @@ | ||
#!/usr/bin/env node | ||
/* eslint-disable no-console */ | ||
/** | ||
* External dependencies. | ||
*/ | ||
const path = require( 'path' ); | ||
const puppeteer = require( 'puppeteer' ); | ||
|
||
/** | ||
* Internal dependencies. | ||
*/ | ||
const manifest = require( './page-manifest.json' ); | ||
|
||
const IMAGE_PATH = path.resolve( process.env.GITHUB_WORKSPACE || '.', 'artifacts' ); | ||
|
||
// node ./env/screenshot-changes.js [...files] | ||
const [ , , ...files ] = process.argv; | ||
|
||
async function getPageDetails( slug ) { | ||
const apiUrl = `https://wordpress.org/wp-json/wp/v2/pages?context=wporg_export&slug=${ slug }`; | ||
let post = false; | ||
try { | ||
const response = await fetch( apiUrl ); | ||
[ post ] = await response.json(); | ||
post.localLink = post.link.replace( 'https://wordpress.org/', 'http://localhost:8888/' ); | ||
} catch ( error ) { | ||
console.error( error.message ); | ||
} | ||
return post; | ||
} | ||
|
||
( async () => { | ||
const browser = await puppeteer.launch( { headless: true } ); | ||
const page = await browser.newPage(); | ||
|
||
await page.setViewport( { | ||
width: 1440, | ||
height: 800, | ||
deviceScaleFactor: 1, | ||
} ); | ||
|
||
for ( let i = 0; i < files.length; i++ ) { | ||
const file = files[ i ]; | ||
const found = manifest.find( | ||
( entry ) => entry.pattern === path.basename( file ) || `${ entry.slug }.php` === path.basename( file ) | ||
); | ||
if ( found ) { | ||
const post = await getPageDetails( found.slug ); | ||
console.log( `${ post.title.rendered } [${ post.link }]` ); | ||
|
||
await page.goto( post.localLink, { waitUntil: 'networkidle0' } ); | ||
await page.evaluate( async () => { | ||
// eslint-disable-next-line no-undef | ||
const images = document.querySelectorAll( 'img[class*=wp-image]' ); | ||
|
||
for ( let img = 0; img < images.length; img++ ) { | ||
images[ img ].scrollIntoView(); | ||
await new Promise( ( r ) => setTimeout( r, 100 ) ); | ||
} | ||
|
||
// Wait for all remaining lazy loading images to load | ||
await Promise.all( | ||
Array.from( images, ( image ) => { | ||
if ( image.complete ) { | ||
return; | ||
} | ||
|
||
return new Promise( ( resolve, reject ) => { | ||
image.addEventListener( 'load', resolve ); | ||
image.addEventListener( 'error', reject ); | ||
} ); | ||
} ) | ||
); | ||
} ); | ||
await page.evaluate( async () => { | ||
// eslint-disable-next-line no-undef | ||
document.body.scrollIntoView( true ); | ||
} ); | ||
|
||
await page.waitForNetworkIdle(); | ||
|
||
await page.screenshot( { | ||
path: `${ IMAGE_PATH }/${ found.slug }.png`, | ||
fullPage: true, | ||
} ); | ||
} | ||
} | ||
|
||
await browser.close(); | ||
} )(); |
This file contains 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 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.