summaryrefslogtreecommitdiffhomepage
path: root/services/blog/nuldoc-src/slide
diff options
context:
space:
mode:
Diffstat (limited to 'services/blog/nuldoc-src/slide')
-rw-r--r--services/blog/nuldoc-src/slide/parse.ts20
-rw-r--r--services/blog/nuldoc-src/slide/slide.ts67
2 files changed, 87 insertions, 0 deletions
diff --git a/services/blog/nuldoc-src/slide/parse.ts b/services/blog/nuldoc-src/slide/parse.ts
new file mode 100644
index 00000000..c5a89675
--- /dev/null
+++ b/services/blog/nuldoc-src/slide/parse.ts
@@ -0,0 +1,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;
+ }
+}
diff --git a/services/blog/nuldoc-src/slide/slide.ts b/services/blog/nuldoc-src/slide/slide.ts
new file mode 100644
index 00000000..8fe99eab
--- /dev/null
+++ b/services/blog/nuldoc-src/slide/slide.ts
@@ -0,0 +1,67 @@
+import { SlideError } from "../errors.ts";
+import { Revision, stringToDate } from "../revision.ts";
+import { z } from "zod/mod.ts";
+
+export const SlideMetadataSchema = z.object({
+ slide: z.object({
+ uuid: z.string(),
+ title: z.string(),
+ event: z.string(),
+ talkType: z.string(),
+ link: z.string(),
+ tags: z.array(z.string()),
+ revisions: z.array(z.object({
+ date: z.string(),
+ remark: z.string(),
+ isInternal: z.boolean().optional(),
+ })),
+ }),
+});
+
+export type SlideMetadata = z.infer<typeof SlideMetadataSchema>;
+
+export type Slide = {
+ sourceFilePath: string;
+ uuid: string;
+ title: string;
+ event: string;
+ talkType: string;
+ slideLink: string;
+ tags: string[];
+ revisions: Revision[];
+};
+
+export function createNewSlideFromMetadata(
+ { slide }: SlideMetadata,
+ sourceFilePath: string,
+): Slide {
+ const revisions = slide.revisions.map(
+ (rev, i) => {
+ const date = rev.date;
+ const remark = rev.remark;
+ const isInternal = rev.isInternal ?? false;
+ return {
+ number: i + 1,
+ date: stringToDate(date),
+ remark,
+ isInternal,
+ };
+ },
+ );
+ if (revisions.length === 0) {
+ throw new SlideError(
+ `[slide.new] 'slide.revisions' field is empty`,
+ );
+ }
+
+ return {
+ sourceFilePath: sourceFilePath,
+ uuid: slide.uuid,
+ title: slide.title,
+ event: slide.event,
+ talkType: slide.talkType,
+ slideLink: slide.link,
+ tags: slide.tags,
+ revisions: revisions,
+ };
+}