aboutsummaryrefslogtreecommitdiffhomepage
path: root/nuldoc-src/docbook/document.ts
diff options
context:
space:
mode:
Diffstat (limited to 'nuldoc-src/docbook/document.ts')
-rw-r--r--nuldoc-src/docbook/document.ts56
1 files changed, 45 insertions, 11 deletions
diff --git a/nuldoc-src/docbook/document.ts b/nuldoc-src/docbook/document.ts
index b779ac7..ae3159a 100644
--- a/nuldoc-src/docbook/document.ts
+++ b/nuldoc-src/docbook/document.ts
@@ -9,7 +9,7 @@ import {
innerText,
} from "../dom.ts";
-export type Document = {
+export class Document {
root: Element;
sourceFilePath: string;
link: string;
@@ -17,7 +17,41 @@ export type Document = {
summary: string; // TODO: should it be markup text?
tags: string[];
revisions: Revision[];
-};
+
+ constructor(
+ root: Element,
+ sourceFilePath: string,
+ link: string,
+ title: string,
+ summary: string,
+ tags: string[],
+ revisions: Revision[],
+ ) {
+ this.root = root;
+ this.sourceFilePath = sourceFilePath;
+ this.link = link;
+ this.title = title;
+ this.summary = summary;
+ this.tags = tags;
+ this.revisions = revisions;
+ }
+
+ getLatestRevision(): Revision {
+ return this.revisions[this.revisions.length - 1];
+ }
+
+ getOldestRevision(): Revision {
+ return this.revisions[0];
+ }
+
+ getUpdatedDate(): string {
+ return this.getLatestRevision().date;
+ }
+
+ getCreatedDate(): string {
+ return this.getOldestRevision().date;
+ }
+}
export function createNewDocumentFromRootElement(
root: Element,
@@ -96,13 +130,13 @@ export function createNewDocumentFromRootElement(
const cwd = Deno.cwd();
const contentDir = join(cwd, config.locations.contentDir);
const link = sourceFilePath.replace(contentDir, "").replace(".xml", "/");
- return {
- root: root,
- title: title,
- summary: summary,
- tags: tags,
- revisions: revisions,
- sourceFilePath: sourceFilePath,
- link: link,
- };
+ return new Document(
+ root,
+ sourceFilePath,
+ link,
+ title,
+ summary,
+ tags,
+ revisions,
+ );
}