From c2be826bc5852b50ba87f3990bdd57dda8ddd293 Mon Sep 17 00:00:00 2001 From: Miao_Spring <539943419@qq.com> Date: Sun, 12 Jan 2025 23:31:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=87=8D=E6=9E=84=E9=83=A8=E5=88=86?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=EF=BC=8C=E7=95=A5=E5=BE=AE=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E6=96=87=E7=AB=A0md=E6=B8=B2=E6=9F=93=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 3 + hooks/useMarkdownit.ts | 10 ++++ nuxt.config.ts | 8 ++- package.json | 2 + .../genshin-gacha.vue => iframe/[url].vue} | 7 ++- pages/index.vue | 15 ++++- pages/posts/index.vue | 8 +-- pages/posts/post-[id].vue | 58 ++++++++++++++++++ pnpm-lock.yaml | 60 +++++++++++++++++++ server/api/posts/getPostContent.ts | 38 ++++++++++++ .../api/posts/{getPosts.ts => getPostList.ts} | 0 tsconfig.json | 2 +- 12 files changed, 200 insertions(+), 11 deletions(-) create mode 100644 hooks/useMarkdownit.ts rename pages/{tool/genshin-gacha.vue => iframe/[url].vue} (64%) create mode 100644 pages/posts/post-[id].vue create mode 100644 server/api/posts/getPostContent.ts rename server/api/posts/{getPosts.ts => getPostList.ts} (100%) diff --git a/.vscode/settings.json b/.vscode/settings.json index 8d12247..c51dbfd 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,8 @@ { "cSpell.words": [ + "linkify", + "Markdownit", + "mdit", "unplugin" ], "vue3snippets.enable-compile-vue-file-on-did-save-code": false diff --git a/hooks/useMarkdownit.ts b/hooks/useMarkdownit.ts new file mode 100644 index 0000000..ce2fe69 --- /dev/null +++ b/hooks/useMarkdownit.ts @@ -0,0 +1,10 @@ +export default async function useMarkdownit() { + const md = await import('markdown-it'); + const markdownit = md.default; + const mdit = markdownit({ + html: true, + linkify: true, + typographer: true + }); + return mdit; +} \ No newline at end of file diff --git a/nuxt.config.ts b/nuxt.config.ts index afa26b0..9f3e126 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -33,8 +33,12 @@ export default defineNuxtConfig({ modules: ["nuxtjs-naive-ui", "@pinia/nuxt"], compatibilityDate: "2025-01-12", build: { - // 开启打包分析 - analyze: true, + analyze: { + filename: "stats.html", + }, + }, + nitro: { + compressPublicAssets: true, }, experimental: { appManifest: false }, }); diff --git a/package.json b/package.json index 5b43bf6..0f27e66 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "dependencies": { "@pinia/nuxt": "^0.9.0", "@vicons/ionicons5": "^0.13.0", + "markdown-it": "^14.1.0", "naive-ui": "^2.41.0", "node-fetch": "^3.3.2", "nuxt": "^3.10.3", @@ -23,6 +24,7 @@ "vue-router": "^4.3.0" }, "devDependencies": { + "@types/markdown-it": "^14.1.2", "sass": "^1.83.1" } } diff --git a/pages/tool/genshin-gacha.vue b/pages/iframe/[url].vue similarity index 64% rename from pages/tool/genshin-gacha.vue rename to pages/iframe/[url].vue index 390c4ef..b830d30 100644 --- a/pages/tool/genshin-gacha.vue +++ b/pages/iframe/[url].vue @@ -1,11 +1,16 @@ \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 182710c..e285d51 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,6 +14,9 @@ importers: '@vicons/ionicons5': specifier: ^0.13.0 version: 0.13.0 + markdown-it: + specifier: ^14.1.0 + version: 14.1.0 naive-ui: specifier: ^2.41.0 version: 2.41.0(vue@3.5.13(typescript@5.7.3)) @@ -42,6 +45,9 @@ importers: specifier: ^4.3.0 version: 4.5.0(vue@3.5.13(typescript@5.7.3)) devDependencies: + '@types/markdown-it': + specifier: ^14.1.2 + version: 14.1.2 sass: specifier: ^1.83.1 version: 1.83.1 @@ -917,12 +923,21 @@ packages: '@types/katex@0.16.7': resolution: {integrity: sha512-HMwFiRujE5PjrgwHQ25+bsLJgowjGjm5Z8FVSf0N6PwgJrwxH0QxzHYDcKsTfV3wva0vzrpqMTJS2jXPr5BMEQ==} + '@types/linkify-it@5.0.0': + resolution: {integrity: sha512-sVDA58zAw4eWAffKOaQH5/5j3XeayukzDk+ewSsnv3p4yJEZHCCzMDiZM8e0OUrRvmpGZ85jf4yDHkHsgBNr9Q==} + '@types/lodash-es@4.17.12': resolution: {integrity: sha512-0NgftHUcV4v34VhXm8QBSftKVXtbkBG3ViCjs6+eJ5a6y6Mi/jiFGPc1sC7QK+9BFhWrURE3EOggmWaSxL9OzQ==} '@types/lodash@4.17.14': resolution: {integrity: sha512-jsxagdikDiDBeIRaPYtArcT8my4tN1og7MtMRquFT3XNA6axxyHDRUemqDz/taRDdOUn0GnGHRCuff4q48sW9A==} + '@types/markdown-it@14.1.2': + resolution: {integrity: sha512-promo4eFwuiW+TfGxhi+0x3czqTYJkG8qB17ZUJiVF10Xm7NLVRSLUsfRTU/6h1e24VvRnXCx+hG7li58lkzog==} + + '@types/mdurl@2.0.0': + resolution: {integrity: sha512-RGdgjQUZba5p6QEFAVx2OGb8rQDL/cPRG7GiedRzMcJ1tYnUANBncjbSB1NRGwbvjcPeikRABz2nshyPk1bhWg==} + '@types/node@22.10.5': resolution: {integrity: sha512-F8Q+SeGimwOo86fiovQh8qiXfFEh2/ocYv7tU5pJ3EXMSSxk1Joj5wefpFK2fHTf/N6HKGSxIDBT9f3gCxXPkQ==} @@ -1966,6 +1981,9 @@ packages: resolution: {integrity: sha512-/vlFKAoH5Cgt3Ie+JLhRbwOsCQePABiU3tJ1egGvyQ+33R/vcwM2Zl2QR/LzjsBeItPt3oSVXapn+m4nQDvpzw==} engines: {node: '>=14'} + linkify-it@5.0.0: + resolution: {integrity: sha512-5aHCbzQRADcdP+ATqnDuhhJ/MRIqDkZX5pyjFHRRysS8vZ5AbqGEoFIb6pYHPZ+L/OC2Lc+xT8uHVVR5CAK/wQ==} + listhen@1.9.0: resolution: {integrity: sha512-I8oW2+QL5KJo8zXNWX046M134WchxsXC7SawLPvRQpogCbkyQIaFxPE89A2HiwR7vAK2Dm2ERBAmyjTYGYEpBg==} hasBin: true @@ -2008,12 +2026,19 @@ packages: magicast@0.3.5: resolution: {integrity: sha512-L0WhttDl+2BOsybvEOLK7fW3UA0OQ0IQ2d6Zl2x/a6vVRs3bAY0ECOSHHeL5jD+SbOpOCUEi0y1DgHEn9Qn1AQ==} + markdown-it@14.1.0: + resolution: {integrity: sha512-a54IwgWPaeBCAAsv13YgmALOF1elABB08FxO9i+r4VFk5Vl4pKokRPeX8u5TCgSsPi6ec1otfLjdOpVcgbpshg==} + hasBin: true + mdn-data@2.0.28: resolution: {integrity: sha512-aylIc7Z9y4yzHYAJNuESG3hfhC+0Ibp/MAMiaOZgNv4pmEdFyfZhhhny4MNiAfWdBQ1RQ2mfDWmM1x8SvGyp8g==} mdn-data@2.0.30: resolution: {integrity: sha512-GaqWWShW4kv/G9IEucWScBx9G1/vsFZZJUO+tD26M8J8z3Kw5RDQjaoZe03YAClgeS/SWPOcb4nkFBTEi5DUEA==} + mdurl@2.0.0: + resolution: {integrity: sha512-Lf+9+2r+Tdp5wXDXC4PcIBjTDtq4UKjCPMQhKIuzpJNW0b96kVqSwW0bT7FhRSfmAiFYgP+SCRvdrDozfh0U5w==} + merge-stream@2.0.0: resolution: {integrity: sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==} @@ -2531,6 +2556,10 @@ packages: protocols@2.0.1: resolution: {integrity: sha512-/XJ368cyBJ7fzLMwLKv1e4vLxOju2MNAIokcr7meSaNcVbWz/CPcW22cP04mwxOErdA5mwjA8Q6w/cdAQxVn7Q==} + punycode.js@2.3.1: + resolution: {integrity: sha512-uxFIHU0YlHYhDQtV4R9J6a52SLx28BCjT+4ieh7IGbgwVJWO+km431c4yRlREUAsAmt/uMjQUyQHNEPf0M39CA==} + engines: {node: '>=6'} + queue-microtask@1.2.3: resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==} @@ -2867,6 +2896,9 @@ packages: engines: {node: '>=14.17'} hasBin: true + uc.micro@2.1.0: + resolution: {integrity: sha512-ARDJmphmdvUk6Glw7y9DQ2bFkKBHwQHLi2lsaH6PPmz/Ka9sFOBsBluozhDltWmnv9u/cF6Rt87znRTPV+yp/A==} + ufo@1.5.4: resolution: {integrity: sha512-UsUk3byDzKd04EyoZ7U4DOlxQaD14JUKQl6/P7wiX4FNvUfm3XL246n9W5AmqwW5RSFJ27NAuM0iLscAOYUiGQ==} @@ -4177,12 +4209,21 @@ snapshots: '@types/katex@0.16.7': {} + '@types/linkify-it@5.0.0': {} + '@types/lodash-es@4.17.12': dependencies: '@types/lodash': 4.17.14 '@types/lodash@4.17.14': {} + '@types/markdown-it@14.1.2': + dependencies: + '@types/linkify-it': 5.0.0 + '@types/mdurl': 2.0.0 + + '@types/mdurl@2.0.0': {} + '@types/node@22.10.5': dependencies: undici-types: 6.20.0 @@ -5296,6 +5337,10 @@ snapshots: lilconfig@3.1.3: {} + linkify-it@5.0.0: + dependencies: + uc.micro: 2.1.0 + listhen@1.9.0: dependencies: '@parcel/watcher': 2.5.0 @@ -5354,10 +5399,21 @@ snapshots: '@babel/types': 7.26.5 source-map-js: 1.2.1 + markdown-it@14.1.0: + dependencies: + argparse: 2.0.1 + entities: 4.5.0 + linkify-it: 5.0.0 + mdurl: 2.0.0 + punycode.js: 2.3.1 + uc.micro: 2.1.0 + mdn-data@2.0.28: {} mdn-data@2.0.30: {} + mdurl@2.0.0: {} + merge-stream@2.0.0: {} merge2@1.4.1: {} @@ -6041,6 +6097,8 @@ snapshots: protocols@2.0.1: {} + punycode.js@2.3.1: {} + queue-microtask@1.2.3: {} queue-tick@1.0.1: {} @@ -6398,6 +6456,8 @@ snapshots: typescript@5.7.3: {} + uc.micro@2.1.0: {} + ufo@1.5.4: {} ultrahtml@1.5.3: {} diff --git a/server/api/posts/getPostContent.ts b/server/api/posts/getPostContent.ts new file mode 100644 index 0000000..2ae00a5 --- /dev/null +++ b/server/api/posts/getPostContent.ts @@ -0,0 +1,38 @@ +const testData = `--- +tags: + - think +date: 2020-10-07 +--- + +# 为何是秦灭六国,统一天下 + +*刚刚与网友谈到这个话题。 +史书总是把王朝兴衰全归因于“人”,我更愿意相信其主因是“天”。 +所以,我更“青睐”把王朝更替与气候变化关联起来的相关学说。* + +**以下为爱好者臆测“为何是秦灭六国,一统天下”的原因(由于是爱好者,并不打算详细论证^_^)** + +### 天 +春秋战国时期大降温(看图)。 +![](./chronology.jpeg) +[来源链接](http://www.360doc.com/content/15/0616/06/17132703_478419907.shtml) +估计北方的诸侯收成都不好吧,没有找到战国时期天灾的相关资料。[期待这本书验证](https://baike.baidu.com/item/%E4%B8%89%E5%8D%83%E5%B9%B4%E5%A4%A9%E7%81%BE/12292062?fr=aladdin) + +### 地 +公元前316年秦灭巴蜀,得成都平原。 +约公元前256开建都江堰,使成都平原得"天府之国"美称,成为秦国粮仓。纬度偏南,地理优势。 +![](./map.jpeg) +那为啥不是楚灭六国呢? +猜测原因是:文明主要在北方形成(黄河流域),当时南方绝大部分是蛮荒之地,开发不够。 +后面两千年,每次大降温(游牧民族必然兴起),导致经济都往南迁移,直到宋朝,南方经济才超过北方,明朝才能成为首个逆袭北方统一中国的王朝。 + +### 人 +商鞅变法(公元前475~公元前221年),史料很多不多说了。 + +***公元前221年,秦灭六国***` + +export default defineEventHandler(async (event) => { + const body = await readBody(event) + const data = `# ${body.id}\n${testData}` + return { data } +}) \ No newline at end of file diff --git a/server/api/posts/getPosts.ts b/server/api/posts/getPostList.ts similarity index 100% rename from server/api/posts/getPosts.ts rename to server/api/posts/getPostList.ts diff --git a/tsconfig.json b/tsconfig.json index 388c1d5..a7be82f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,7 +8,7 @@ "server/**/*", "style/**/*", "utils/**/*", - ".nuxt/**/*", + ".nuxt/*.d.ts", "types/**/*" ] }