diff --git a/Scripts/build-website.mjs b/Scripts/build-website.mjs index ddfe5e0..dfff0db 100644 --- a/Scripts/build-website.mjs +++ b/Scripts/build-website.mjs @@ -3,6 +3,7 @@ import { fileURLToPath } from 'node:url'; import path from 'node:path'; import os from 'node:os'; import { createHash } from 'node:crypto'; +import { guidePath, renderGuide, renderGuideCards, tutorialContent } from '../website/tutorials.mjs'; export const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); const appInfo = await readFile(path.join(root, 'AppResources/Info.plist'), 'utf8'); @@ -85,7 +86,9 @@ export function renderPage(template, language, copy, screenshots, assetVersions, `` ].join('\n '); const languageLinks = languages.map(l => `${l.name}`).join('\n '); - const values = { ...copy, head, languageLinks, + const guideLabel = tutorialContent.locales[language.id]?.nav; + const guideNav = guideLabel ? `${escape(guideLabel)}` : ''; + const values = { ...copy, head, languageLinks, guideNav, guideCards: renderGuideCards(language.id, prefix), armDownloadURL: `https://github.com/ixiehao/MP4Flow/releases/latest/download/MP4Flow-${appVersion}-arm64.dmg`, intelDownloadURL: `https://github.com/ixiehao/MP4Flow/releases/latest/download/MP4Flow-${appVersion}-x86_64.dmg`, scriptVersion: assetVersions.script, locale: language.locale, language: language.id, languageName: language.name, privacyURL: `https://github.com/ixiehao/MP4Flow/blob/main/PRIVACY${language.id === 'ja' ? '.ja' : ''}.md` }; @@ -97,7 +100,7 @@ export function renderPage(template, language, copy, screenshots, assetVersions, } let result = template.replace(/\{\{(\w+)\}\}/g, (_, key) => { if (!(key in values)) throw new Error(`Missing template value: ${key}`); - return ['head', 'languageLinks'].includes(key) ? values[key] : escape(values[key]).replace(/\n/g, '
'); + return ['head', 'languageLinks', 'guideNav', 'guideCards'].includes(key) ? values[key] : escape(values[key]).replace(/\n/g, '
'); }); result = result.replace(' language.id in tutorialContent.locales); + for (const [slug, guide] of Object.entries(tutorialContent.guides)) { + if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(slug) || !/^[a-zA-Z0-9-]+\.(mkv|mov|mp4)$/.test(guide.sample)) { + throw new Error(`Invalid tutorial source: ${slug}`); + } + await readFile(path.join(root, 'website/assets/tutorials', guide.sample)); + for (const { id } of guideLanguages) { + const { media } = guide[id]; + const imagePath = `assets/tutorials/v${tutorialContent.captureVersion.replaceAll('.', '')}-${guide.capture}-${id}.webp`; + if (media.src !== imagePath || !Number.isSafeInteger(media.width) || media.width <= 0 + || !Number.isSafeInteger(media.height) || media.height <= 0) { + throw new Error(`Invalid tutorial screenshot: ${slug}/${id}`); + } + const hash = createHash('sha256').update(await readFile(path.join(root, 'website', media.src))).digest('hex'); + if (hash !== media.sha256) throw new Error(`Changed tutorial screenshot: ${slug}/${id}`); + } + } await rm(output, { recursive: true, force: true }); await mkdir(output, { recursive: true }); await cp(path.join(root, 'website/assets'), path.join(output, 'assets'), { recursive: true }); @@ -135,8 +155,23 @@ export async function buildSite(output = path.join(root, '_site')) { const english = languages.find(language => language.id === 'en'); await mkdir(path.join(output, 'en'), { recursive: true }); await writeFile(path.join(output, 'en/index.html'), renderPage(template, english, catalogs.en, screenshots, assetVersions, 'en/')); - const alternates = [...languages.map(l => ({ locale: l.locale, url: siteURL + localePath(l.id) })), { locale: 'x-default', url: siteURL }]; - const sitemap = `\n\n${languages.map(l => ` ${siteURL}${localePath(l.id)}\n${alternates.map(a => ` `).join('\n')}\n `).join('\n')}\n\n`; + const sitemapGroup = (editions, route) => editions.map(language => { + const alternates = [...editions, { locale: 'x-default', id: 'en' }]; + return ` ${siteURL}${route(language.id)}\n${alternates.map(a => ` `).join('\n')}\n `; + }); + const entries = sitemapGroup(languages, localePath); + for (const [slug, guide] of Object.entries(tutorialContent.guides)) { + for (const language of guideLanguages) { + const directory = path.join(output, guidePath(slug, language.id)); + const media = guide[language.id].media; + await mkdir(directory, { recursive: true }); + await writeFile(path.join(directory, 'index.html'), renderGuide({ + slug, language, languages, siteURL, styles, siteCopy: catalogs[language.id], media + })); + } + entries.push(...sitemapGroup(guideLanguages, id => guidePath(slug, id))); + } + const sitemap = `\n\n${entries.join('\n')}\n\n`; await writeFile(path.join(output, 'sitemap.xml'), sitemap); return output; } diff --git a/Scripts/search-content.py b/Scripts/search-content.py index d3ca528..323500e 100644 --- a/Scripts/search-content.py +++ b/Scripts/search-content.py @@ -121,7 +121,19 @@ def language_ids(config): def page_url(config, language): return config['site_url'] + ('' if language == 'en' else language + '/') -def inspect_page(html, canonical, language, urls): +def tutorial_groups(config): + if 'tutorial_source' not in config: + return [] + content = json.loads((ROOT/config['tutorial_source']).read_text()) + ids = list(content['locales']) + require('en' in ids and set(ids) <= set(language_ids(config)), 'Invalid tutorial languages') + groups = [] + for slug in content['guides']: + require(re.fullmatch(r'[a-z0-9]+(?:-[a-z0-9]+)*', slug), 'Invalid tutorial slug') + groups.append({language: page_url(config, language)+'guides/'+slug+'/' for language in ids}) + return groups + +def inspect_page(html, canonical, language, urls, site=None): doc = Document(html) root, main, title = doc.find('html'), doc.find('main'), doc.find('title') require(root is not None and root.attrs.get('lang', '').split('-')[0] == language, f'{canonical}: wrong HTML language') @@ -146,14 +158,15 @@ def inspect_page(html, canonical, language, urls): md = doc.find('link', type='text/markdown') require(md is not None and urljoin(canonical, md.attrs.get('href', '')) == canonical+'index.md', f'{canonical}: missing Markdown alternate') descriptor = doc.find('link', rel='describedby') - require(descriptor is not None and urljoin(canonical, descriptor.attrs.get('href', '')) == urls['en']+'llms.txt', f'{canonical}: missing AI reading index') + require(descriptor is not None and urljoin(canonical, descriptor.attrs.get('href', '')) == (site or urls['en'])+'llms.txt', f'{canonical}: missing AI reading index') schemas = [json.loads(node.text()) for node in doc.root.nodes() if node.tag == 'script' and node.attrs.get('type') == 'application/ld+json'] require(schemas, f'{canonical}: missing structured data') graphs = [entry for schema in schemas for entry in schema.get('@graph', [schema])] - require(any(node.get('@type') in ('SoftwareApplication', 'WebSite', 'ProfilePage') for node in graphs), f'{canonical}: missing page/application schema') + types = ('Article',) if site else ('SoftwareApplication', 'WebSite', 'ProfilePage') + require(any(node.get('@type') in types for node in graphs), f'{canonical}: missing page/application schema') for node in graphs: - if node.get('@type') == 'SoftwareApplication': - require(node.get('url') == canonical and node.get('description') == description.attrs['content'], f'{canonical}: application facts differ from metadata') + if node.get('@type') in ('SoftwareApplication', 'Article'): + require(node.get('url') == canonical and node.get('description') == description.attrs['content'], f'{canonical}: structured data differs from metadata') body = markdown(doc.find('body'), canonical) text = '# ' + title.text().strip() + '\n\n> ' + description.attrs['content'].strip() + '\n\n<' + canonical + '>\n\n' + body text = re.sub(r'[\t ]+\n', '\n', text) @@ -177,9 +190,11 @@ def build(config, check=False): ids = language_ids(config) urls = {language: page_url(config, language) for language in ids} site = config['site_url'] + tutorials = tutorial_groups(config) + canonical_pages = [canonical for group in [urls, *tutorials] for canonical in group.values()] sitemap = ET.fromstring((directory/'sitemap.xml').read_text()) locations = [node.text for node in sitemap.findall('{*}url/{*}loc')] - require(len(locations) == len(urls) and set(locations) == set(urls.values()), 'Sitemap does not match actual canonical languages') + require(len(locations) == len(canonical_pages) and set(locations) == set(canonical_pages), 'Sitemap does not match actual canonical pages') summaries = {} for language, canonical in urls.items(): folder = directory/('' if language == 'en' else language) @@ -188,6 +203,15 @@ def build(config, check=False): compare_or_write(folder/'index.md', text, check) lines = ['# '+config['name'], '', '> '+summaries['en'], '', '## Pages', ''] lines += [f'- [{LANGUAGE_NAMES.get(language, language)}]({canonical}index.md)' for language, canonical in urls.items()] + if tutorials: + lines += ['', '## Guides', ''] + for group in tutorials: + for language, canonical in group.items(): + folder = directory/canonical.removeprefix(site) + text, _ = inspect_page((folder/'index.html').read_text(), canonical, language, group, site) + compare_or_write(folder/'index.md', text, check) + title = text.splitlines()[0].removeprefix('# ') + lines.append(f'- [{title} ({LANGUAGE_NAMES[language]})]({canonical}index.md)') if config.get('projects'): lines += ['', '## Projects', ''] lines += [f'- [{project["name"]}]({project["url"]}): {project["description"]}' for project in config['projects']] @@ -196,13 +220,14 @@ def build(config, check=False): compare_or_write(directory/'indexnow-key.txt', ownership_key(config)+'\n', check) for url in config.get('root_sitemaps', []): require('Sitemap: '+url in (directory/'robots.txt').read_text(), 'Domain-root robots is missing '+url) - return len(ids) + return len(canonical_pages) def notification(config): base = config['site_url'] origin = urlsplit(base) require(origin.scheme == 'https' and base.endswith('/') and not origin.query and not origin.fragment, 'Use the production HTTPS directory') urls = [page_url(config, language) for language in language_ids(config)] + urls += [canonical for group in tutorial_groups(config) for canonical in group.values()] require(all(url.startswith(base) and not urlsplit(url).query for url in urls), 'URLs must stay in this project scope') return {'host': origin.netloc, 'key': ownership_key(config), 'keyLocation': base+'indexnow-key.txt', 'urlList': urls} diff --git a/Scripts/tests/website.test.mjs b/Scripts/tests/website.test.mjs index f5b6875..6831e1f 100644 --- a/Scripts/tests/website.test.mjs +++ b/Scripts/tests/website.test.mjs @@ -5,6 +5,7 @@ import path from 'node:path'; import os from 'node:os'; import { createHash } from 'node:crypto'; import { appVersion, buildSite, languages, localePath, readCatalogs, siteURL } from '../build-website.mjs'; +import { guidePath, tutorialContent } from '../../website/tutorials.mjs'; test('seven canonical pages are complete, crawlable and use matching real screenshots', async t => { const output = await mkdtemp(path.join(os.tmpdir(), 'mp4flow-website-test-')); @@ -142,12 +143,27 @@ test('seven canonical pages are complete, crawlable and use matching real screen assert.ok(chineseReadme.includes('[官方网站](https://ixiehao.github.io/MP4Flow/zh/)')); }); const sitemap = await readFile(path.join(output, 'sitemap.xml'), 'utf8'); - assert.equal((sitemap.match(//g) ?? []).length, 7); - assert.equal((sitemap.match(/xhtml:link/g) ?? []).length, 56); + const guideLanguages = Object.keys(tutorialContent.locales); + const guideCount = Object.keys(tutorialContent.guides).length * guideLanguages.length; + assert.equal((sitemap.match(//g) ?? []).length, languages.length + guideCount); + assert.equal((sitemap.match(/xhtml:link/g) ?? []).length, 56 + guideCount * (guideLanguages.length + 1)); assert.doesNotMatch(sitemap, /https:\/\/ixiehao.github.io\/MP4Flow\/en\//); assert.match(sitemap, /https:\/\/ixiehao.github.io\/MP4Flow\/zh\/<\/loc>/); await assert.rejects(stat(path.join(output, 'locales'))); await assert.rejects(stat(path.join(output, 'Scripts'))); + const sample = await readFile(path.join(output, 'assets/tutorials/Patterns.mkv')); + assert.equal(sample.subarray(0, 4).toString('hex'), '1a45dfa3'); + for (const [slug, guide] of Object.entries(tutorialContent.guides)) { + for (const id of guideLanguages) { + const route = guidePath(slug, id); + const html = await readFile(path.join(output, route, 'index.html'), 'utf8'); + assert.ok(sitemap.includes(`${siteURL}${route}`)); + assert.ok(html.includes(`rel="canonical" href="${siteURL}${route}"`)); + assert.ok(html.includes(`

${guide[id].title}

`)); + assert.equal((html.match(/

/g) ?? []).length, 3); + } + } }); test('42 localized captures match their provenance and actual JPEG dimensions', async () => { diff --git a/docs/WEBSITE.md b/docs/WEBSITE.md index bb854ec..41e464d 100644 --- a/docs/WEBSITE.md +++ b/docs/WEBSITE.md @@ -18,7 +18,7 @@ The existing GitHub Pages site stays at . - `website/index.html` is the shared template; `website/locales/*.json` contains all public copy, accessible labels and metadata. - `Scripts/build-website.mjs` uses Node.js standard libraries to generate `_site/`. No framework, package install or runtime translation request is required. -- Each generated page contains its full translation, canonical URL, reciprocal `hreflang` links, share metadata and structured data. The build also creates the seven-page sitemap. +- Each generated page contains its full translation, canonical URL, reciprocal `hreflang` links, share metadata and structured data. The build also creates the sitemap for the seven home pages and the localized guides. - English is served directly at the root, including without JavaScript. The old `/MP4Flow/en/` remains an English alias with the root as its canonical URL; only the seven canonical routes appear in the sitemap. - Existing `?lang=en`, `?lang=ja` and other supported language links redirect to the corresponding page, preserving the section and other query parameters. Explicit page URLs take priority over browser language or old preferences. - Query-language routing uses the generated language links rather than maintaining a second route map in JavaScript. @@ -38,6 +38,12 @@ Phone layouts show one visual article per row; wider screens use two columns. Ke The FAQ uses the same full-width, pale rounded panel as the surrounding sections. Place its heading beside the disclosure cards on desktop and above them on phones. Keep the native `details` controls, visible keyboard focus and a generous question hit area; long translations and expanded answers must remain inside their cards. +## Task guides + +`website/tutorials.json` holds three task guides in English, Simplified Chinese and Japanese. The builder publishes standalone Guides pages with reciprocal language links, an equivalent Markdown page, and sitemap entries. Homepage links appear in those three languages. + +Each guide uses a synthetic downloadable example, three steps and a check of the exported result. The screenshots were captured from the matching released App in isolated macOS CI windows. Their version, dimensions, hashes, captions and alternate text are in the same catalog. Publish only the inspected WebP derivatives and the sample inputs. + ## Native installer messaging The hero highlights a lightweight native macOS app. “About 3 MB” describes each compressed, architecture-specific DMG; it excludes separately installed FFmpeg/ffprobe. Keep that distinction visible in the download section. Apple Silicon (`arm64`) and Intel (`x86_64`) downloads are explicit choices, with an About This Mac hint; do not infer CPU architecture from a browser user agent. The static generator reads the release version from `AppResources/Info.plist` for download asset names and `SoftwareApplication.softwareVersion`. Confirm both assets exist before deploying a new version of these links. Screenshot provenance retains its actual capture version. diff --git a/search-content.config.json b/search-content.config.json index 5e616cf..36cec6c 100644 --- a/search-content.config.json +++ b/search-content.config.json @@ -4,5 +4,6 @@ "directory": "_site", "source_url": "https://github.com/ixiehao/MP4Flow", "key_file": "website/indexnow-key.txt", - "language_source": "website/locales/*.json" + "language_source": "website/locales/*.json", + "tutorial_source": "website/tutorials.json" } diff --git a/website-tests/guides.spec.mjs b/website-tests/guides.spec.mjs new file mode 100644 index 0000000..10f4644 --- /dev/null +++ b/website-tests/guides.spec.mjs @@ -0,0 +1,42 @@ +import { test, expect, languages } from './support.mjs'; +import { guidePath, tutorialContent } from '../website/tutorials.mjs'; + +for (const language of languages.filter(id => id in tutorialContent.locales)) { + for (const viewport of [{ width: 320, height: 568 }, { width: 1280, height: 900 }]) { + test.describe(`${language} guides at ${viewport.width}px`, () => { + test.use({ javaScriptEnabled: false, viewport, isMobile: viewport.width < 500, hasTouch: viewport.width < 500 }); + test('localized tutorials, sample media and language links work without JavaScript', async ({ page }) => { + const home = language === 'en' ? './' : language + '/'; + for (const [slug, guide] of Object.entries(tutorialContent.guides)) { + expect((await page.goto(home)).status()).toBe(200); + await page.locator('#guides').getByRole('link', { name: guide[language].title }).click(); + const route = guidePath(slug, language); + expect(page.url()).toMatch(new RegExp(`/${route}$`)); + await expect(page.getByRole('heading', { level: 1 })).toHaveText(guide[language].title); + await expect(page.locator('.guide-steps > li')).toHaveCount(3); + await expect(page.locator('.guide-result p')).toHaveText(guide[language].result); + const layout = await page.evaluate(() => ({ width: innerWidth, scrollWidth: document.documentElement.scrollWidth })); + expect(layout).toEqual({ width: viewport.width, scrollWidth: viewport.width }); + const sample = page.locator('main a[download]'); + const sampleURL = new URL(await sample.getAttribute('href'), page.url()).href; + expect((await page.request.head(sampleURL)).status()).toBe(200); + const picture = page.getByRole('img', { name: guide[language].alt }); + await expect(picture).toBeVisible(); + const dimensions = await picture.evaluate(image => ({ + width: image.naturalWidth, height: image.naturalHeight, rendered: image.getBoundingClientRect().width, + bounds: image.closest('article').getBoundingClientRect().width + })); + expect(dimensions.width).toBe(guide[language].media.width); + expect(dimensions.height).toBe(guide[language].media.height); + expect(dimensions.rendered).toBeLessThanOrEqual(dimensions.bounds); + const original = await page.locator('.guide-figure a').getAttribute('href'); + expect(original).toEqual(await picture.getAttribute('src')); + expect((await page.request.head(new URL(original, page.url()).href)).status()).toBe(200); + const other = language === 'ja' ? 'zh' : 'ja'; + await page.locator(`.guide-languages a[lang="${other === 'zh' ? 'zh-CN' : other}"]`).click(); + await expect(page.getByRole('heading', { level: 1 })).toHaveText(guide[other].title); + } + }); + }); + } +} diff --git a/website/assets/tutorials/Patterns.mkv b/website/assets/tutorials/Patterns.mkv new file mode 100644 index 0000000..1bf2398 Binary files /dev/null and b/website/assets/tutorials/Patterns.mkv differ diff --git a/website/assets/tutorials/Patterns.mov b/website/assets/tutorials/Patterns.mov new file mode 100644 index 0000000..22cd703 Binary files /dev/null and b/website/assets/tutorials/Patterns.mov differ diff --git a/website/assets/tutorials/v153-convert-en.webp b/website/assets/tutorials/v153-convert-en.webp new file mode 100644 index 0000000..d7c9d4e Binary files /dev/null and b/website/assets/tutorials/v153-convert-en.webp differ diff --git a/website/assets/tutorials/v153-convert-ja.webp b/website/assets/tutorials/v153-convert-ja.webp new file mode 100644 index 0000000..cfa7f2c Binary files /dev/null and b/website/assets/tutorials/v153-convert-ja.webp differ diff --git a/website/assets/tutorials/v153-convert-zh.webp b/website/assets/tutorials/v153-convert-zh.webp new file mode 100644 index 0000000..c1dad28 Binary files /dev/null and b/website/assets/tutorials/v153-convert-zh.webp differ diff --git a/website/assets/tutorials/v153-size-en.webp b/website/assets/tutorials/v153-size-en.webp new file mode 100644 index 0000000..0b922e6 Binary files /dev/null and b/website/assets/tutorials/v153-size-en.webp differ diff --git a/website/assets/tutorials/v153-size-ja.webp b/website/assets/tutorials/v153-size-ja.webp new file mode 100644 index 0000000..b35756a Binary files /dev/null and b/website/assets/tutorials/v153-size-ja.webp differ diff --git a/website/assets/tutorials/v153-size-zh.webp b/website/assets/tutorials/v153-size-zh.webp new file mode 100644 index 0000000..cb2db74 Binary files /dev/null and b/website/assets/tutorials/v153-size-zh.webp differ diff --git a/website/assets/tutorials/v153-trim-en.webp b/website/assets/tutorials/v153-trim-en.webp new file mode 100644 index 0000000..fa5374a Binary files /dev/null and b/website/assets/tutorials/v153-trim-en.webp differ diff --git a/website/assets/tutorials/v153-trim-ja.webp b/website/assets/tutorials/v153-trim-ja.webp new file mode 100644 index 0000000..ce2719a Binary files /dev/null and b/website/assets/tutorials/v153-trim-ja.webp differ diff --git a/website/assets/tutorials/v153-trim-zh.webp b/website/assets/tutorials/v153-trim-zh.webp new file mode 100644 index 0000000..35b4ed5 Binary files /dev/null and b/website/assets/tutorials/v153-trim-zh.webp differ diff --git a/website/index.html b/website/index.html index f6a53b4..9c1ac9b 100644 --- a/website/index.html +++ b/website/index.html @@ -13,6 +13,7 @@
@@ -113,6 +114,8 @@

{{workflowTitle}}

+ {{guideCards}} +

{{faqTitle}}

diff --git a/website/styles.css b/website/styles.css index 142fd1f..82a9153 100644 --- a/website/styles.css +++ b/website/styles.css @@ -231,3 +231,42 @@ footer .media-credit { flex: 0 0 100%; margin-top: 5px; color: #7b889c; font-siz } @media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } .faq-list summary svg { transition: none; } } :lang(zh) h1, :lang(ja) h1, :lang(ko) h1 { line-height: 1.2; letter-spacing: -.035em; } + +/* Guides */ +.guide-section { margin-bottom: 76px; } +.guide-section h2 { margin-bottom: 24px; } +.guide-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; } +.guide-card { padding: 22px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); } +.guide-card h3 { margin-bottom: 8px; font-size: 1.12rem; line-height: 1.45; } +.guide-card h3 a { display: inline-grid; align-items: center; min-height: 44px; padding-block: 8px; color: #174da7; text-decoration: underline; text-underline-offset: 4px; } +.guide-card p { margin-bottom: 0; color: var(--muted); line-height: 1.65; } +.guide-header { justify-content: space-between; } +.guide-languages { display: flex; flex-wrap: wrap; gap: 6px 12px; } +.guide-languages a { display: grid; min-height: 44px; align-items: center; padding-inline: 8px; font-size: .86rem; } +.guide-languages a[aria-current="page"] { color: #174da7; font-weight: 700; text-decoration: underline; text-underline-offset: 4px; } +.guide-page { max-width: 850px; padding-block: clamp(24px, 5vw, 64px) 72px; } +.guide-intro { margin-bottom: 30px; } +.guide-intro h1 { max-width: 100%; margin: 12px 0; font-size: clamp(2rem, 5vw, 3rem); line-height: 1.16; letter-spacing: -.04em; } +.guide-intro p, .guide-page section p, .guide-steps li > p { margin-bottom: 0; color: var(--muted); line-height: 1.75; } +.guide-back, .guide-actions a, .guide-more a, .guide-figure a { color: #174da7; text-decoration: underline; text-underline-offset: 4px; } +.guide-back { display: inline-flex; align-items: center; min-height: 44px; font-weight: 650; } +.guide-prepare, .guide-result { padding: clamp(18px, 4vw, 26px); border: 1px solid var(--line); border-radius: 16px; background: var(--surface); overflow-wrap: anywhere; } +.guide-page h2 { margin-bottom: 8px; font-size: 1.19rem; line-height: 1.4; letter-spacing: -.02em; } +.guide-actions { display: flex; flex-wrap: wrap; gap: 4px 18px; margin-top: 10px; } +.guide-actions a { display: inline-flex; min-height: 44px; align-items: center; } +.guide-steps { display: grid; gap: 22px; margin: 32px 0; padding-left: 1.5rem; } +.guide-steps li { min-width: 0; padding-left: 4px; overflow-wrap: anywhere; } +.guide-steps li::marker { color: #174da7; font-weight: 700; } +.guide-figure { margin: 16px 0 0; } +.guide-figure img { display: block; max-width: 100%; height: auto; border: 1px solid var(--line); border-radius: 12px; } +.guide-figure figcaption { margin-top: 8px; color: var(--muted); font-size: .9rem; line-height: 1.65; } +.guide-figure a { display: inline-flex; align-items: center; min-height: 44px; padding-block: 8px; } +.guide-more { margin-top: 30px; } +.guide-more ul { margin: 0; padding-left: 1.1rem; } +.guide-more li { margin-bottom: 4px; } +.guide-more a { display: inline-block; padding-block: 10px; } +@media (max-width: 760px) { + .guide-section { margin-bottom: 54px; } + .guide-grid { grid-template-columns: minmax(0, 1fr); } + .guide-card { padding: 16px 20px; } +} diff --git a/website/tutorials.json b/website/tutorials.json new file mode 100644 index 0000000..afea7d9 --- /dev/null +++ b/website/tutorials.json @@ -0,0 +1,295 @@ +{ + "locales": { + "en": { + "heading": "MP4Flow guides", + "prepare": "Before you start", + "setup": "Install MP4Flow and confirm that FFmpeg and ffprobe are ready under “Help → Check Dependencies…”. The synthetic sample below is 12 seconds long at 640 × 360.", + "install": "Download and setup", + "sample": "Download {file}", + "verify": "Check the result", + "image": "View full-size image", + "more": "More guides", + "nav": "Guides" + }, + "zh": { + "heading": "MP4Flow 使用教程", + "prepare": "开始前", + "setup": "安装 MP4Flow,在「帮助 → 检查依赖…」确认 FFmpeg 和 ffprobe 已就绪。下面提供 12 秒、640 × 360 的合成示例。", + "install": "下载与安装", + "sample": "下载 {file}", + "verify": "检查成品", + "image": "查看原尺寸图片", + "more": "其他教程", + "nav": "教程" + }, + "ja": { + "heading": "MP4Flow の使い方", + "prepare": "はじめる前に", + "setup": "MP4Flow をインストールし、「ヘルプ → 依存ツールを確認…」で FFmpeg と ffprobe が使えることを確認します。サンプルは 12 秒、640 × 360 の合成テスト映像です。", + "install": "ダウンロードとセットアップ", + "sample": "{file} をダウンロード", + "verify": "出力を確認する", + "image": "画像を原寸で表示", + "more": "ほかのガイド", + "nav": "ガイド" + } + }, + "guides": { + "mkv-to-mp4": { + "capture": "convert", + "en": { + "title": "Convert MKV to MP4 on a Mac", + "description": "Turn the 12-second MKV sample into a playable MP4 with Smart Convert.", + "steps": [ + [ + "Add the MKV", + "Click Add Videos or drag Patterns.mkv into the conversion queue." + ], + [ + "Keep the original resolution", + "Keep Smart Convert and Balanced. Select Original under Resolution and Source Folder under Output Location. Smart Convert copies compatible video when possible." + ], + [ + "Convert and open the folder", + "Click Start. When the row shows Completed, click its folder icon (Open Folder)." + ] + ], + "result": "Open Patterns-MP4FlowConverted.mp4. Check the .mp4 extension in Finder, then play the file and verify it is about 12 seconds long at 640 × 360.", + "alt": "MP4Flow’s English queue showing a completed conversion of Patterns.mkv.", + "caption": "Completed means the MP4 is ready. The folder icon locates it in Finder.", + "media": { + "src": "assets/tutorials/v153-convert-en.webp", + "width": 980, + "height": 395, + "sha256": "727167ed2cf2877893d99bd261388b8c57e3ad2e421f628c37f16a5ad951e92f" + } + }, + "zh": { + "title": "在 Mac 上把 MKV 转成 MP4", + "description": "用智能转换将 12 秒的 MKV 示例变成可播放的 MP4。", + "steps": [ + [ + "添加 MKV", + "点击「添加视频」,或将 Patterns.mkv 拖入转换队列。" + ], + [ + "保留原始分辨率", + "保持「智能转换(推荐)」「清晰刚好」「原始尺寸」和「源文件夹」。视频编码兼容时,智能转换会优先复制视频流。" + ], + [ + "转换并找到成品", + "点击「开始转换」。队列显示「已完成」后,点击该行的文件夹图标「打开文件夹」。" + ] + ], + "result": "打开 Patterns-MP4FlowConverted.mp4,确认可以播放。在访达检查文件扩展名为 .mp4,再核对视频约 12 秒、640 × 360。", + "alt": "MP4Flow 简体中文队列中,Patterns.mkv 的转换状态为已完成。", + "caption": "队列显示「已完成」。点击该行的文件夹图标可在访达找到成品。", + "media": { + "src": "assets/tutorials/v153-convert-zh.webp", + "width": 980, + "height": 395, + "sha256": "1a0fd91bd3820cdffaf0f404841b85c8c9051e8f961334508895c8dd17282ac6" + } + }, + "ja": { + "title": "Mac で MKV を MP4 に変換する", + "description": "スマート変換で、12 秒の MKV サンプルを再生できる MP4 に変換します。", + "steps": [ + [ + "MKV を追加する", + "「動画を追加」をクリックするか、Patterns.mkv を変換キューにドラッグします。" + ], + [ + "元の解像度を保つ", + "「スマート変換(おすすめ)」「バランス」「元のサイズ」と「元のフォルダ」を選びます。互換性がある場合は映像ストリームをコピーします。" + ], + [ + "変換して保存先を開く", + "「変換を開始」をクリックします。行が「完了」になったら、フォルダアイコンの「フォルダを開く」を選びます。" + ] + ], + "result": "Patterns-MP4FlowConverted.mp4 を再生します。Finder で拡張子が .mp4 であることを確認し、長さが約 12 秒、解像度が 640 × 360 であることを確かめます。", + "alt": "Patterns.mkv の変換が完了した MP4Flow の日本語キュー。", + "caption": "「完了」と表示されたら、フォルダアイコンから Finder で出力を確認できます。", + "media": { + "src": "assets/tutorials/v153-convert-ja.webp", + "width": 980, + "height": 395, + "sha256": "484ae39377008cd8e718cc74c2266ee5b51570d11b498a314048425323697f09" + } + }, + "sample": "Patterns.mkv" + }, + "trim-mp4-clip": { + "capture": "trim", + "en": { + "title": "Trim an MOV clip to MP4 on a Mac", + "description": "Keep seconds 3–8 of the sample and export a five-second MP4 clip.", + "steps": [ + [ + "Open Trim", + "Add a fresh copy of Patterns.mov to the queue. Click the scissors icon (Trim) on its row." + ], + [ + "Choose the range to keep", + "Under Keep range, set Start to 00:00:03.000 and End to 00:00:08.000. Check that Kept Duration reads 00:00:05.000, then click Confirm Trim." + ], + [ + "Export the clip", + "Keep Smart Convert and click Start. When it finishes, use Open Folder on the completed row." + ] + ], + "result": "Play Patterns-trim-000003-000008.mp4 from start to finish. It should run for about 5 seconds and contain only the selected segment. The input MOV stays in place.", + "alt": "English trim editor with Start at 3 seconds, End at 8 seconds and a kept duration of 5 seconds.", + "caption": "The kept range starts at 00:00:03.000 and ends at 00:00:08.000.", + "media": { + "src": "assets/tutorials/v153-trim-en.webp", + "width": 760, + "height": 540, + "sha256": "7a1bdc876e4eee2a67ebfaf14c823171fa98ee9c8d481ccefb8b4d9d1a17ff33" + } + }, + "zh": { + "title": "在 Mac 上从 MOV 截取片段并导出 MP4", + "description": "保留示例的第 3–8 秒,导出 5 秒的 MP4 片段。", + "steps": [ + [ + "打开剪切", + "把一份新的 Patterns.mov 加到队列,点击该行的剪刀图标「剪切」。" + ], + [ + "设定保留范围", + "在「保留范围」中将「起始」设为 00:00:03.000,「结束」设为 00:00:08.000。确认「保留时长」为 00:00:05.000 后,点击「确认剪切」。" + ], + [ + "导出片段", + "保持「智能转换(推荐)」,点击「开始转换」。完成后点击该行的「打开文件夹」。" + ] + ], + "result": "从头播放 Patterns-trim-000003-000008.mp4,应只有选中的约 5 秒片段。原 MOV 仍保存在原处。", + "alt": "简体中文剪切窗口,起始为 3 秒、结束为 8 秒,保留时长为 5 秒。", + "caption": "「起始」为 00:00:03.000,「结束」为 00:00:08.000。", + "media": { + "src": "assets/tutorials/v153-trim-zh.webp", + "width": 760, + "height": 540, + "sha256": "4ce036a21df5edbf1a2b74487d90a06fda037e57754ba37139eae72ca8afcf60" + } + }, + "ja": { + "title": "Mac で MOV の一部を MP4 に切り出す", + "description": "サンプルの 3~8 秒を残し、5 秒の MP4 クリップにします。", + "steps": [ + [ + "トリミングを開く", + "新しい Patterns.mov をキューに追加し、行のはさみアイコン「トリミング」をクリックします。" + ], + [ + "残す範囲を指定する", + "「残す範囲」の「開始」を 00:00:03.000、「終了」を 00:00:08.000 にします。「保存する長さ」が 00:00:05.000 になったら「トリミングを確定」をクリックします。" + ], + [ + "クリップを書き出す", + "「スマート変換(おすすめ)」のまま「変換を開始」をクリックします。完了した行から「フォルダを開く」を選びます。" + ] + ], + "result": "Patterns-trim-000003-000008.mp4 を最初から再生し、選択した約 5 秒の映像だけが含まれていることを確認します。元の MOV はそのまま残ります。", + "alt": "開始 3 秒、終了 8 秒、保存する長さ 5 秒を示す日本語のトリミング画面。", + "caption": "「開始」は 00:00:03.000、「終了」は 00:00:08.000 です。", + "media": { + "src": "assets/tutorials/v153-trim-ja.webp", + "width": 760, + "height": 540, + "sha256": "737c4760eef41f6bcb9188595bb376c7916aaa3cdbed23a51eccdc830e601076" + } + }, + "sample": "Patterns.mov" + }, + "mp4-target-size": { + "capture": "size", + "en": { + "title": "Export a smaller MP4 on a Mac", + "description": "Set a 1 MB target for the MKV sample, then check the size of the exported MP4.", + "steps": [ + [ + "Open Export Settings", + "Add a fresh copy of Patterns.mkv. Click the gear icon (Export Settings) for that video." + ], + [ + "Set a 1 MB target", + "Turn on the switch next to Target Size, enter 1 MB, and click Apply Settings. A size target re-encodes the video and can reduce detail." + ], + [ + "Convert and locate the MP4", + "Keep the original resolution and click Start. Use Open Folder when the row shows Completed." + ] + ], + "result": "Compare the original MKV and output MP4 in Finder using Get Info (⌘I). In this example, the input is about 3.03 MB and the output is about 0.97 MB. The target is approximate. If you have a strict upload limit, allow some margin and check the actual file before uploading.", + "alt": "English Export Settings panel with Target Size switched on and set to 1 MB.", + "caption": "1 MB is the export target. Finder shows the actual file size.", + "media": { + "src": "assets/tutorials/v153-size-en.webp", + "width": 640, + "height": 536, + "sha256": "f6a7f59d4f84caa5cb0744c4b9e9da5f96ec7e24b05a2cb6e35fab477c357eba" + } + }, + "zh": { + "title": "在 Mac 上按目标体积导出 MP4", + "description": "把示例 MKV 的目标体积设为 1 MB,再核对导出的 MP4 有多大。", + "steps": [ + [ + "打开导出设置", + "添加一份新的 Patterns.mkv,点击该视频的齿轮图标「导出设置」。" + ], + [ + "将目标设为 1 MB", + "开启「目标体积」开关,输入 1 MB,再点击「应用设置」。按体积导出会重新编码,画面细节可能减少。" + ], + [ + "转换并找到 MP4", + "保留原始尺寸,点击「开始转换」。队列显示「已完成」后,点击「打开文件夹」。" + ] + ], + "result": "在访达分别选中原 MKV 和导出的 MP4,按 ⌘I 查看大小。本例从约 3.03 MB 导出为约 0.97 MB。目标体积是估算值。若上传有硬性限制,设置时留些余量,上传前再确认文件大小。", + "alt": "简体中文导出设置窗口中,目标体积开关已打开,数值为 1 MB。", + "caption": "1 MB 是导出目标,实际大小以访达显示为准。", + "media": { + "src": "assets/tutorials/v153-size-zh.webp", + "width": 640, + "height": 536, + "sha256": "838a7af292cfebead05c68249599e8d31cd938069435e70973ef51a1d6aa8ece" + } + }, + "ja": { + "title": "Mac で MP4 を小さいサイズに書き出す", + "description": "MKV サンプルに 1 MB の目標を設定し、実際の MP4 の容量を確認します。", + "steps": [ + [ + "書き出し設定を開く", + "新しい Patterns.mkv を追加し、動画の歯車アイコン「書き出し設定」をクリックします。" + ], + [ + "目標を 1 MB にする", + "「目標サイズ」をオンにして 1 MB を入力し、「設定を適用」をクリックします。目標サイズを使うと再エンコードされ、細部が失われることがあります。" + ], + [ + "変換して MP4 を開く", + "元の解像度のまま「変換を開始」をクリックします。行が「完了」になったら「フォルダを開く」を選びます。" + ] + ], + "result": "Finder で元の MKV と出力した MP4 をそれぞれ選び、⌘I でサイズを比較します。このサンプルは約 3.03 MB から約 0.97 MB になりました。目標は目安です。厳密なアップロード上限がある場合は余裕を持たせ、実際の容量を確認してください。", + "alt": "日本語の書き出し設定画面で、目標サイズをオンにして 1 MB を指定した状態。", + "caption": "1 MB は書き出しの目標値です。実際のサイズは Finder で確認します。", + "media": { + "src": "assets/tutorials/v153-size-ja.webp", + "width": 640, + "height": 536, + "sha256": "e5fa4dd7eb07ae1b4b3c22d62155ec5edc5dd89044eba2adef2d21e37449d23a" + } + }, + "sample": "Patterns.mkv" + } + }, + "captureVersion": "1.5.3" +} diff --git a/website/tutorials.mjs b/website/tutorials.mjs new file mode 100644 index 0000000..df37090 --- /dev/null +++ b/website/tutorials.mjs @@ -0,0 +1,106 @@ +import { readFile } from 'node:fs/promises'; + +export const tutorialContent = JSON.parse(await readFile(new URL('tutorials.json', import.meta.url), 'utf8')); +export const guidePath = (slug, id) => (id === 'en' ? '' : `${id}/`) + `guides/${slug}/`; +const escape = value => String(value).replace(/[&<>"']/g, char => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[char]); + +export function renderGuideCards(language, prefix) { + const ui = tutorialContent.locales[language]; + if (!ui) return ''; + const cards = Object.entries(tutorialContent.guides).map(([slug, story]) => ` + `).join(''); + return `
+

${escape(ui.heading)}

+
${cards}
+
`; +} + +export function renderGuide({ slug, language, languages, siteURL, styles, siteCopy, media }) { + const ui = tutorialContent.locales[language.id]; + const guide = tutorialContent.guides[slug]; + const story = guide[language.id]; + const route = guidePath(slug, language.id); + const canonical = siteURL + route; + const prefix = '../'.repeat(route.split('/').length - 1); + const home = prefix + (language.id === 'en' ? '' : language.id + '/'); + const editions = languages.filter(({ id }) => id in tutorialContent.locales); + const editionsMeta = editions.map(edition => ``).join('\n '); + const editionLinks = editions.map(edition => `${edition.name}`).join(''); + const title = `${story.title} | MP4Flow`; + const shareImage = siteURL + media.src; + const schema = { '@context': 'https://schema.org', '@type': 'Article', headline: story.title, description: story.description, url: canonical, inLanguage: language.locale, image: shareImage }; + const illustration = `
+ ${escape(story.alt)} +
${escape(story.caption)} ${escape(ui.image)}
+
`; + const illustrationIndex = slug === 'mkv-to-mp4' ? 2 : 1; + const steps = story.steps.map(([heading, body], index) => ` +
  • ${escape(heading)}

    ${escape(body)}

    ${index === illustrationIndex ? illustration : ''}
  • `).join(''); + const more = Object.entries(tutorialContent.guides).filter(([id]) => id !== slug).map(([id, guide]) => + `
  • ${escape(guide[language.id].title)}
  • `).join(''); + return ` + + + + + ${escape(title)} + + + ${editionsMeta} + + + + + + + + + + + + + + + + + + +
    + + +
    + + +`; +}