import { glob } from 'glob'; import { read_text } from '../fs'; import { BuildState } from './state'; import { build_partials, file_hash_matches, map_input_file_to_output_file, map_output_file_to_url, render_page, skip_file, update_metadata } from './helpers'; export async function render_markdown_files(state: BuildState) { const promises: Promise[] = [ ]; const files = await glob(state.conf.input.markdown, { absolute: true, cwd: state.conf.input.root, }); if (! state.partials) { await build_partials(state); } for (const in_file of files) { if (state.seen_files.has(in_file)) { continue; } state.seen_files.add(in_file); promises.push( render_markdown_file(state, in_file) ); } await Promise.all(promises); } export async function render_markdown_file(state: BuildState, in_file: string) { const out_file = await map_input_file_to_output_file(state, in_file, [ '.md', '.markdown' ], '.html'); const out_url = map_output_file_to_url(state, out_file); const { frontmatter, text, hash } = await read_text(in_file); if (frontmatter?.skip) { return; } if (file_hash_matches(state, in_file, hash)) { return skip_file(state, in_file, out_file, out_url, frontmatter); } await render_page(state, out_file, out_url, text, true, frontmatter); update_metadata(state, in_file, hash); }