From 8fbae689d69c177cda9708e00c2eb8f30f9b5591 Mon Sep 17 00:00:00 2001 From: m1ngsama Date: Tue, 10 Jun 2025 09:23:30 +0800 Subject: [PATCH] add author url support in layout --- astro.config.mts | 37 +++++++++++---------- package.json | 2 ++ pnpm-lock.yaml | 57 +++++++++++++++++++++++++++++++++ src/layouts/MarkdownPost.astro | 8 ++++- src/pages/posts/minecraftMac.md | 2 +- 5 files changed, 87 insertions(+), 19 deletions(-) diff --git a/astro.config.mts b/astro.config.mts index 38a9ef1..5b23eda 100644 --- a/astro.config.mts +++ b/astro.config.mts @@ -1,23 +1,26 @@ -import { defineConfig } from "astro/config" -import { SITE_URL } from "./src/consts" -import vue from "@astrojs/vue" -import tailwind from "@astrojs/tailwind" -import react from "@astrojs/react" -import { handleLocalCoverPlugin } from "./src/plugins/cover" -import { themePipeline } from "./src/plugins/theme" +import { defineConfig } from "astro/config"; +import { SITE_URL } from "./src/consts"; +import vue from "@astrojs/vue"; +import tailwind from "@astrojs/tailwind"; +import react from "@astrojs/react"; +import { handleLocalCoverPlugin } from "./src/plugins/cover"; +import { themePipeline } from "./src/plugins/theme"; +import remarkToc from "remark-toc"; +import rehypeSlug from "rehype-slug"; // https://astro.build/config export default defineConfig({ site: SITE_URL, markdown: { - rehypePlugins: [handleLocalCoverPlugin, ...themePipeline], + remarkPlugins: [[remarkToc, { heading: "目录", tight: true }]], + rehypePlugins: [rehypeSlug, handleLocalCoverPlugin, ...themePipeline], syntaxHighlight: "shiki", shikiConfig: { themes: { - light: 'github-light', - dark: 'github-dark', + light: "github-light", + dark: "github-dark", }, - } + }, }, integrations: [ vue(), @@ -33,13 +36,13 @@ export default defineConfig({ "/active": { target: "https://active.nbtca.space", changeOrigin: true, - rewrite: path => path.replace(/^\/active/, ""), + rewrite: (path) => path.replace(/^\/active/, ""), }, "/saturday": { target: "http://localhost:4000", - rewrite: path => path.replace(/^\/saturday/, ""), + rewrite: (path) => path.replace(/^\/saturday/, ""), }, - } - } - } -}) + }, + }, + }, +}); diff --git a/package.json b/package.json index 3a9f32e..564798c 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,8 @@ "react": "^18.3.1", "react-dom": "^18.3.1", "rehype": "^13.0.2", + "rehype-slug": "^6.0.0", + "remark-toc": "^9.0.0", "sharp": "^0.33.5", "tailwindcss": "^3.4.17", "unist-util-visit": "^5.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0197441..165c5f1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -80,6 +80,12 @@ importers: rehype: specifier: ^13.0.2 version: 13.0.2 + rehype-slug: + specifier: ^6.0.0 + version: 6.0.0 + remark-toc: + specifier: ^9.0.0 + version: 9.0.0 sharp: specifier: ^0.33.5 version: 0.33.5 @@ -2462,6 +2468,9 @@ packages: '@types/react@18.3.23': resolution: {integrity: sha512-/LDXMQh55EzZQ0uVAZmKKhfENivEvWz6E+EYzh+/MCjMhNsotd+ZHhBGIjFDTi6+fz0OhQQQLbTgdQIxxCsC0w==} + '@types/ungap__structured-clone@1.2.0': + resolution: {integrity: sha512-ZoaihZNLeZSxESbk9PUAPZOlSpcKx81I1+4emtULDVmBLkYutTcMlCj2K9VNlf9EWODxdO6gkAqEaLorXwZQVA==} + '@types/unist@3.0.3': resolution: {integrity: sha512-ko/gIFJRv177XgZsZcBwnqJN5x/Gien8qNOn0D5bQU/zAzVf9Zt3BlcUiLqhV9y4ARk0GbT3tnUiPNgnTXzc/Q==} @@ -3752,6 +3761,9 @@ packages: hast-util-from-parse5@8.0.3: resolution: {integrity: sha512-3kxEVkEKt0zvcZ3hCRYI8rqrgwtlIOFMWkbclACvjlDw8Li9S2hk/d51OI0nr/gIpdMHNepwgOKqZ/sy0Clpyg==} + hast-util-heading-rank@3.0.0: + resolution: {integrity: sha512-EJKb8oMUXVHcWZTDepnr+WNbfnXKFNf9duMesmr4S8SXTJBJ9M4Yok08pu9vxdJwdlGRhVumk9mEhkEvKGifwA==} + hast-util-is-element@3.0.0: resolution: {integrity: sha512-Val9mnv2IWpLbNPqc/pUem+a7Ipj2aHacCwgNfTiK0vJKl0LF+4Ba4+v1oPHFpf3bLYmreq0/l3Gud9S5OH42g==} @@ -3767,6 +3779,9 @@ packages: hast-util-to-parse5@8.0.0: resolution: {integrity: sha512-3KKrV5ZVI8if87DVSi1vDeByYrkGzg4mEfeu4alwgmmIeARiBLKCZS2uw5Gb6nU9x9Yufyj3iudm6i7nl52PFw==} + hast-util-to-string@3.0.1: + resolution: {integrity: sha512-XelQVTDWvqcl3axRfI0xSeoVKzyIFPwsAGSLIsKdJKQMXDYJS4WYrBNF/8J7RdhIcFI2BOHgAifggsvsxp/3+A==} + hast-util-to-text@4.0.2: resolution: {integrity: sha512-KK6y/BN8lbaq654j7JgBydev7wuNMcID54lkRav1P0CaE1e47P72AWWPiGKXTJU271ooYzcvTAn/Zt0REnvc7A==} @@ -4222,6 +4237,9 @@ packages: mdast-util-to-string@4.0.0: resolution: {integrity: sha512-0H44vDimn51F0YwvxSJSm0eCDOJTRlmN0R1yBh4HLj9wiV1Dn0QoXGbvFAWj2hSItVTlCmBF1hqKlIyUBVFLPg==} + mdast-util-toc@7.1.0: + resolution: {integrity: sha512-2TVKotOQzqdY7THOdn2gGzS9d1Sdd66bvxUyw3aNpWfcPXCLYSJCCgfPy30sEtuzkDraJgqF35dzgmz6xlvH/w==} + merge-stream@2.0.0: resolution: {integrity: sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==} @@ -4799,6 +4817,9 @@ packages: rehype-raw@7.0.0: resolution: {integrity: sha512-/aE8hCfKlQeA8LmyeyQvQF3eBiLRGNlfBJEvWH7ivp9sBqs7TNqBL5X3v157rM4IFETqDnIOO+z5M/biZbo9Ww==} + rehype-slug@6.0.0: + resolution: {integrity: sha512-lWyvf/jwu+oS5+hL5eClVd3hNdmwM1kAC0BUvEGD19pajQMIzcNUd/k9GsfQ+FfECvX+JE+e9/btsKH0EjJT6A==} + rehype-stringify@10.0.1: resolution: {integrity: sha512-k9ecfXHmIPuFVI61B9DeLPN0qFHfawM6RsuX48hoqlaKSF61RskNjSm1lI8PhBEM0MRdLxVVm4WmTqJQccH9mA==} @@ -4821,6 +4842,9 @@ packages: remark-stringify@11.0.0: resolution: {integrity: sha512-1OSmLd3awB/t8qdoEOMazZkNsfVTeY4fTsgzcQFdXNq8ToTN4ZGwrMnlda4K6smTFKD+GRV6O48i6Z4iKgPPpw==} + remark-toc@9.0.0: + resolution: {integrity: sha512-KJ9txbo33GjDAV1baHFze7ij4G8c7SGYoY8Kzsm2gzFpbhL/bSoVpMMzGa3vrNDSWASNd/3ppAqL7cP2zD6JIA==} + repeat-string@1.6.1: resolution: {integrity: sha512-PV0dzCYDNfRi1jCDbJzpW7jNNDRuCOG/jI5ctQcGKt/clZD+YcPS3yIlWuTJMmESC8aevCFmWJy5wjAFgNqN6w==} engines: {node: '>=0.10'} @@ -8875,6 +8899,8 @@ snapshots: '@types/prop-types': 15.7.14 csstype: 3.1.3 + '@types/ungap__structured-clone@1.2.0': {} + '@types/unist@3.0.3': {} '@types/uuid@10.0.0': {} @@ -10475,6 +10501,10 @@ snapshots: vfile-location: 5.0.3 web-namespaces: 2.0.1 + hast-util-heading-rank@3.0.0: + dependencies: + '@types/hast': 3.0.4 + hast-util-is-element@3.0.0: dependencies: '@types/hast': 3.0.4 @@ -10523,6 +10553,10 @@ snapshots: web-namespaces: 2.0.1 zwitch: 2.0.4 + hast-util-to-string@3.0.1: + dependencies: + '@types/hast': 3.0.4 + hast-util-to-text@4.0.2: dependencies: '@types/hast': 3.0.4 @@ -11040,6 +11074,16 @@ snapshots: dependencies: '@types/mdast': 4.0.4 + mdast-util-toc@7.1.0: + dependencies: + '@types/mdast': 4.0.4 + '@types/ungap__structured-clone': 1.2.0 + '@ungap/structured-clone': 1.3.0 + github-slugger: 2.0.0 + mdast-util-to-string: 4.0.0 + unist-util-is: 6.0.0 + unist-util-visit: 5.0.0 + merge-stream@2.0.0: {} merge2@1.4.1: {} @@ -11718,6 +11762,14 @@ snapshots: hast-util-raw: 9.1.0 vfile: 6.0.3 + rehype-slug@6.0.0: + dependencies: + '@types/hast': 3.0.4 + github-slugger: 2.0.0 + hast-util-heading-rank: 3.0.0 + hast-util-to-string: 3.0.1 + unist-util-visit: 5.0.0 + rehype-stringify@10.0.1: dependencies: '@types/hast': 3.0.4 @@ -11772,6 +11824,11 @@ snapshots: mdast-util-to-markdown: 2.1.2 unified: 11.0.5 + remark-toc@9.0.0: + dependencies: + '@types/mdast': 4.0.4 + mdast-util-toc: 7.1.0 + repeat-string@1.6.1: {} require-directory@2.1.1: {} diff --git a/src/layouts/MarkdownPost.astro b/src/layouts/MarkdownPost.astro index 581a364..2b2ef9b 100644 --- a/src/layouts/MarkdownPost.astro +++ b/src/layouts/MarkdownPost.astro @@ -88,7 +88,13 @@ const dateFormatted = formatDate(pubDate)

- 作者: {frontmatter.author} 发表日期:{dateFormatted} + 作者: + { + typeof frontmatter.author === "object" + ? {frontmatter.author.name} + : frontmatter.author + } + ,发表日期:{dateFormatted}

diff --git a/src/pages/posts/minecraftMac.md b/src/pages/posts/minecraftMac.md index cac7148..901e3da 100644 --- a/src/pages/posts/minecraftMac.md +++ b/src/pages/posts/minecraftMac.md @@ -5,7 +5,7 @@ pubDate: 2025-06-10 description: "🤪" author: name: "小明" - link: "https://m1ng.space/" + url: "https://m1ng.space/" cover: url: "https://i.pinimg.com/736x/6f/00/d7/6f00d73e426549d0f5b1bb873bf2015f.jpg" alt: "cover"