Repository navigation
docs(readme): the product in pictures, and the title without the author #349
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
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,60 @@ | ||
| import { mkdir } from 'node:fs/promises' | ||
| import { resolve } from 'node:path' | ||
| import { chromium } from 'playwright' | ||
| import { preview } from 'vite' | ||
|
|
||
| /** | ||
| * Renders the README's pictures of this site's pages into `docs/media/`, from the built site: run | ||
| * `pnpm build:demo` first. Run this when a page it shows changes its look. | ||
| */ | ||
|
|
||
| const rootDir = resolve(import.meta.dirname, '..') | ||
| const outDir = resolve(rootDir, '..', '..', 'docs', 'media') | ||
| const quiz = resolve(rootDir, 'demo', 'content', 'quiz.h5p') | ||
| // GitHub draws a README about 830 px wide: 1100 px at 1.5 is twice that, for a dense screen. | ||
| const width = 1100 | ||
| const scale = 1.5 | ||
|
|
||
| await mkdir(outDir, { recursive: true }) | ||
| const server = await preview({ root: rootDir, logLevel: 'warn', preview: { port: 4397, strictPort: false } }) | ||
| const base = server.resolvedUrls.local[0].replace(/\/$/, '') | ||
| const browser = await chromium.launch() | ||
| try { | ||
| const context = await browser.newContext({ viewport: { width, height: 700 }, deviceScaleFactor: scale, colorScheme: 'light' }) | ||
| const page = await context.newPage() | ||
| /** @param {string} name @param {number} height */ | ||
| const shoot = async (name, height) => { | ||
| await page.setViewportSize({ width, height: Math.ceil(height) }) | ||
| await page.evaluate(() => document.fonts.ready) | ||
| await page.evaluate(() => new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)))) | ||
| await page.screenshot({ path: resolve(outDir, name) }) | ||
| console.log(`[readme-media] ${name} ${width * scale}x${Math.round(Math.ceil(height) * scale)}`) | ||
| } | ||
|
|
||
| // The player page from its samples down, with the quiz at its first question. | ||
| await page.goto(`${base}/`) | ||
| await page.getByRole('button', { name: 'Quiz', exact: true }).click() | ||
| await page.waitForFunction(() => document.querySelector('h5p-player')?.state === 'ready', null, { timeout: 60_000 }) | ||
| const frame = page.frames().find((candidate) => candidate.url().includes('/h5p/frame/')) | ||
| if (!frame) throw new Error('the player has no frame') | ||
| await frame.getByRole('button', { name: 'Start' }).click() | ||
| await frame.getByRole('button', { name: 'Check' }).first().waitFor() | ||
| await frame.evaluate(() => document.fonts.ready) | ||
| // The frame's new height reaches the element a message later, so the page waits for it. | ||
| await page.waitForFunction(() => (document.querySelector('h5p-player')?.getBoundingClientRect().height ?? 0) > 400) | ||
| await page.locator('.samples').evaluate((samples) => { | ||
| const bar = document.querySelector('.topbar') | ||
| scrollTo(0, scrollY + samples.getBoundingClientRect().top - (bar instanceof HTMLElement ? bar.offsetHeight : 0) - 8) | ||
| }) | ||
| await shoot('player.png', await page.locator('h5p-player').evaluate((player) => player.getBoundingClientRect().bottom + 8)) | ||
|
|
||
| // The SCORM page with one package chosen, down to what its zip will hold. | ||
| await page.goto(`${base}/demo/scorm.html`) | ||
| await page.locator('#file').setInputFiles(quiz) | ||
| // A row is listed as soon as it is chosen, and says "Reading…" until its plan is known. | ||
| await page.locator('#files li[data-state="planned"]').first().waitFor() | ||
| await shoot('scorm.png', await page.locator('#files').evaluate((rows) => rows.getBoundingClientRect().bottom + 24)) | ||
| } finally { | ||
| await browser.close() | ||
| await server.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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
Uh oh!
There was an error while loading. Please reload this page.