feat: web based SPA

This commit is contained in:
2026-04-25 19:15:41 +02:00
parent a18a25294c
commit 9162c149c4
5 changed files with 10 additions and 12 deletions
+1
View File
@@ -13,6 +13,7 @@ This template should help get you started developing with Vue 3 in Vite.
- [x] link to home - [x] link to home
- [ ] link to previous/next article - [ ] link to previous/next article
- [x] set page title - [x] set page title
- [ ] SPA and opengraph
## Recommended IDE Setup ## Recommended IDE Setup
+5 -7
View File
@@ -12,9 +12,7 @@ function parseMetadata(
title: decodeURIComponent((srcAttributes.title as string) ?? 'Untitled'), title: decodeURIComponent((srcAttributes.title as string) ?? 'Untitled'),
date: date, date: date,
author: decodeURIComponent((srcAttributes.author as string) ?? ''), author: decodeURIComponent((srcAttributes.author as string) ?? ''),
thumbnail: srcAttributes.thumbnail thumbnail: (srcAttributes.thumbnail as string) ?? '',
? (srcAttributes.thumbnail as string).replaceAll('./', pathPrefix + '/')
: pathPrefix + '/thumbnail.jpg',
draft: !!srcAttributes.draft, draft: !!srcAttributes.draft,
} }
} }
@@ -50,8 +48,8 @@ function transformMermaidBlocks(srcHtml: string): string {
return outHtml return outHtml
} }
function transformHtml(srcHtml: string, pathPrefix: string): string { function transformHtml(srcHtml: string): string {
let outHtml: string = srcHtml.replaceAll('="./', '="' + pathPrefix + '/') let outHtml: string = srcHtml
outHtml = transformLatexBlocks(outHtml) outHtml = transformLatexBlocks(outHtml)
outHtml = transformMermaidBlocks(outHtml) outHtml = transformMermaidBlocks(outHtml)
return outHtml return outHtml
@@ -61,12 +59,12 @@ export async function loadArticle(date: Date): Promise<Article | null> {
const year = date.getFullYear().toString() const year = date.getFullYear().toString()
const month = (date.getMonth() + 1).toString().padStart(2, '0') const month = (date.getMonth() + 1).toString().padStart(2, '0')
const day = date.getDate().toString().padStart(2, '0') const day = date.getDate().toString().padStart(2, '0')
const path = `./articles/${year}/${month}/${day}` const path = `./articles/${year}/${month}/${day}/`
try { try {
const data = (await import(`@articles/${year}/${month}/${day}/index.md`)) as MarkdownData const data = (await import(`@articles/${year}/${month}/${day}/index.md`)) as MarkdownData
return { return {
metadata: parseMetadata(data.attributes, path, date), metadata: parseMetadata(data.attributes, path, date),
html: transformHtml(data.html, path), html: transformHtml(data.html),
} }
} catch (ex) { } catch (ex) {
console.error(ex) console.error(ex)
+3 -3
View File
@@ -1,13 +1,13 @@
import ArticleView from '@views/ArticleView.vue' import ArticleView from '@views/ArticleView.vue'
import HomeView from '@views/HomeView.vue' import HomeView from '@views/HomeView.vue'
import NotFoundView from '@views/NotFoundView.vue' import NotFoundView from '@views/NotFoundView.vue'
import { createRouter, createWebHashHistory } from 'vue-router' import { createRouter, createWebHistory } from 'vue-router'
const router = createRouter({ const router = createRouter({
history: createWebHashHistory(), history: createWebHistory(),
routes: [ routes: [
{ path: '/', component: HomeView }, { path: '/', component: HomeView },
{ path: '/articles/:year(\\d{4})/:month(\\d{2})/:day(\\d{2})', component: ArticleView }, { path: '/articles/:year(\\d{4})/:month(\\d{2})/:day(\\d{2})/', component: ArticleView },
{ path: '/:pathMatch(.*)', component: NotFoundView }, { path: '/:pathMatch(.*)', component: NotFoundView },
], ],
}) })
+1 -1
View File
@@ -26,7 +26,7 @@ onBeforeMount(async () => {
<span class="time" <span class="time"
><span>Published on</span>&nbsp;&nbsp;{{ simpleDateFormat(metadata.date) }}</span ><span>Published on</span>&nbsp;&nbsp;{{ simpleDateFormat(metadata.date) }}</span
> >
<img alt="thumbnail" :src="metadata.thumbnail" /> <img alt="thumbnail" :src="metadata.path + metadata.thumbnail" />
</RouterLink> </RouterLink>
</div> </div>
</template> </template>
-1
View File
@@ -18,5 +18,4 @@ export default defineConfig({
'@components': fileURLToPath(new URL('./src/components', import.meta.url)), '@components': fileURLToPath(new URL('./src/components', import.meta.url)),
}, },
}, },
assetsInclude: [/\.\/articles\/.*'/],
}) })