Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions e2e/build.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,39 @@ test('a link carrying the source builds it at once, deflated or not', async ({ p
await expectPlays(page)
await expect(page.locator('#source')).toHaveValue(JSON.stringify(RIVERS))

const plain = Buffer.from(JSON.stringify({ ...RIVERS, title: 'Seas' })).toString('base64url')
// Plain base64url, with umlauts and ß: the bytes are UTF-8, and the file name keeps the letters.
const plain = Buffer.from(JSON.stringify({ ...RIVERS, language: 'de', title: 'Größte Flüsse' })).toString('base64url')
await page.goto(`/build#source=${plain}`)
await expect(page.locator('#status')).toContainText('Built “Seas”')
await expect(page.locator('#status')).toContainText('Built “Größte Flüsse”')
await expectPlays(page)
await expect(page.locator('#download')).toHaveAttribute('download', 'größte-flüsse.h5p')

// A title in another script keeps its letters too, rather than becoming activity.h5p.
await page.goto(`/build#source=${Buffer.from(JSON.stringify({ ...RIVERS, language: 'uk', title: 'Річки України' })).toString('base64url')}`)
await expectPlays(page)
await expect(page.locator('#download')).toHaveAttribute('download', 'річки-україни.h5p')

expect(elsewhere, 'nothing was fetched from another site').toEqual([])
expect(problems, problems.join('\n')).toEqual([])
})

test('a Question Set shows its cover title as written, tags and entities nowhere', async ({ page, baseURL }) => {
const { problems } = watch(page, baseURL)
// h5p-author 0.5.0 wrapped this plain field in <div>, which the set draws as text (h5p-offline-player#164).
const title = "Germany's Surrender: die größten Ereignisse"
const quiz = {
type: 'H5P.QuestionSet', title: 'Surrender', language: 'en', license: 'CC BY', authors: [{ name: 'Ann Author', role: 'Author' }],
params: {
introPage: { showIntroPage: true, title, introduction: 'Five questions.' },
questions: [{ library: 'H5P.TrueFalse', params: { question: 'The war in Europe ended in 1945.', correct: 'true' } }]
}
}
await page.goto(`/build#source=${Buffer.from(JSON.stringify(quiz)).toString('base64url')}`)
await expectPlays(page)
await expect(page.frameLocator('h5p-player iframe').first().locator('h2').first()).toHaveText(title)
expect(problems, problems.join('\n')).toEqual([])
})

test('a source that names a file waits for it, then builds with it', async ({ page, baseURL }) => {
const { problems } = watch(page, baseURL)
const delta = {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"vite": "^8.3.5"
},
"dependencies": {
"@missing-elements/h5p-author": "^0.5.0",
"@missing-elements/h5p-author": "^0.5.1",
"@missing-elements/h5p-embed": "^1.7.0",
"@missing-elements/h5p-libraries": "^1.1.0",
"@missing-elements/h5p-offline-player": "^1.5.1",
Expand Down
20 changes: 5 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 10 additions & 7 deletions src/build-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,20 @@ export function forTheChat(problems: Problem[]): string {
].join('\n')
}

/** A file name for the package, from its title. */
/**
* A file name for the package, from its title: its letters, marks and digits in any script, lower
* case, joined by hyphens, at most 60 of them. "Die größten Ereignisse" is
* `die-größten-ereignisse.h5p`, and a Cyrillic or Greek title keeps its letters, where a slug of
* ASCII alone turned ß into a hyphen and such a title into `activity.h5p`.
*/
export function packageName(title: unknown): string {
const words = String(title ?? '')
.normalize('NFKD')
.replace(/[̀-ͯ]/g, '')
.normalize('NFC')
.toLowerCase()
.replace(/[^a-z0-9]+/g, '-')
.replace(/[^\p{L}\p{M}\p{N}]+/gu, '-')
.replace(/^-+|-+$/g, '')
.slice(0, 60)
.replace(/-+$/, '')
return `${words || 'activity'}.h5p`
const short = Array.from(words).slice(0, 60).join('').replace(/-+$/, '')
return `${short || 'activity'}.h5p`
}

/** A size in kilobytes below a megabyte, in megabytes above. */
Expand Down
Loading