diff --git a/src/lib/writeTemplate.ts b/src/lib/write-template.ts similarity index 78% rename from src/lib/writeTemplate.ts rename to src/lib/write-template.ts index fd390a48..f85b6b18 100644 --- a/src/lib/writeTemplate.ts +++ b/src/lib/write-template.ts @@ -7,7 +7,12 @@ import { copyFileSync, existsSync, mkdirSync, writeFileSync } from 'fs'; * @param html The HTML to write * @param css The CSS to write */ -const writeTemplate = (template: string, html: string, css: string) => { +const writeTemplate = ( + template: string, + type: 'ssr' | 'csr', + html: string, + css: string, +) => { const outDir = `build-static/${template}`; mkdirSync(outDir, { recursive: true }); @@ -15,7 +20,7 @@ const writeTemplate = (template: string, html: string, css: string) => { writeFileSync(`${outDir}/index.html`, html, 'utf-8'); writeFileSync(`${outDir}/style.css`, css, 'utf-8'); - const adJSON = `src/templates/csr/${template}/ad.json`; + const adJSON = `src/templates/${type}/${template}/ad.json`; if (existsSync(adJSON)) { copyFileSync(adJSON, `${outDir}/ad.json`); diff --git a/src/routes/csr/[template].json.ts b/src/routes/csr/[template].json.ts index 07a031d3..ad4c8b8c 100644 --- a/src/routes/csr/[template].json.ts +++ b/src/routes/csr/[template].json.ts @@ -4,7 +4,7 @@ import { marked } from 'marked'; import { getCommit } from '$lib/git'; import { build } from '$lib/rollup'; import { getProps } from '$lib/svelte'; -import { writeTemplate } from '$lib/writeTemplate'; +import { writeTemplate } from '$lib/write-template'; const github = 'https://github.com/guardian/commercial-templates/blob'; @@ -59,7 +59,7 @@ export const GET: RequestHandler = async ({ params }) => { ? marked.parse(readFileSync(`${dir}/README.md`, 'utf-8')) : `

no description provided

`; - writeTemplate(template, html, css); + writeTemplate(template, 'csr', html, css); return { body: { diff --git a/src/routes/ssr/[template].json.ts b/src/routes/ssr/[template].json.ts index a9dd039e..87bdecbe 100644 --- a/src/routes/ssr/[template].json.ts +++ b/src/routes/ssr/[template].json.ts @@ -6,7 +6,7 @@ import type { OutputAsset, OutputChunk } from 'rollup'; import { getCommit } from '$lib/git'; import { build } from '$lib/rollup'; import { getProps } from '$lib/svelte'; -import { writeTemplate } from '$lib/writeTemplate'; +import { writeTemplate } from '$lib/write-template'; type Output = { html?: string; @@ -100,7 +100,7 @@ export const GET: RequestHandler = async ({ params }) => { ? marked.parse(readFileSync(`${dir}/README.md`, 'utf-8')) : `

no description provided

`; - writeTemplate(template, html, css); + writeTemplate(template, 'ssr', html, css); return { body: {