Skip to content

Commit bfe4c9a

Browse files
committed
feat: auto module
1 parent f59e107 commit bfe4c9a

10 files changed

+66
-26
lines changed

index.html

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
<meta http-equiv="X-UA-Compatible" content="chrome=1" />
88
<meta name="revisit-after" content="7 days" />
99
<meta name="viewport" content="width=device-width, initial-scale=1.0">
10+
<meta name="keywords" content="ntnyq">
11+
<meta name="description" content="ntnyq's website">
1012
<meta name="theme-color" content="#ffffff" />
1113
<link rel="shortcut icon" href="/static/icons/favicon.png" type="image/png" />
1214
<link href="https://fonts.googleapis.com/css2?family=Fira+Code&family=Inter:wght@200;400;600&display=swap" rel="stylesheet" />

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"vite-ssg-sitemap": "^0.2.2"
4949
},
5050
"dependencies": {
51+
"@gtm-support/vue-gtm": "^1.4.0",
5152
"@vueuse/core": "^8.2.6",
5253
"@vueuse/head": "^0.7.6",
5354
"nprogress": "^0.2.0",

pnpm-lock.yaml

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/ThemeToggle.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<template>
2-
<a
2+
<span
33
@click="toggleDark"
44
title="Toggle Color Scheme"
5-
class="select-none"
5+
class="select-none cursor-pointer"
66
>
77
<IRiMoonLine v-if="isDark" />
88
<IRiSunLine v-else />
9-
</a>
9+
</span>
1010
</template>
1111

1212
<script setup lang="ts">

src/main.ts

+11-17
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
import pages from '~pages'
2+
import { ViteSSG } from 'vite-ssg'
3+
import type { RouterScrollBehavior } from 'vue-router'
4+
import App from './App.vue'
5+
16
import '@unocss/reset/tailwind.css'
27
import 'uno.css'
38
import '@/styles/main.css'
49
import '@/styles/prose.css'
510
import '@/styles/markdown.css'
6-
import pages from '~pages'
7-
import { ViteSSG } from 'vite-ssg'
8-
import NPprogress from 'nprogress'
9-
import type { RouterScrollBehavior } from 'vue-router'
10-
import App from './App.vue'
1111

1212
const routes = pages.map(route => ({
1313
...route,
@@ -20,16 +20,10 @@ const scrollBehavior: RouterScrollBehavior = (_, __, savedPosition) =>
2020

2121
export const createApp = ViteSSG(
2222
App,
23-
{ routes, scrollBehavior },
24-
({ router, isClient }) => {
25-
if (isClient) {
26-
router.beforeEach(() => {
27-
NPprogress.start()
28-
})
29-
30-
router.afterEach(() => {
31-
NPprogress.done()
32-
})
33-
}
34-
}
23+
{ routes, scrollBehavior, base: import.meta.env.BASE_URL },
24+
ctx => {
25+
Object.values(import.meta.globEager(`./modules/*.ts`)).forEach(i =>
26+
i.install?.(ctx),
27+
)
28+
},
3529
)

src/modules/gtm.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { createGtm } from '@gtm-support/vue-gtm'
2+
import type { UserModule } from '@/types'
3+
4+
export const install: UserModule = ({ app }) => {
5+
app.use(createGtm({ id: `GTM-T497H2P` }))
6+
}

src/modules/nprogress.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import NProgress from 'nprogress'
2+
import { type UserModule } from '@/types'
3+
4+
export const install: UserModule = ({ isClient, router }) => {
5+
if (!isClient) return
6+
router.beforeEach((to, from) => {
7+
if (to.path === from.path) return
8+
NProgress.start()
9+
})
10+
router.afterEach(() => NProgress.done())
11+
}

src/modules/pwa.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { type UserModule } from '@/types'
2+
3+
export const install: UserModule = async ({ isClient, router }) => {
4+
if (!isClient) return
5+
await router.isReady()
6+
const { registerSW } = await import(`virtual:pwa-register`)
7+
registerSW({ immediate: true })
8+
}

src/types/index.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { type ViteSSGContext } from 'vite-ssg'
2+
3+
export type UserModule = (ctx: ViteSSGContext) => void

vite.config.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,7 @@ export default defineConfig({
7474
presets: [
7575
presetUno(),
7676
presetIcons({
77-
extraProperties: {
78-
dispaly: `inline-block`,
79-
height: `1.2em`,
80-
width: `1.2em`,
81-
'vertical-align': `text-bottom`,
82-
},
77+
warn: true,
8378
}),
8479
],
8580
}),

0 commit comments

Comments
 (0)