- You did it!
-
- Visit vuejs.org to read the
- documentation
-
+
-
-
diff --git a/src/interfaces.ts b/src/interfaces.ts
new file mode 100644
index 0000000..1add3a9
--- /dev/null
+++ b/src/interfaces.ts
@@ -0,0 +1,11 @@
+export interface MarkdownAttributes {
+ title?: string
+ draft?: string
+ thumbnail?: string
+ path?: string
+}
+
+export interface MarkdownData {
+ attributes: MarkdownAttributes
+ html: string
+}
diff --git a/src/lib/articles.ts b/src/lib/articles.ts
new file mode 100644
index 0000000..9753ce5
--- /dev/null
+++ b/src/lib/articles.ts
@@ -0,0 +1,44 @@
+import type { ArticleList, MarkdownAttributes } from '@/interfaces'
+import type { MarkdownData } from '@interfaces'
+
+function completeAttributes(
+ srcAttributes: MarkdownAttributes,
+ pathPrefix: string,
+): MarkdownAttributes {
+ return {
+ draft: srcAttributes.draft ?? 'false',
+ thumbnail: srcAttributes.thumbnail
+ ? pathPrefix + srcAttributes.thumbnail
+ : pathPrefix + '/thumbnail.jpg',
+ title: srcAttributes.title ?? 'Untitled',
+ path: pathPrefix,
+ }
+}
+
+export async function loadArticle(year: number, month: number, day: number): MarkdownData | null {
+ const path = `${year}/${month.toString().padStart(2, '0')}/${day.toString().padStart(2, '0')}`
+ console.log(path)
+ try {
+ const data = (await import(
+ `@articles/${year}/${month.toString().padStart(2, '0')}/${day.toString().padStart(2, '0')}/index.md`
+ )) as MarkdownData
+ return {
+ attributes: completeAttributes(data.attributes, `./articles/${path}`),
+ html: data.html.replaceAll('./', `./articles/${path}/`),
+ }
+ } catch {
+ return null
+ }
+}
+
+export async function listArticles(): Promise