windicss 替换为 unocss

This commit is contained in:
2025-02-25 22:49:45 +08:00
parent 8abfdb2fc0
commit 986472d76d
9 changed files with 47 additions and 24 deletions

16
app.vue
View File

@@ -6,11 +6,11 @@
nav.container.mx-auto.flex.text-gray-400.text-lg.font-bold nav.container.mx-auto.flex.text-gray-400.text-lg.font-bold
template(v-for="item in navbar") template(v-for="item in navbar")
NuxtLink.px-4.py-6.transition-all.duration-150( NuxtLink.px-4.py-6.transition-all.duration-150(
class="hover:text-gray-800", class="text-gray-500 hover:text-dark-800",
:class="{ 'text-black': item.active }", :class="{ 'text-dark-800': item.active }",
:to="item.path" :to="item.path"
) {{ item.title }} ) {{ item.title }}
NuxtLink.px-4.py-6.ml-auto(to="/account" v-if="!account.padding") {{ account.online ? account.name : '登录' }} NuxtLink.px-4.py-6.ml-auto.text-gray-500(to="/account" v-if="!account.padding") {{ account.online ? account.name : '登录' }}
NuxtPage NuxtPage
</template> </template>
@@ -71,6 +71,16 @@ onMounted(() => {
</script> </script>
<style> <style>
/** 去除链接默认下划线 */
a {
text-decoration: none;
}
/** 全局字体 */
body {
font-family: 'Noto Sans SC', 'Microsoft YaHei', sans-serif;
}
/** 全局滚动条取消空间占用, 防止渲染时闪烁 */ /** 全局滚动条取消空间占用, 防止渲染时闪烁 */
::-webkit-scrollbar { ::-webkit-scrollbar {
display: none; display: none;

View File

@@ -1,9 +1,7 @@
import { defineNuxtConfig } from 'nuxt/config' import { defineNuxtConfig } from 'nuxt/config'
import { PugExtractor } from 'vite-plugin-windicss'
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({ export default defineNuxtConfig({
modules: ['nuxt-windicss'], modules: ['@unocss/nuxt'],
app: { app: {
head: { head: {
title: 'satori', title: 'satori',
@@ -12,16 +10,6 @@ export default defineNuxtConfig({
] ]
}, },
}, },
windicss: {
config: {
extract: {
extractors: [{
extractor: PugExtractor,
extensions: ['vue', 'pug'],
}]
},
},
},
nitro: { nitro: {
storage: { storage: {
blog: { blog: {
@@ -51,5 +39,6 @@ export default defineNuxtConfig({
clientPort: 3000 clientPort: 3000
} }
} }
} },
compatibilityDate: '2025-02-25'
}) })

View File

@@ -8,11 +8,13 @@
"update": "ssh satori 'cd satori; git pull; npm i; npm run build; pm2 restart satori'" "update": "ssh satori 'cd satori; git pull; npm i; npm run build; pm2 restart satori'"
}, },
"devDependencies": { "devDependencies": {
"@unocss/extractor-pug": "^66.0.0",
"@unocss/nuxt": "^66.0.0",
"@vue/compiler-sfc": "^3.3.4", "@vue/compiler-sfc": "^3.3.4",
"nuxt": "3.7.4", "nuxt": "3.15.4",
"nuxt-windicss": "^2.6.0",
"pug": "^3.0.2", "pug": "^3.0.2",
"vite-plugin-windicss": "^1.9.3" "pug-plain-loader": "^1.1.0",
"unocss": "^66.0.0"
}, },
"dependencies": { "dependencies": {
"@formkit/auto-animate": "^0.8.0", "@formkit/auto-animate": "^0.8.0",

View File

@@ -56,7 +56,7 @@ div.container.mx-auto.py-24.flex.gap-8.w-full(
span.mr-4 {{ content }} span.mr-4 {{ content }}
time.text-xs(:datetime="updatedAt || createdAt") {{ date }} time.text-xs(:datetime="updatedAt || createdAt") {{ date }}
// 右侧栏(aside) // 右侧栏(aside)
aside.w-64.py-2.flex.flex-col.gap-8(class="<sm:hidden") aside.w-64.py-2.flex.flex-col.gap-8
div(v-if="!tagPending && tags.length") div(v-if="!tagPending && tags.length")
span.font-bold # TAG span.font-bold # TAG
ul.flex.flex-wrap.gap-2.py-1 ul.flex.flex-wrap.gap-2.py-1
@@ -68,7 +68,7 @@ div.container.mx-auto.py-24.flex.gap-8.w-full(
span.font-bold # 归档 span.font-bold # 归档
template(v-for="item in data.filter(x => x.title)" :key="item.id") template(v-for="item in data.filter(x => x.title)" :key="item.id")
NuxtLink.block.truncate( NuxtLink.block.truncate(
class="hover:text-pink-500" class="text-dark-600 hover:text-pink-500 visited:text-gray-500"
:to="`/blog/${item.id}`" :to="`/blog/${item.id}`"
) {{ item.title }} ) {{ item.title }}
// 弹出层编辑器(编辑日志) // 弹出层编辑器(编辑日志)

View File

@@ -1,4 +1,4 @@
<template lang="pug"> <template lang="pug">
main.container.mx-auto.h-screen.flex.justify-center.align-center.items-center main.container.mx-auto.h-screen.flex.justify-center.align-center.items-center
div.text-red-100.text-8xl.cursor-pointer satori div.text-red-100.text-8xl.cursor-pointer.ma3 satori
</template> </template>

View File

@@ -19,6 +19,8 @@ export default defineEventHandler(async event => {
if (event.node.req.method === 'GET') { if (event.node.req.method === 'GET') {
const file_name = decodeURI(event.context.params.id) const file_name = decodeURI(event.context.params.id)
const file_path = path.resolve(dirPath, file_name) const file_path = path.resolve(dirPath, file_name)
const width = parseInt(event.node.req.query.w)
const format = event.context.params.format
// 检查文件是否存在 // 检查文件是否存在
if (!fs.existsSync(file_path)) { if (!fs.existsSync(file_path)) {

View File

@@ -13,6 +13,7 @@ if (!fs.existsSync(dirPath)) {
} }
export default defineEventHandler(async event => { export default defineEventHandler(async event => {
// 处理 GET 请求(读取image中的图片文件列表) // 处理 GET 请求(读取image中的图片文件列表)
if (event.node.req.method === 'GET') { if (event.node.req.method === 'GET') {
const files = await fs.promises.readdir(dirPath) const files = await fs.promises.readdir(dirPath)
@@ -30,6 +31,7 @@ export default defineEventHandler(async event => {
return { list } return { list }
} }
// 处理 POST 请求(FromData上传图片) // 处理 POST 请求(FromData上传图片)
if (event.node.req.method === 'POST') { if (event.node.req.method === 'POST') {
const form = formidable({ multiples: true, uploadDir: dirPath }) const form = formidable({ multiples: true, uploadDir: dirPath })
@@ -55,4 +57,5 @@ export default defineEventHandler(async event => {
return { list } return { list }
} }
}) })

17
uno.config.ts Normal file
View File

@@ -0,0 +1,17 @@
import { defineConfig, presetWind3, presetWebFonts } from 'unocss'
import extractorPug from '@unocss/extractor-pug'
export default defineConfig({
presets: [
presetWind3(),
presetWebFonts({
fonts: {
sans: 'Roboto',
mono: ['Fira Code', 'Fira Mono:400,700']
}
})
],
extractors: [
extractorPug(),
],
})