From 9bae3a813d5111d9bd997fc2b16565e7a4709165 Mon Sep 17 00:00:00 2001 From: klemek Date: Fri, 24 Apr 2026 23:43:08 +0200 Subject: [PATCH] feat: page title --- .env.example | 3 +++ .gitignore | 1 + bun.lock | 1 + index.html | 4 ++-- src/components/PageFooter.vue | 16 ++++++++++++++++ src/lib/meta.ts | 2 ++ src/views/ArticleView.vue | 22 ++++++---------------- src/views/HomeView.vue | 9 ++++++--- src/views/NotFoundView.vue | 12 ++++++++++-- tsconfig.app.json | 3 ++- vite.config.ts | 1 + 11 files changed, 50 insertions(+), 24 deletions(-) create mode 100644 .env.example create mode 100644 src/components/PageFooter.vue diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..9939800 --- /dev/null +++ b/.env.example @@ -0,0 +1,3 @@ +VITE_APP_TITLE=My Blog +VITE_APP_SIGNATURE=By me +VITE_APP_LANG=en \ No newline at end of file diff --git a/.gitignore b/.gitignore index cd68f14..f5bdc70 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,4 @@ __screenshots__/ # Vite *.timestamp-*-*.mjs +.env \ No newline at end of file diff --git a/bun.lock b/bun.lock index 8a0ea9f..00f7bd9 100644 --- a/bun.lock +++ b/bun.lock @@ -1,5 +1,6 @@ { "lockfileVersion": 1, + "configVersion": 0, "workspaces": { "": { "name": "md-blog", diff --git a/index.html b/index.html index 0f75371..e61045e 100644 --- a/index.html +++ b/index.html @@ -1,10 +1,10 @@ - + - Blog + %VITE_APP_TITLE% diff --git a/src/components/PageFooter.vue b/src/components/PageFooter.vue new file mode 100644 index 0000000..a19f3b1 --- /dev/null +++ b/src/components/PageFooter.vue @@ -0,0 +1,16 @@ + + + diff --git a/src/lib/meta.ts b/src/lib/meta.ts index a17dec5..14f5645 100644 --- a/src/lib/meta.ts +++ b/src/lib/meta.ts @@ -3,3 +3,5 @@ import packageJson from '@/../package.json' export const NAME = packageJson.name export const VERSION = packageJson.version export const REPOSITORY = packageJson.repository +export const TITLE = import.meta.env.VITE_APP_TITLE +export const SIGNATURE = import.meta.env.VITE_APP_SIGNATURE diff --git a/src/views/ArticleView.vue b/src/views/ArticleView.vue index 306e4f9..b0aa178 100644 --- a/src/views/ArticleView.vue +++ b/src/views/ArticleView.vue @@ -5,10 +5,11 @@ import { loadArticle } from '@lib/articles' import { useRoute, onBeforeRouteUpdate, type RouteLocation } from 'vue-router' import NotFoundView from './NotFoundView.vue' import { dateFromParts, simpleDateFormat } from '@lib/dates' -import { NAME, REPOSITORY, VERSION } from '@lib/meta' +import { SIGNATURE, TITLE } from '@lib/meta' +import PageFooter from '@components/PageFooter.vue' const article = ref
(null) -const loading = ref(true) +const loading = ref(true) const route = useRoute() async function loadPage(target: RouteLocation) { @@ -20,13 +21,10 @@ async function loadPage(target: RouteLocation) { target.params.day as string, ), ) + window.document.title = TITLE + ' — ' + (article.value?.metadata.title ?? 'Not Found') loading.value = false } -function scrollTop() { - window.scrollTo(0, 0) -} - onBeforeMount(() => loadPage(route)) onBeforeRouteUpdate(loadPage) @@ -50,17 +48,9 @@ onBeforeRouteUpdate(loadPage) thumbnail
-
TODO signature
+

- Go to top - - Back to home -
-
- - {{ new Date().getFullYear() }} - Made with {{ NAME }} - {{ VERSION }} - -
+ diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue index ecf2ca5..1dbbd66 100644 --- a/src/views/HomeView.vue +++ b/src/views/HomeView.vue @@ -2,20 +2,22 @@ import { ref, onBeforeMount } from 'vue' import { listArticles } from '@lib/articles' import type { ArticleMetadata } from '@interfaces' -import { simpleDateFormat } from '@/lib/dates' +import { simpleDateFormat } from '@lib/dates' +import { TITLE } from '@lib/meta' +import PageFooter from '@components/PageFooter.vue' const articles = ref([]) onBeforeMount(async () => { const newArticles = await listArticles() - console.log(newArticles) articles.value.splice(0, articles.value.length, ...newArticles) + window.document.title = TITLE + ' — Home' }) diff --git a/src/views/NotFoundView.vue b/src/views/NotFoundView.vue index 48bda74..c0717dc 100644 --- a/src/views/NotFoundView.vue +++ b/src/views/NotFoundView.vue @@ -1,9 +1,17 @@ - + diff --git a/tsconfig.app.json b/tsconfig.app.json index 2ad17d6..3876e79 100644 --- a/tsconfig.app.json +++ b/tsconfig.app.json @@ -12,7 +12,8 @@ "@lib/*": ["./src/lib/*"], "@views/*": ["./src/views/*"], "@interfaces": ["./src/interfaces.ts"], - "@articles/*": ["./articles/*"] + "@articles/*": ["./articles/*"], + "@components/*": ["./src/components/*"] }, // `vue-tsc --build` produces a .tsbuildinfo file for incremental type-checking. diff --git a/vite.config.ts b/vite.config.ts index e6b5bc9..1afb172 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -15,6 +15,7 @@ export default defineConfig({ '@lib': fileURLToPath(new URL('./src/lib', import.meta.url)), '@articles': fileURLToPath(new URL('./articles', import.meta.url)), '@interfaces': fileURLToPath(new URL('./src/interfaces.ts', import.meta.url)), + '@components': fileURLToPath(new URL('./src/components', import.meta.url)), }, }, assetsInclude: [/\.\/articles\/.*(?!\.md)'/],