π₯ Make videos programmatically with React
some SEO titles
Jonny Burger644a474adeb2
diff --git a/packages/convert/app/components/Main.tsx b/packages/convert/app/components/Main.tsxindex 0be413c8d0..19fa5360e7 100644--- a/packages/convert/app/components/Main.tsx+++ b/packages/convert/app/components/Main.tsx@@ -1,16 +1,21 @@-import React, {useState} from 'react';+import React, {useEffect, useState} from 'react';import {SAMPLE_FILE, TEST_FAST} from '~/lib/config';import {Source} from '~/lib/convert-state';import {FileAvailable} from './FileAvailable';import {PickFile} from './PickFile';export const Main: React.FC<{- readonly title: string;-}> = ({title}) => {+ readonly headerTitle: string;+ readonly pageTitle: string;+}> = ({headerTitle, pageTitle}) => {const [src, setSrc] = useState<Source | null>(TEST_FAST ? {type: 'url', url: SAMPLE_FILE} : null,);+ useEffect(() => {+ document.title = pageTitle;+ }, [pageTitle]);+return (<div className="font-sans min-h-screen ">{src ? (@@ -20,7 +25,7 @@ export const Main: React.FC<{setSrc={setSrc}/>) : (- <PickFile setSrc={setSrc} title={title} />+ <PickFile setSrc={setSrc} title={headerTitle} />)}</div>);diff --git a/packages/convert/app/root.tsx b/packages/convert/app/root.tsxindex 73d217fa1c..7aca28603e 100644--- a/packages/convert/app/root.tsx+++ b/packages/convert/app/root.tsx@@ -8,10 +8,8 @@ export function Layout({children}: {readonly children: React.ReactNode}) {<meta charSet="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" /><title>Remotion Convert</title>- <meta- name="description"- content="Fast video conversion in the browser."- />+ <meta name="description" content="Remotion Convert" />+ <link rel="icon" href="https://www.remotion.dev/img/favicon.png" /><Links /></head><body>diff --git a/packages/convert/app/routes/_index.tsx b/packages/convert/app/routes/_index.tsxindex c9c7b3e39e..429d9f06e4 100644--- a/packages/convert/app/routes/_index.tsx+++ b/packages/convert/app/routes/_index.tsx@@ -1,7 +1,10 @@import {Main} from '~/components/Main';+import {getHeaderTitle, getPageTitle} from '~/seo';const Index = () => {- return <Main title="Fast video conversion in the browser" />;+ return (+ <Main headerTitle={getHeaderTitle(null)} pageTitle={getPageTitle(null)} />+ );};export default Index;diff --git a/packages/convert/app/routes/convert-mp4-to-webm.tsx b/packages/convert/app/routes/convert-mp4-to-webm.tsxdeleted file mode 100644index cb04dd7b22..0000000000--- a/packages/convert/app/routes/convert-mp4-to-webm.tsx+++ /dev/null@@ -1,7 +0,0 @@-import {Main} from '~/components/Main';--const Index = () => {- return <Main title="Fast MP4 to WebM conversion in the browser" />;-};--export default Index;diff --git a/packages/convert/app/routes/convert-webm-to-mp4.tsx b/packages/convert/app/routes/convert-webm-to-mp4.tsxdeleted file mode 100644index 1a04e3a59f..0000000000--- a/packages/convert/app/routes/convert-webm-to-mp4.tsx+++ /dev/null@@ -1,7 +0,0 @@-import {Main} from '~/components/Main';--const Index = () => {- return <Main title="Fast WebM to MP4 conversion in the browser" />;-};--export default Index;diff --git a/packages/convert/app/routes/convert.$action.tsx b/packages/convert/app/routes/convert.$action.tsxnew file mode 100644index 0000000000..fbff7b2966--- /dev/null+++ b/packages/convert/app/routes/convert.$action.tsx@@ -0,0 +1,16 @@+import {useParams} from '@remix-run/react';+import {Main} from '~/components/Main';+import {getHeaderTitle, getPageTitle, parseRouteAction} from '~/seo';++const Index = () => {+ const {input, output} = parseRouteAction(useParams().action as string);++ return (+ <Main+ pageTitle={getPageTitle({input, output, type: 'convert'})}+ headerTitle={getHeaderTitle({input, output, type: 'convert'})}+ />+ );+};++export default Index;diff --git a/packages/convert/app/routes/convert._index.tsx b/packages/convert/app/routes/convert._index.tsxnew file mode 100644index 0000000000..429d9f06e4--- /dev/null+++ b/packages/convert/app/routes/convert._index.tsx@@ -0,0 +1,10 @@+import {Main} from '~/components/Main';+import {getHeaderTitle, getPageTitle} from '~/seo';++const Index = () => {+ return (+ <Main headerTitle={getHeaderTitle(null)} pageTitle={getPageTitle(null)} />+ );+};++export default Index;diff --git a/packages/convert/app/routes/convert.tsx b/packages/convert/app/routes/convert.tsxdeleted file mode 100644index c9c7b3e39e..0000000000--- a/packages/convert/app/routes/convert.tsx+++ /dev/null@@ -1,7 +0,0 @@-import {Main} from '~/components/Main';--const Index = () => {- return <Main title="Fast video conversion in the browser" />;-};--export default Index;diff --git a/packages/convert/app/seo.ts b/packages/convert/app/seo.tsnew file mode 100644index 0000000000..2349017f20--- /dev/null+++ b/packages/convert/app/seo.ts@@ -0,0 +1,54 @@+import {+ ConvertMediaContainer,+ getAvailableContainers,+} from '@remotion/webcodecs';+import {renderHumanReadableContainer} from './lib/render-codec-label';++export const inputContainers: ConvertMediaContainer[] = ['mp4', 'webm'];+export const outputContainers = getAvailableContainers();++export const parseRouteAction = (action: string) => {+ const split = action.split('-to-');+ if (split.length !== 2) {+ throw new Error('Invalid action');+ }++ if (split[0] === split[1]) {+ throw new Error('Input and output container cannot be the same');+ }++ return {+ input: split[0] as ConvertMediaContainer,+ output: split[1] as ConvertMediaContainer,+ };+};++export type RouteAction = {+ type: 'convert';+ input: ConvertMediaContainer;+ output: ConvertMediaContainer;+};++export const getHeaderTitle = (routeAction: RouteAction | null) => {+ if (routeAction && routeAction.type === 'convert') {+ return `Fast ${renderHumanReadableContainer(routeAction.input)} β ${renderHumanReadableContainer(routeAction.output)} conversion in the browser`;+ }++ return 'Fast video conversion in the browser';+};++export const getPageTitle = (routeAction: RouteAction | null) => {+ if (routeAction === null) {+ return 'Remotion Convert β Fast video conversion in the browser';+ }++ return `Online ${renderHumanReadableContainer(routeAction.input)} to ${renderHumanReadableContainer(routeAction.output)} converter - Remotion Convert`;+};++export const getDescription = (routeAction: RouteAction | null) => {+ if (routeAction === null) {+ return 'The fastest online video converter, powered by WebCodecs. No upload required, no watermarks, no limits.';+ }++ return `The fastest online ${renderHumanReadableContainer(routeAction.input)} to ${renderHumanReadableContainer(routeAction.output)} converter, powered by WebCodecs. No upload required, no watermarks, no limits.`;+};diff --git a/packages/docs/copy-convert.ts b/packages/docs/copy-convert.tsindex 127fb671a3..50d56d395b 100644--- a/packages/docs/copy-convert.ts+++ b/packages/docs/copy-convert.ts@@ -1,6 +1,8 @@import {$} from 'bun';-import fs from 'fs';+import fs, {readFileSync, writeFileSync} from 'fs';import path from 'path';+// @ts-ignore outside project+import * as seo from '../convert/app/seo';await $`bunx turbo "@remotion/convert#build-spa"`;@@ -8,11 +10,64 @@ const dir = path.join(__dirname, '../convert/spa-dist/client');fs.cpSync(dir, path.join(__dirname, './build/convert'), {recursive: true});-const extraSlugs = ['convert-mp4-to-webm'];-for (const slug of extraSlugs) {- const out = path.join(__dirname, `./build/${slug}/index.html`);+const extraPages: {+ slug: string;+ pageTitle: string;+ description: string;+}[] = [];++for (const inputs of seo.inputContainers) {+ for (const outputs of seo.outputContainers) {+ extraPages.push({+ slug: `/convert/${inputs}-to-${outputs}`,+ pageTitle: seo.getPageTitle({+ input: inputs,+ output: outputs,+ type: 'convert',+ }),+ description: seo.getDescription({+ input: inputs,+ output: outputs,+ type: 'convert',+ }),+ });+ }+}++const contents = path.join(dir, 'index.html');++// Replace the text in <title>+const getContentWithTitle = (title: string, description: string) => {+ const c = readFileSync(contents, 'utf-8');+ const matcher = '<title>Remotion Convert</title>';++ if (!c.includes(matcher)) {+ throw new Error('Could not find title');+ }++ const descriptionMatcher =+ '<meta name="description" content="Remotion Convert"/>';+ if (!c.includes(descriptionMatcher)) {+ throw new Error('Could not find description');+ }++ return c+ .replace(+ descriptionMatcher,+ `<meta name="description" content="${description}" />`,+ )+ .replace(matcher, `<title>${title}</title>`);+};++writeFileSync(+ path.join(__dirname, './build/convert/index.html'),+ getContentWithTitle(seo.getPageTitle(null), seo.getDescription(null)),+);++for (const page of extraPages) {+ const out = path.join(__dirname, `./build/${page.slug}/index.html`);if (!fs.existsSync(path.dirname(out))) {fs.mkdirSync(path.dirname(out), {recursive: true});}- fs.copyFileSync(path.join(dir, 'index.html'), out);+ fs.writeFileSync(out, getContentWithTitle(page.pageTitle, page.description));}