Generate web slides from Markdoc
at main 1.4 kB view raw
1import { 2 build, 3 type Config, 4 defineConfig, 5 parse, 6 type TokenNormalized, 7} from "@terrazzo/parser"; 8import pluginCss from "@terrazzo/plugin-css"; 9 10export function prefixToken(token: TokenNormalized) { 11 return `--morkdeck-${token.$type}-${token.id.replace(/\./g, "-")}`; 12} 13 14const configBase: Config = { 15 plugins: [ 16 pluginCss({ 17 variableName: prefixToken, 18 baseSelector: ":root", 19 }), 20 ], 21}; 22 23export async function compileCss(themePath?: string) { 24 const config = defineConfig(configBase, { 25 cwd: new URL(import.meta.url), 26 }); 27 28 const tokensUrl = new URL("./tokens", import.meta.url); 29 const files: Array<{ src: string; filename: URL }> = []; 30 const tokenSources = Deno.readDir(tokensUrl); 31 for await (const source of tokenSources) { 32 if (source.isFile) { 33 const filename = new URL(`tokens/${source.name}`, tokensUrl); 34 files.push({ 35 filename, 36 src: await Deno.readTextFile(filename), 37 }); 38 } 39 } 40 41 if (themePath) { 42 const themeUrl = new URL(themePath, Deno.cwd()); 43 files.push({ 44 filename: new URL(themePath, Deno.cwd()), 45 src: await Deno.readTextFile(themeUrl), 46 }); 47 } 48 49 const { tokens, sources } = await parse(files, { config }); 50 const buildResult = await build(tokens, { sources, config }); 51 52 return buildResult.outputFiles.map((f) => f.contents).join("\n\n"); 53}