aboutsummaryrefslogtreecommitdiffhomepage
path: root/nuldoc-src/slide/slide.ts
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2023-03-17 00:48:07 +0900
committernsfisis <nsfisis@gmail.com>2023-03-18 21:02:54 +0900
commit5208a0a0f7e5703af37c9adf6d60f6c8ef10b9ee (patch)
treee2c3272f21e45acb377e70ce2d1c85811e3ab26b /nuldoc-src/slide/slide.ts
parent7688362ad3b57b0cdd6f048d1e595f69748fc183 (diff)
downloadblog.nsfisis.dev-5208a0a0f7e5703af37c9adf6d60f6c8ef10b9ee.tar.gz
blog.nsfisis.dev-5208a0a0f7e5703af37c9adf6d60f6c8ef10b9ee.tar.zst
blog.nsfisis.dev-5208a0a0f7e5703af37c9adf6d60f6c8ef10b9ee.zip
feat(nuldoc): add /slides/ page
Diffstat (limited to 'nuldoc-src/slide/slide.ts')
-rw-r--r--nuldoc-src/slide/slide.ts122
1 files changed, 122 insertions, 0 deletions
diff --git a/nuldoc-src/slide/slide.ts b/nuldoc-src/slide/slide.ts
new file mode 100644
index 0000000..859bd56
--- /dev/null
+++ b/nuldoc-src/slide/slide.ts
@@ -0,0 +1,122 @@
+import { Config } from "../config.ts";
+import { SlideError } from "../errors.ts";
+import { Revision } from "../revision.ts";
+import {
+ Element,
+ findChildElements,
+ findFirstChildElement,
+ innerText,
+} from "../dom.ts";
+
+export type Slide = {
+ sourceFilePath: string;
+ title: string;
+ event: string;
+ talkType: string;
+ slideLink: string;
+ tags: string[];
+ revisions: Revision[];
+};
+
+export function createNewSlideFromRootElement(
+ root: Element,
+ sourceFilePath: string,
+ _config: Config,
+): Slide {
+ const slide = findFirstChildElement(root, "slide");
+ if (!slide) {
+ throw new SlideError(
+ `[slide.new] <slide> element not found`,
+ );
+ }
+ const info = findFirstChildElement(slide, "info");
+ if (!info) {
+ throw new SlideError(
+ `[slide.new] <info> element not found`,
+ );
+ }
+
+ const titleElement = findFirstChildElement(info, "title");
+ if (!titleElement) {
+ throw new SlideError(
+ `[slide.new] <title> element not found`,
+ );
+ }
+ const title = innerText(titleElement).trim();
+
+ const eventElement = findFirstChildElement(info, "event");
+ if (!eventElement) {
+ throw new SlideError(
+ `[slide.new] <event> element not found`,
+ );
+ }
+ const event = innerText(eventElement).trim();
+
+ const talkTypeElement = findFirstChildElement(info, "talktype");
+ if (!talkTypeElement) {
+ throw new SlideError(
+ `[slide.new] <talktype> element not found`,
+ );
+ }
+ const talkType = innerText(talkTypeElement).trim();
+
+ const slideLinkElement = findFirstChildElement(info, "link");
+ if (!slideLinkElement) {
+ throw new SlideError(
+ `[slide.new] <link> element not found`,
+ );
+ }
+ const slideLink = innerText(slideLinkElement).trim();
+
+ const keywordsetElement = findFirstChildElement(info, "keywordset");
+ let tags: string[];
+ if (!keywordsetElement) {
+ tags = [];
+ } else {
+ tags = findChildElements(keywordsetElement, "keyword").map((x) =>
+ innerText(x).trim()
+ );
+ }
+ const revhistoryElement = findFirstChildElement(info, "revhistory");
+ if (!revhistoryElement) {
+ throw new SlideError(
+ `[slide.new] <revhistory> element not found`,
+ );
+ }
+ const revisions = findChildElements(revhistoryElement, "revision").map(
+ (x, i) => {
+ const dateElement = findFirstChildElement(x, "date");
+ if (!dateElement) {
+ throw new SlideError(
+ `[slide.new] <date> element not found`,
+ );
+ }
+ const revremarkElement = findFirstChildElement(x, "revremark");
+ if (!revremarkElement) {
+ throw new SlideError(
+ `[slide.new] <revremark> element not found`,
+ );
+ }
+ return {
+ number: i + 1,
+ date: innerText(dateElement).trim(),
+ remark: innerText(revremarkElement).trim(),
+ };
+ },
+ );
+ if (revisions.length === 0) {
+ throw new SlideError(
+ `[slide.new] <revision> element not found`,
+ );
+ }
+
+ return {
+ sourceFilePath: sourceFilePath,
+ title: title,
+ event: event,
+ talkType: talkType,
+ slideLink: slideLink,
+ tags: tags,
+ revisions: revisions,
+ };
+}