summaryrefslogtreecommitdiffhomepage
path: root/vhosts/blog/nuldoc-src/slide/parse.ts
blob: c5a89675ac4a8836ed3bc3837f59aeb3a9d00669 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { parse as parseToml } from "@std/toml";
import {
  createNewSlideFromMetadata,
  Slide,
  SlideMetadataSchema,
} from "./slide.ts";

export async function parseSlideFile(filePath: string): Promise<Slide> {
  try {
    const root = SlideMetadataSchema.parse(
      parseToml(await Deno.readTextFile(filePath)),
    );
    return createNewSlideFromMetadata(root, filePath);
  } catch (e) {
    if (e instanceof Error) {
      e.message = `${e.message} in ${filePath}`;
    }
    throw e;
  }
}