├── .editorconfig ├── .example.env ├── .gitignore ├── .npmrc ├── .prettierignore ├── .prettierrc.js ├── .vscode ├── extensions.json ├── post.code-snippets └── settings.json ├── LICENSE ├── README.md ├── astro.config.ts ├── biome.json ├── package.json ├── pnpm-lock.yaml ├── postcss.config.cjs ├── public ├── admin │ └── config.yml ├── icon.svg ├── icons │ ├── bilibili.svg │ ├── linux.do.svg │ └── nodeseek.svg └── social-card.avif ├── src ├── assets │ ├── roboto-mono-700.ttf │ └── roboto-mono-regular.ttf ├── components │ ├── BaseHead.astro │ ├── FormattedDate.astro │ ├── Paginator.astro │ ├── Search.astro │ ├── SkipLink.astro │ ├── SocialList.astro │ ├── ThemeProvider.astro │ ├── ThemeToggle.astro │ ├── blog │ │ ├── Masthead.astro │ │ ├── PostPreview.astro │ │ ├── TOC.astro │ │ ├── TOCHeading.astro │ │ └── webmentions │ │ │ ├── Comments.astro │ │ │ ├── Likes.astro │ │ │ └── index.astro │ ├── layout │ │ ├── Footer.astro │ │ └── Header.astro │ └── note │ │ └── Note.astro ├── content.config.ts ├── content │ ├── note │ │ └── demo.md │ └── post │ │ └── demo │ │ ├── cover-image │ │ ├── cover.png │ │ └── index.md │ │ ├── draft-post.md │ │ ├── markdown-elements │ │ ├── admonistions.md │ │ ├── index.md │ │ └── logo.png │ │ └── social-image │ │ ├── 1215191008.avif │ │ └── index.md ├── data │ └── post.ts ├── env.d.ts ├── layouts │ ├── Base.astro │ └── BlogPost.astro ├── pages │ ├── 404.astro │ ├── about.astro │ ├── index.astro │ ├── notes │ │ ├── [...page].astro │ │ ├── [...slug].astro │ │ └── rss.xml.ts │ ├── og-image │ │ └── [...slug].png.ts │ ├── posts │ │ ├── [...page].astro │ │ └── [...slug].astro │ ├── rss.xml.ts │ └── tags │ │ ├── [tag] │ │ └── [...page].astro │ │ └── index.astro ├── plugins │ ├── remark-admonitions.ts │ └── remark-reading-time.ts ├── site.config.ts ├── styles │ └── global.css ├── types.ts └── utils │ ├── date.ts │ ├── domElement.ts │ ├── generateToc.ts │ └── webmentions.ts ├── tailwind.config.ts └── tsconfig.json /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | indent_style = space 6 | indent_size = 2 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true -------------------------------------------------------------------------------- /.example.env: -------------------------------------------------------------------------------- 1 | WEBMENTION_API_KEY= 2 | WEBMENTION_URL= 3 | WEBMENTION_PINGBACK=#optional -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # build output 2 | dist/ 3 | .output/ 4 | 5 | # dependencies 6 | node_modules/ 7 | 8 | # logs 9 | npm-debug.log* 10 | yarn-debug.log* 11 | yarn-error.log* 12 | pnpm-debug.log* 13 | 14 | 15 | # environment variables 16 | .env 17 | .env.production 18 | 19 | # macOS-specific files 20 | .DS_Store 21 | 22 | # misc 23 | *.pem 24 | .cache 25 | .astro -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | enable-pre-post-scripts=true -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | *.min.js 2 | node_modules 3 | 4 | # cache-dirs 5 | **/.cache 6 | 7 | pnpm-lock.yaml 8 | dist -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | /** @type {import("@types/prettier").Options} */ 2 | module.exports = { 3 | printWidth: 100, 4 | semi: true, 5 | singleQuote: false, 6 | tabWidth: 2, 7 | useTabs: true, 8 | plugins: ["prettier-plugin-astro", "prettier-plugin-tailwindcss" /* Must come last */], 9 | overrides: [ 10 | { 11 | files: "**/*.astro", 12 | options: { 13 | parser: "astro", 14 | }, 15 | }, 16 | { 17 | files: ["*.mdx", "*.md"], 18 | options: { 19 | printWidth: 80, 20 | }, 21 | }, 22 | ], 23 | }; 24 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": ["astro-build.astro-vscode"], 3 | "unwantedRecommendations": [] 4 | } 5 | -------------------------------------------------------------------------------- /.vscode/post.code-snippets: -------------------------------------------------------------------------------- 1 | { 2 | // Place your astro-cactus workspace snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and 3 | // description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope 4 | // is left empty or omitted, the snippet gets applied to all languages. The prefix is what is 5 | // used to trigger the snippet and the body will be expanded and inserted. Possible variables are: 6 | // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. 7 | // Placeholders with the same ids are connected. 8 | // Example: 9 | // "Print to console": { 10 | // "scope": "javascript,typescript", 11 | // "prefix": "log", 12 | // "body": [ 13 | // "console.log('$1');", 14 | // "$2" 15 | // ], 16 | // "description": "Log output to console" 17 | // } 18 | "Add frontmatter to an Astro Cactus Post": { 19 | "scope": "markdown,mdx", 20 | "prefix": "frontmatter-post", 21 | "body": [ 22 | "---", 23 | "title: ${TM_FILENAME_BASE/(.*)/${1:/capitalize}/}", 24 | "description: 'Please enter a description of your post here, between 50-160 chars!'", 25 | "publishDate: $CURRENT_DATE $CURRENT_MONTH_NAME $CURRENT_YEAR", 26 | "tags: []", 27 | "draft: false", 28 | "---", 29 | "$2", 30 | ], 31 | "description": "Add frontmatter for new Markdown post", 32 | }, 33 | "Add frontmatter to an Astro Cactus Note": { 34 | "scope": "markdown,mdx", 35 | "prefix": "frontmatter-note", 36 | "body": [ 37 | "---", 38 | "title: ${TM_FILENAME_BASE/(.*)/${1:/capitalize}/}", 39 | "description: 'Enter a description here (optional)'", 40 | "publishDate: \"${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}T${CURRENT_HOUR}:${CURRENT_MINUTE}:00Z\"", 41 | "---", 42 | "$2", 43 | ], 44 | "description": "Add frontmatter for a new Markdown note", 45 | }, 46 | } 47 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "[javascript]": { "editor.defaultFormatter": "biomejs.biome" }, 3 | "[typescript]": { "editor.defaultFormatter": "biomejs.biome" }, 4 | "[javascriptreact]": { "editor.defaultFormatter": "biomejs.biome" }, 5 | "[typescriptreact]": { "editor.defaultFormatter": "biomejs.biome" }, 6 | "[json]": { "editor.defaultFormatter": "biomejs.biome" }, 7 | "[jsonc]": { "editor.defaultFormatter": "biomejs.biome" }, 8 | "editor.formatOnSave": true, 9 | "prettier.documentSelectors": ["**/*.astro"], 10 | "editor.codeActionsOnSave": { 11 | "source.organizeImports": "never", 12 | "source.organizeImports.biome": "explicit", 13 | "quickfix.biome": "explicit" 14 | }, 15 | "[markdown]": { 16 | "editor.wordWrap": "on" 17 | }, 18 | "typescript.tsdk": "node_modules/typescript/lib", 19 | "astro.content-intellisense": true 20 | } 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Chris Williams 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | Astro Cactus logo 3 |
4 |

5 | Astro 仙人掌 6 |

7 | 8 | Astro 仙人掌 是一个基于 Astro 框架的博客主题,使用 Astro 和 TailwindCSS。是 Astro Cactus 主题项目的中文汉化版。同时集成 **decap cms**,实现在线编辑、发布。 9 | 10 | 原主题地址: https://github.com/chrismwilliams/astro-theme-cactus 11 | 12 | ## 演示站点 💻 13 | 14 | 点击预览 [Demo](https://demo.343700.xyz/) 15 | 16 | ## 快速开始 🚀 17 | 18 | ### A、网页编辑模式 19 | 20 | 教学视频:[【零基础】【零成本】搭建一个属于自己的Astro博客网站](https://www.bilibili.com/video/BV18eCpYcEAk) 21 | 22 | 1. 点击 Fork 按钮,复制本项目到你的GitHub 仓库 23 | 2. [Vercel](vercel.com) 注册登录,关联 GitHub 账户,导入仓库 24 | 3. 添加一个[GitHub认证](https://github.com/settings/applications/new),得到 Oauth ID 和 secret 25 | - Homepage URL —— https://你的域名 26 | - Authorization callback URL —— https://域名/oauth/callback 27 | 4. 在 Vercel -> Settings -> Environment Variables,添加2个环境变量 28 | - OAUTH_GITHUB_CLIENT_ID -> Oauth ID 29 | - OAUTH_GITHUB_CLIENT_SECRET -> Oauth secret 30 | 5. 修改GitHub仓库 `public/admin/config.yml`,修改 `repo`、`site_domain`、`base_url` 31 | 6. 通过访问 `你的域名/admin` 访问博客后台,进行编辑、发布文章 32 | 33 | 34 | 35 | ### B、本地编辑模式 36 | 37 | 先完成【A、网页编辑模式】中的步骤,然后执行下面的步骤 38 | 39 | 1. 点击 Fork 按钮,复制本项目到你的GitHub 仓库,然后点击 Code 按钮,复制项目地址。 40 | 2. 本地电脑上执行下面代码,安装项目 41 | ```bash 42 | git clone https://github.com/your-username/astro-theme-cactus-zh-cn.git 43 | 44 | cd astro-theme-cactus-zh-cn 45 | 46 | pnpm install 47 | ``` 48 | 3. 在 `src/content` 文件夹中,新建 markdown 文件,例如 `src/content/posts/hello-world.md` 49 | 4. 保存md文件,执行 git push 推送到远程仓库 50 | 51 | #### 命令 52 | 53 | | 命令 | 操作 | 54 | | :--------------- | :------------------------------------------------------------- | 55 | | `pnpm install` | 安装依赖项 | 56 | | `pnpm dev` | 在 `localhost:3000` 启动本地开发服务器 | 57 | | `pnpm build` | 将生产站点构建到 `./dist/` 目录下 | 58 | | `pnpm postbuild` | 执行 Pagefind 脚本,为博客文章构建静态搜索功能 | 59 | | `pnpm preview` | 在部署前本地预览构建结果 | 60 | | `pnpm sync` | 根据 `src/content/config.ts` 中的配置生成类型 | 61 | 62 | ## 个性化配置 ⚙ 63 | 64 | - 修改导航栏标题,图片 -> `src/components/layout/Header.astro` 65 | - 修改网站配置 -> `src/site.config.ts` 66 | - 修改框架配置 -> `astro.config.ts` 67 | - 修改社交图标链接 -> `src/components/SocialList.astro` 68 | 69 | 70 | ## License 71 | 72 | MIT 73 | -------------------------------------------------------------------------------- /astro.config.ts: -------------------------------------------------------------------------------- 1 | import fs from "node:fs"; 2 | import mdx from "@astrojs/mdx"; 3 | import sitemap from "@astrojs/sitemap"; 4 | import tailwind from "@astrojs/tailwind"; 5 | import expressiveCode from "astro-expressive-code"; 6 | import icon from "astro-icon"; 7 | import robotsTxt from "astro-robots-txt"; 8 | import webmanifest from "astro-webmanifest"; 9 | import { defineConfig, envField } from "astro/config"; 10 | import { expressiveCodeOptions } from "./src/site.config"; 11 | import { siteConfig } from "./src/site.config"; 12 | import vercel from "@astrojs/vercel"; 13 | 14 | // Remark plugins 15 | import remarkDirective from "remark-directive"; // Handle ::: directives as nodes 16 | import { remarkAdmonitions } from "./src/plugins/remark-admonitions"; // Add admonitions 17 | import { remarkReadingTime } from "./src/plugins/remark-reading-time"; 18 | import remarkMath from "remark-math"; // Add LaTeX support 19 | import remarkGemoji from "remark-gemoji"; // Add emoji support 20 | 21 | // Rehype plugins 22 | import rehypeExternalLinks from "rehype-external-links"; 23 | import rehypeUnwrapImages from "rehype-unwrap-images"; 24 | import rehypeKatex from "rehype-katex"; // Render LaTeX with KaTeX 25 | 26 | 27 | import decapCmsOauth from "astro-decap-cms-oauth"; 28 | 29 | // https://astro.build/config 30 | export default defineConfig({ 31 | output: 'server', 32 | adapter: vercel(), 33 | image: { 34 | domains: ["webmention.io"], 35 | }, 36 | integrations: [expressiveCode(expressiveCodeOptions), icon({ 37 | iconDir: "public/icons", // 修改:指定自定义图标目录 name = svg文件名 38 | }), tailwind({ 39 | applyBaseStyles: false, 40 | nesting: true, 41 | }), sitemap(), mdx(), robotsTxt(), webmanifest({ 42 | // See: https://github.com/alextim/astro-lib/blob/main/packages/astro-webmanifest/README.md 43 | /** 44 | * required 45 | **/ 46 | name: siteConfig.title, 47 | /** 48 | * optional 49 | **/ 50 | short_name: "仙人掌主题", 51 | description: siteConfig.description, 52 | lang: siteConfig.lang, 53 | icon: "public/icon.svg", // the source for generating favicon & icons 54 | icons: [ 55 | { 56 | src: "icons/apple-touch-icon.png", // used in src/components/BaseHead.astro L:26 57 | sizes: "180x180", 58 | type: "image/png", 59 | }, 60 | { 61 | src: "icons/icon-192.png", 62 | sizes: "192x192", 63 | type: "image/png", 64 | }, 65 | { 66 | src: "icons/icon-512.png", 67 | sizes: "512x512", 68 | type: "image/png", 69 | }, 70 | ], 71 | start_url: "/", 72 | background_color: "#1d1f21", 73 | theme_color: "#2bbc8a", 74 | display: "standalone", 75 | config: { 76 | insertFaviconLinks: false, 77 | insertThemeColorMeta: false, 78 | insertManifestLink: false, 79 | }, 80 | }), decapCmsOauth()], 81 | markdown: { 82 | rehypePlugins: [ 83 | [ 84 | rehypeExternalLinks, 85 | { 86 | rel: ["nofollow, noreferrer"], 87 | target: "_blank", 88 | }, 89 | ], 90 | rehypeUnwrapImages, 91 | rehypeKatex, // 添加 KaTeX 用于 LaTeX 渲染 92 | ], 93 | remarkPlugins: [ 94 | remarkReadingTime, 95 | remarkDirective, 96 | remarkAdmonitions, 97 | remarkMath, // 添加 LaTeX 功能 98 | remarkGemoji, // 添加 emoji 功能 99 | ], 100 | remarkRehype: { 101 | footnoteLabelProperties: { 102 | className: [""], 103 | }, 104 | footnoteLabel: '脚注:', 105 | }, 106 | }, 107 | // https://docs.astro.build/en/guides/prefetch/ 108 | prefetch: { 109 | defaultStrategy: 'viewport', 110 | prefetchAll: true, 111 | }, 112 | // ! 改为你的网站地址,不然社交图片无法加载 113 | site: "https://demo.343700.xyz/", 114 | vite: { 115 | optimizeDeps: { 116 | exclude: ["@resvg/resvg-js"], 117 | }, 118 | plugins: [rawFonts([".ttf", ".woff"])], 119 | }, 120 | env: { 121 | schema: { 122 | WEBMENTION_API_KEY: envField.string({ context: "server", access: "secret", optional: true }), 123 | WEBMENTION_URL: envField.string({ context: "client", access: "public", optional: true }), 124 | WEBMENTION_PINGBACK: envField.string({ context: "client", access: "public", optional: true }), 125 | }, 126 | }, 127 | }); 128 | 129 | function rawFonts(ext: string[]) { 130 | return { 131 | name: "vite-plugin-raw-fonts", 132 | // @ts-expect-error:next-line 133 | transform(_, id) { 134 | if (ext.some((e) => id.endsWith(e))) { 135 | const buffer = fs.readFileSync(id); 136 | return { 137 | code: `export default ${JSON.stringify(buffer)}`, 138 | map: null, 139 | }; 140 | } 141 | }, 142 | }; 143 | } 144 | -------------------------------------------------------------------------------- /biome.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@biomejs/biome/configuration_schema.json", 3 | "formatter": { 4 | "indentStyle": "tab", 5 | "indentWidth": 2, 6 | "lineWidth": 100, 7 | "formatWithErrors": true, 8 | "ignore": ["*.astro"] 9 | }, 10 | "organizeImports": { 11 | "enabled": true 12 | }, 13 | "linter": { 14 | "enabled": true, 15 | "rules": { 16 | "recommended": true, 17 | "a11y": { 18 | "noSvgWithoutTitle": "off" 19 | }, 20 | "suspicious": { 21 | "noExplicitAny": "warn" 22 | } 23 | } 24 | }, 25 | "javascript": { 26 | "formatter": { 27 | "trailingCommas": "all", 28 | "semicolons": "always" 29 | } 30 | }, 31 | "vcs": { 32 | "clientKind": "git", 33 | "enabled": true, 34 | "useIgnoreFile": true 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "", 3 | "version": "5.0.0", 4 | "scripts": { 5 | "dev": "astro dev", 6 | "start": "astro dev", 7 | "build": "astro build", 8 | "postbuild": "pagefind --site dist/client --output-path .vercel/output/static/pagefind", 9 | "preview": "astro preview", 10 | "lint": "biome lint .", 11 | "format": "pnpm run format:code && pnpm run format:imports", 12 | "format:code": "biome format . --write && prettier -w \"**/*\" \"!**/*.{md,mdx}\" --ignore-unknown --cache", 13 | "format:imports": "biome check --formatter-enabled=false --write", 14 | "check": "astro check" 15 | }, 16 | "dependencies": { 17 | "@astrojs/mdx": "4.0.1", 18 | "@astrojs/rss": "4.0.10", 19 | "@astrojs/sitemap": "3.2.1", 20 | "@astrojs/tailwind": "5.1.3", 21 | "@astrojs/vercel": "^8.0.1", 22 | "astro": "5.0.3", 23 | "astro-decap-cms-oauth": "^0.5.1", 24 | "astro-expressive-code": "^0.38.3", 25 | "astro-icon": "^1.1.4", 26 | "astro-robots-txt": "^1.0.0", 27 | "astro-webmanifest": "^1.0.0", 28 | "cssnano": "^7.0.6", 29 | "hastscript": "^9.0.0", 30 | "mdast-util-directive": "^3.0.0", 31 | "mdast-util-to-markdown": "^2.1.2", 32 | "mdast-util-to-string": "^4.0.0", 33 | "rehype-external-links": "^3.0.0", 34 | "rehype-unwrap-images": "^1.0.0", 35 | "remark-directive": "^3.0.0", 36 | "satori": "0.12.0", 37 | "satori-html": "^0.3.2", 38 | "sharp": "^0.33.5", 39 | "unified": "^11.0.5", 40 | "unist-util-visit": "^5.0.0", 41 | "rehype-katex": "^7.0.1", 42 | "remark-gemoji": "^8.0.0", 43 | "remark-math": "^6.0.0" 44 | }, 45 | "devDependencies": { 46 | "@astrojs/check": "^0.9.4", 47 | "@biomejs/biome": "^1.9.4", 48 | "@iconify-json/mdi": "^1.2.1", 49 | "@pagefind/default-ui": "^1.2.0", 50 | "@resvg/resvg-js": "^2.6.2", 51 | "@tailwindcss/typography": "^0.5.15", 52 | "@types/hast": "^3.0.4", 53 | "@types/mdast": "^4.0.4", 54 | "autoprefixer": "^10.4.20", 55 | "pagefind": "^1.2.0", 56 | "prettier": "^3.4.2", 57 | "prettier-plugin-astro": "0.14.1", 58 | "prettier-plugin-tailwindcss": "^0.6.9", 59 | "reading-time": "^1.5.0", 60 | "tailwindcss": "^3.4.16", 61 | "typescript": "^5.7.2" 62 | }, 63 | "packageManager": "pnpm@9.15.0+sha512.76e2379760a4328ec4415815bcd6628dee727af3779aaa4c914e3944156c4299921a89f976381ee107d41f12cfa4b66681ca9c718f0668fa0831ed4c6d8ba56c" 64 | } 65 | -------------------------------------------------------------------------------- /postcss.config.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: [ 3 | require("autoprefixer"), 4 | ...(process.env.NODE_ENV === "production" ? [require("cssnano")] : []), 5 | ], 6 | }; 7 | -------------------------------------------------------------------------------- /public/admin/config.yml: -------------------------------------------------------------------------------- 1 | backend: 2 | name: github 3 | branch: main # change this to your branch 4 | repo: example/cactus # 1、change this to your repo 5 | site_domain: example.com # 2、change this to your domain 6 | base_url: https://example.com # 3、change this to your prod URL 7 | auth_endpoint: oauth # the oauth route provided by the integration 8 | 9 | collections: 10 | - name: "note" 11 | label: "笔记" 12 | folder: "src/content/note" 13 | create: true 14 | slug: "{{year}}.{{month}}.{{day}}_{{slug}}" 15 | fields: 16 | - { label: "标题", name: "title", widget: "string", required: true } 17 | - { 18 | label: "简介", 19 | name: "description", 20 | widget: "string", 21 | default: "这是一篇有意思的文章", 22 | required: true, 23 | } 24 | - { 25 | label: "发布日期", 26 | name: "publishDate", 27 | widget: "datetime", 28 | date_format: "YYYY-MM-DD", 29 | time_format: "HH:mm", 30 | required: true, 31 | } 32 | - { label: "正文", name: "body", widget: "markdown" } 33 | 34 | - name: "post" 35 | label: "博文" 36 | folder: "src/content/post" 37 | create: true 38 | slug: "{{year}}.{{month}}.{{day}}_{{slug}}" 39 | fields: 40 | - { label: "标题", name: "title", widget: "string", required: true } 41 | - { 42 | label: "简介", 43 | name: "description", 44 | widget: "string", 45 | default: "这是一篇有意思的文章", 46 | required: true, 47 | } 48 | - { 49 | label: "发布日期", 50 | name: "publishDate", 51 | widget: "datetime", 52 | date_format: "YYYY-MM-DD", 53 | required: true, 54 | } 55 | - { label: "标签", name: "tags", widget: "list", required: true } 56 | - { 57 | label: "ogImage", 58 | name: "ogImage", 59 | widget: "string", 60 | default: "/social-card.avif", 61 | required: true, 62 | } 63 | - { label: "正文", name: "body", widget: "markdown" } 64 | 65 | media_folder: "public/assets/images" # 文件将被存储在仓库中的位置 66 | public_folder: "/assets/images" # 上传媒体文件的 src 属性 67 | 68 | -------------------------------------------------------------------------------- /public/icon.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/icons/bilibili.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /public/icons/linux.do.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/icons/nodeseek.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /public/social-card.avif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zouzonghao/Astro-theme-Cactus-zh_CN/b25a7399c3fadca5b176dd8e6afca6d805c866ce/public/social-card.avif -------------------------------------------------------------------------------- /src/assets/roboto-mono-700.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zouzonghao/Astro-theme-Cactus-zh_CN/b25a7399c3fadca5b176dd8e6afca6d805c866ce/src/assets/roboto-mono-700.ttf -------------------------------------------------------------------------------- /src/assets/roboto-mono-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zouzonghao/Astro-theme-Cactus-zh_CN/b25a7399c3fadca5b176dd8e6afca6d805c866ce/src/assets/roboto-mono-regular.ttf -------------------------------------------------------------------------------- /src/components/BaseHead.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import { WEBMENTION_PINGBACK, WEBMENTION_URL } from "astro:env/client"; 3 | import { siteConfig } from "@/site.config"; 4 | import type { SiteMeta } from "@/types"; 5 | import "@/styles/global.css"; 6 | 7 | type Props = SiteMeta; 8 | 9 | const { articleDate, description, ogImage, title } = Astro.props; 10 | 11 | const titleSeparator = "•"; 12 | const siteTitle = `${title} ${titleSeparator} ${siteConfig.title}`; 13 | const canonicalURL = new URL(Astro.url.pathname, Astro.site); 14 | const socialImageURL = new URL(ogImage ? ogImage : "/social-card.avif", Astro.url).href; 15 | --- 16 | 17 | 18 | 19 | {siteTitle} 20 | 21 | {/* Icons */} 22 | 23 | { 24 | import.meta.env.PROD && ( 25 | <> 26 | {/* Favicon & Apple Icon */} 27 | 28 | 29 | {/* Manifest */} 30 | 31 | 32 | ) 33 | } 34 | 35 | {/* Canonical URL */} 36 | 37 | 38 | {/* Primary Meta Tags */} 39 | 40 | 41 | 42 | 43 | {/* Theme Colour */} 44 | 45 | 46 | {/* Open Graph / Facebook */} 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | { 57 | articleDate && ( 58 | <> 59 | 60 | 61 | 62 | ) 63 | } 64 | 65 | {/* Twitter */} 66 | 67 | 68 | 69 | 70 | 71 | 72 | {/* Sitemap */} 73 | 74 | 75 | {/* RSS auto-discovery */} 76 | 77 | 78 | {/* Webmentions */} 79 | { 80 | WEBMENTION_URL && ( 81 | <> 82 | 83 | {WEBMENTION_PINGBACK && } 84 | 85 | ) 86 | } 87 | 88 | 89 | -------------------------------------------------------------------------------- /src/components/FormattedDate.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import { getFormattedDate } from "@/utils/date"; 3 | import type { HTMLAttributes } from "astro/types"; 4 | 5 | type Props = HTMLAttributes<"time"> & { 6 | date: Date; 7 | dateTimeOptions?: Intl.DateTimeFormatOptions; 8 | }; 9 | 10 | const { date, dateTimeOptions, ...attrs } = Astro.props; 11 | 12 | const postDate = getFormattedDate(date, dateTimeOptions); 13 | const ISO = date.toISOString(); 14 | --- 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/components/Paginator.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import type { PaginationLink } from "@/types"; 3 | 4 | interface Props { 5 | nextUrl?: PaginationLink; 6 | prevUrl?: PaginationLink; 7 | } 8 | 9 | const { nextUrl, prevUrl } = Astro.props; 10 | --- 11 | 12 | { 13 | (prevUrl || nextUrl) && ( 14 | // 修改:翻页 15 | 37 | ) 38 | } 39 | -------------------------------------------------------------------------------- /src/components/Search.astro: -------------------------------------------------------------------------------- 1 | --- 2 | // Heavy inspiration taken from Astro Starlight -> https://github.com/withastro/starlight/blob/main/packages/starlight/components/Search.astro 3 | 4 | import "@pagefind/default-ui/css/ui.css"; 5 | export const prerender = true; 6 | --- 7 | 8 | 9 | 31 | 35 |
36 | 40 | { 41 | import.meta.env.DEV ? ( 42 |
43 |

44 | Search is only available in production builds.
45 | Try building and previewing the site to test it out locally. 46 |

47 |
48 | ) : ( 49 |
50 | 52 | ) 53 | } 54 |
55 |
56 |
57 | 58 | 137 | 138 | 196 | 197 | 206 | -------------------------------------------------------------------------------- /src/components/SkipLink.astro: -------------------------------------------------------------------------------- 1 | skip to content 3 | 4 | -------------------------------------------------------------------------------- /src/components/SocialList.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import { Icon } from "astro-icon/components"; 3 | 4 | /** 5 | Uses https://www.astroicon.dev/getting-started/ 6 | Find icons via guide: https://www.astroicon.dev/guides/customization/#open-source-icon-sets 7 | Only installed pack is: @iconify-json/mdi 8 | */ 9 | const socialLinks: { 10 | friendlyName: string; 11 | isWebmention?: boolean; 12 | link: string; 13 | name: string; 14 | }[] = [ 15 | { 16 | friendlyName: "Github", 17 | link: "https://github.com/zouzonghao", 18 | name: "mdi:github", 19 | }, 20 | // 修改:添加其他社交平台链接,name 为 /public/icons/ 下的 svg 文件名 下的 svg 文件名 21 | { 22 | friendlyName: "Bilibili", 23 | link: "https://bilibili.com/", 24 | name: "bilibili", 25 | }, 26 | { 27 | friendlyName: "Nodeseek", 28 | link: "https://www.nodeseek.com/", 29 | name: "nodeseek", 30 | }, 31 | { 32 | friendlyName: "linux.do", 33 | link: "https://linux.do/", 34 | name: "linux.do", 35 | }, 36 | ]; 37 | --- 38 | 39 |
40 | 41 | 58 |
59 | -------------------------------------------------------------------------------- /src/components/ThemeProvider.astro: -------------------------------------------------------------------------------- 1 | {/* Inlined to avoid FOUC. This is a parser blocking script. */} 2 | 48 | -------------------------------------------------------------------------------- /src/components/ThemeToggle.astro: -------------------------------------------------------------------------------- 1 | 2 | 53 | 54 | 55 | 85 | -------------------------------------------------------------------------------- /src/components/blog/Masthead.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import { Image } from "astro:assets"; 3 | import type { CollectionEntry } from "astro:content"; 4 | import FormattedDate from "@/components/FormattedDate.astro"; 5 | 6 | interface Props { 7 | content: CollectionEntry<"post">; 8 | } 9 | 10 | const { 11 | content: { data }, 12 | } = Astro.props; 13 | 14 | const dateTimeOptions: Intl.DateTimeFormatOptions = { 15 | month: "long", 16 | }; 17 | --- 18 | 19 | { 20 | data.coverImage && ( 21 |
22 | {data.coverImage.alt} 29 |
30 | ) 31 | } 32 | {data.draft ? (Draft) : null} 33 |

34 | {data.title} 35 |

36 |
37 |

38 | /{" "} 39 | {/* @ts-ignore:next-line. TODO: add reading time to collection schema? */} 40 | {data.readingTime} 41 |

42 | { 43 | data.updatedDate && ( 44 | 45 | Updated: 46 | 47 | 48 | ) 49 | } 50 |
51 | { 52 | !!data.tags?.length && ( 53 |
54 | 71 | {data.tags.map((tag, i) => ( 72 | <> 73 | {/* prettier-ignore */} 74 | 75 | {tag} 76 | {i < data.tags.length - 1 && ", "} 77 | 78 | 79 | ))} 80 |
81 | ) 82 | } 83 | -------------------------------------------------------------------------------- /src/components/blog/PostPreview.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import type { CollectionEntry } from "astro:content"; 3 | import FormattedDate from "@/components/FormattedDate.astro"; 4 | import type { HTMLTag, Polymorphic } from "astro/types"; 5 | 6 | type Props = Polymorphic<{ as: Tag }> & { 7 | post: CollectionEntry<"post">; 8 | withDesc?: boolean; 9 | }; 10 | 11 | const { as: Tag = "div", post, withDesc = false } = Astro.props; 12 | --- 13 | 14 | 15 | 19 | 20 | {post.data.draft && (Draft) } 21 | 22 | {post.data.title} 23 | 24 | 25 | {withDesc && {post.data.description}} 26 | -------------------------------------------------------------------------------- /src/components/blog/TOC.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import { generateToc } from "@/utils/generateToc"; 3 | import type { MarkdownHeading } from "astro"; 4 | import TOCHeading from "./TOCHeading.astro"; 5 | 6 | interface Props { 7 | headings: MarkdownHeading[]; 8 | } 9 | 10 | const { headings } = Astro.props; 11 | 12 | const toc = generateToc(headings); 13 | --- 14 | 15 | 22 | -------------------------------------------------------------------------------- /src/components/blog/TOCHeading.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import type { TocItem } from "@/utils/generateToc"; 3 | 4 | interface Props { 5 | heading: TocItem; 6 | } 7 | 8 | const { 9 | heading: { children, depth, slug, text }, 10 | } = Astro.props; 11 | --- 12 | 13 |
  • 2 ? "ms-2" : ""}`}> 14 | #{text} 19 | { 20 | !!children.length && ( 21 |
      22 | {children.map((subheading) => ( 23 | 24 | ))} 25 |
    26 | ) 27 | } 28 |
  • 29 | -------------------------------------------------------------------------------- /src/components/blog/webmentions/Comments.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import { Image } from "astro:assets"; 3 | import type { WebmentionsChildren } from "@/types"; 4 | import { Icon } from "astro-icon/components"; 5 | 6 | interface Props { 7 | mentions: WebmentionsChildren[]; 8 | } 9 | 10 | const { mentions } = Astro.props; 11 | 12 | const validComments = ["mention-of", "in-reply-to"]; 13 | 14 | const comments = mentions.filter( 15 | (mention) => validComments.includes(mention["wm-property"]) && mention.content?.text, 16 | ); 17 | 18 | /** 19 | ! show a link to the mention 20 | 21 | */ 22 | --- 23 | 24 | { 25 | !!comments.length && ( 26 |
    27 |

    28 | {comments.length} Mention{comments.length > 1 ? "s" : ""} 29 |

    30 |
      31 | {comments.map((mention) => ( 32 |
    • 33 | {mention.author?.photo && mention.author.photo !== "" ? ( 34 | mention.author.url && mention.author.url !== "" ? ( 35 | 42 | {mention.author?.name} 49 | 50 | ) : ( 51 | {mention.author?.name} 58 | ) 59 | ) : null} 60 |
      61 |
      62 |

      63 | {mention.author?.name} 64 |

      65 | 72 | 75 | 82 |
      83 |

      84 | {mention.content?.text} 85 |

      86 |
      87 |
    • 88 | ))} 89 |
    90 |
    91 | ) 92 | } 93 | -------------------------------------------------------------------------------- /src/components/blog/webmentions/Likes.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import { Image } from "astro:assets"; 3 | import type { WebmentionsChildren } from "@/types"; 4 | 5 | interface Props { 6 | mentions: WebmentionsChildren[]; 7 | } 8 | 9 | const { mentions } = Astro.props; 10 | const MAX_LIKES = 10; 11 | 12 | const likes = mentions.filter((mention) => mention["wm-property"] === "like-of"); 13 | const likesToShow = likes 14 | .filter((like) => like.author?.photo && like.author.photo !== "") 15 | .slice(0, MAX_LIKES); 16 | --- 17 | 18 | { 19 | !!likes.length && ( 20 |
    21 |

    22 | {likes.length} 23 | {likes.length > 1 ? " People" : " Person"} liked this 24 |

    25 | {!!likesToShow.length && ( 26 | 49 | )} 50 |
    51 | ) 52 | } 53 | -------------------------------------------------------------------------------- /src/components/blog/webmentions/index.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import { getWebmentionsForUrl } from "@/utils/webmentions"; 3 | import Comments from "./Comments.astro"; 4 | import Likes from "./Likes.astro"; 5 | 6 | const url = new URL(Astro.url.pathname, Astro.site); 7 | 8 | const webMentions = await getWebmentionsForUrl(`${url}`); 9 | 10 | // Return if no webmentions 11 | if (!webMentions.length) return; 12 | --- 13 | 14 |
    15 |

    Webmentions for this post

    16 |
    17 | 18 | 19 |
    20 |

    21 | Responses powered by{" "} 22 | Webmentions 23 |

    24 | -------------------------------------------------------------------------------- /src/components/layout/Footer.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import { menuLinks, siteConfig } from "@/site.config"; 3 | 4 | const year = new Date().getFullYear(); 5 | --- 6 | 7 |
    10 |
    11 | © {siteConfig.author} 12 | 13 | 14 | {year} 15 |
    16 | 28 |
    29 | -------------------------------------------------------------------------------- /src/components/layout/Header.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import Search from "@/components/Search.astro"; 3 | import ThemeToggle from "@/components/ThemeToggle.astro"; 4 | import { menuLinks } from "@/site.config"; 5 | --- 6 | 7 |
    8 |
    9 | 14 | 15 | 20 | 40 | 41 | 仙人掌主题 42 | 43 | 61 |
    62 | 63 | 64 | 65 | 102 | 103 |
    104 | 105 | 125 | -------------------------------------------------------------------------------- /src/components/note/Note.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import { type CollectionEntry, render } from "astro:content"; 3 | import FormattedDate from "@/components/FormattedDate.astro"; 4 | import type { HTMLTag, Polymorphic } from "astro/types"; 5 | 6 | type Props = Polymorphic<{ as: Tag }> & { 7 | note: CollectionEntry<"note">; 8 | isPreview?: boolean | undefined; 9 | }; 10 | 11 | const { as: Tag = "div", note, isPreview = false } = Astro.props; 12 | const { Content } = await render(note); 13 | --- 14 | 15 |
    21 | 22 | { 23 | isPreview ? ( 24 | 25 | {note.data.title} 26 | 27 | ) : ( 28 | <>{note.data.title} 29 | ) 30 | } 31 | 32 | 33 | 43 |
    47 | 48 |
    49 |
    50 | -------------------------------------------------------------------------------- /src/content.config.ts: -------------------------------------------------------------------------------- 1 | import { defineCollection, z } from "astro:content"; 2 | import { glob } from "astro/loaders"; 3 | 4 | function removeDupsAndLowerCase(array: string[]) { 5 | return [...new Set(array.map((str) => str.toLowerCase()))]; 6 | } 7 | 8 | const baseSchema = z.object({ 9 | title: z.string().max(60), 10 | }); 11 | 12 | const post = defineCollection({ 13 | loader: glob({ base: "./src/content/post", pattern: "**/*.{md,mdx}" }), 14 | schema: ({ image }) => 15 | baseSchema.extend({ 16 | description: z.string(), 17 | coverImage: z 18 | .object({ 19 | alt: z.string(), 20 | src: image(), 21 | }) 22 | .optional(), 23 | draft: z.boolean().default(false), 24 | ogImage: z.string().optional(), 25 | tags: z.array(z.string()).default([]).transform(removeDupsAndLowerCase), 26 | publishDate: z 27 | .string() 28 | .or(z.date()) 29 | .transform((val) => new Date(val)), 30 | updatedDate: z 31 | .string() 32 | .optional() 33 | .transform((str) => (str ? new Date(str) : undefined)), 34 | }), 35 | }); 36 | 37 | const note = defineCollection({ 38 | loader: glob({ base: "./src/content/note", pattern: "**/*.{md,mdx}" }), 39 | schema: baseSchema.extend({ 40 | description: z.string().optional(), 41 | publishDate: z 42 | .string() 43 | // .datetime({ offset: true }) // Ensures ISO 8601 format with offsets allowed (e.g. "2024-01-01T00:00:00Z" and "2024-01-01T00:00:00+02:00") 44 | // .transform((val) => new Date(val)), 45 | .refine((val) => { 46 | // 修改:解析自定义格式的日期字符串,兼容 "YYYY-MM-DD HH:mm" 和 "YYYY-MM-DDTHH:mm" 47 | const datePattern = /^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}$/; 48 | return datePattern.test(val); 49 | }, "Invalid date format. Expected YYYY-MM-DD HH:mm or YYYY-MM-DDTHH:mm") 50 | .transform((val) => { 51 | // 统一处理分隔符,将 "T" 替换为空格 52 | const normalizedVal = val.replace("T", " "); 53 | const [datePart, timePart] = normalizedVal.split(" "); 54 | if (!datePart || !timePart) { 55 | throw new Error("Invalid date format. Expected YYYY-MM-DD HH:mm or YYYY-MM-DDTHH:mm"); 56 | } 57 | const [year, month, day] = datePart.split("-"); 58 | const [hour, minute] = timePart.split(":"); 59 | if (!year || !month || !day || !hour || !minute) { 60 | throw new Error("Invalid date format. Expected YYYY-MM-DD HH:mm or YYYY-MM-DDTHH:mm"); 61 | } 62 | return new Date(Number(year), Number(month) - 1, Number(day), Number(hour), Number(minute)); 63 | }), 64 | }), 65 | }); 66 | 67 | export const collections = { post, note }; 68 | -------------------------------------------------------------------------------- /src/content/note/demo.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 示例 3 | description: 一则笔记 4 | publishDate: "2024-12-13 16:35" 5 | --- 6 | 7 | 学海无涯苦做舟 8 | -------------------------------------------------------------------------------- /src/content/post/demo/cover-image/cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zouzonghao/Astro-theme-Cactus-zh_CN/b25a7399c3fadca5b176dd8e6afca6d805c866ce/src/content/post/demo/cover-image/cover.png -------------------------------------------------------------------------------- /src/content/post/demo/cover-image/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "示例3 添加封面图" 3 | description: "这篇文章是如何添加封面的示例" 4 | publishDate: "1998-07-28" 5 | coverImage: 6 | src: "./cover.png" 7 | alt: "封面图" 8 | tags: ["示例"] 9 | ogImage: "/social-card.avif" 10 | --- 11 | 12 | ## 添加封面图 13 | 14 | 在 Front Matter(最上面用`---`包裹的内容)里,添加一个 `coverImage` 属性,并设置图片路径和描述。 15 | 16 | ```yaml 17 | --- 18 | title: "示例3 添加封面图" 19 | description: "这篇文章是如何添加封面的示例" 20 | publishDate: "1998-07-28" 21 | coverImage: 22 | src: "./cover.png" 23 | alt: "封面图" 24 | tags: ["示例"] 25 | ogImage: "/social-card.avif" 26 | --- 27 | 28 | ``` 29 | 30 | ## 路径 31 | 32 | 将图片和文章放入相同文件夹下 33 | 34 | 通过 `./cover.png` 来引入图片 35 | 36 | 在文章中也是一样的 37 | 38 | 如: 39 | 40 | ```md 41 | ![](./cover.png) 42 | ``` 43 | 44 | 显示: 45 | 46 | ![Astro build wallpaper](./cover.png) 47 | -------------------------------------------------------------------------------- /src/content/post/demo/draft-post.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "示例4 草稿" 3 | description: "This post is for testing the draft post functionality" 4 | publishDate: "1998-07-27" 5 | tags: ["示例"] 6 | draft: true 7 | ogImage: "/social-card.avif" 8 | --- 9 | 10 | 如果你的文章还未完成 11 | 12 | 在 Front Matter(最上面用`---`包裹的内容)里,添加一个 `draft` 属性,并设置为 `true`。 13 | 14 | 此时你的文章只会在运行 `pnpm run dev` 时可见,其他情况下会被忽略 15 | 16 | ```yaml 17 | --- 18 | title: "示例4 草稿" 19 | description: "This post is for testing the draft post functionality" 20 | publishDate: "1998-07-27" 21 | tags: ["示例"] 22 | draft: true 23 | ogImage: "/social-card.avif" 24 | --- 25 | ``` 26 | -------------------------------------------------------------------------------- /src/content/post/demo/markdown-elements/admonistions.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "示例2 Markdown 提示框" 3 | description: "本文展示了在仙人掌中使用 Markdown 提示框功能" 4 | publishDate: "1998-07-29" 5 | tags: ["示例"] 6 | ogImage: "/social-card.avif" 7 | --- 8 | 9 | ## 什么是提示框 10 | 11 | 提示框(也称为“侧边栏”)用于提供与内容相关的支持性和/或补充性信息。 12 | 13 | ## 如何使用 14 | 15 | 在 Astro Cactus 中使用提示框,将你的 Markdown 内容包裹在一对三冒号 `:::` 中。第一对冒号还应包含你想要使用的提示框类型。 16 | 17 | 例如,使用以下 Markdown: 18 | 19 | ```md 20 | :::note 21 | 突出显示用户应注意的信息,即使在快速浏览时也应留意。 22 | ::: 23 | ``` 24 | 25 | 输出: 26 | 27 | :::note 28 | 突出显示用户应注意的信息,即使在快速浏览时也应留意。 29 | ::: 30 | 31 | ## 提示框类型 32 | 33 | 目前支持以下提示框类型: 34 | 35 | - `note` 36 | - `tip` 37 | - `important` 38 | - `warning` 39 | - `caution` 40 | 41 | ### 注意 42 | 43 | ```md 44 | :::note 45 | 突出显示用户应注意的信息,即使在快速浏览时也应留意。 46 | ::: 47 | ``` 48 | 49 | :::note 50 | 突出显示用户应注意的信息,即使在快速浏览时也应留意。 51 | ::: 52 | 53 | ### 提示 54 | 55 | ```md 56 | :::tip 57 | 可选信息,帮助用户更成功。 58 | ::: 59 | ``` 60 | 61 | :::tip 62 | 可选信息,帮助用户更成功。 63 | ::: 64 | 65 | ### 重要 66 | 67 | ```md 68 | :::important 69 | 用户成功所必需的关键信息。 70 | ::: 71 | ``` 72 | 73 | :::important 74 | 用户成功所必需的关键信息。 75 | ::: 76 | 77 | ### 警告 78 | 79 | ```md 80 | :::warning 81 | 由于潜在风险,需要用户立即关注的关键内容。 82 | ::: 83 | ``` 84 | 85 | :::warning 86 | 由于潜在风险,需要用户立即关注的关键内容。 87 | ::: 88 | 89 | ### 小心 90 | 91 | ```md 92 | :::caution 93 | 行动的负面潜在后果。 94 | ::: 95 | ``` 96 | 97 | :::caution 98 | 行动的负面潜在后果。 99 | ::: 100 | 101 | ## 自定义提示框标题 102 | 103 | 你可以使用以下标记自定义提示框标题: 104 | 105 | ```md 106 | :::note[我的自定义标题] 107 | 这是一个带有自定义标题的提示框。 108 | ::: 109 | ``` 110 | 111 | 输出: 112 | 113 | :::note[我的自定义标题] 114 | 这是一个带有自定义标题的提示框。 115 | ::: 116 | -------------------------------------------------------------------------------- /src/content/post/demo/markdown-elements/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "示例1 Markdown 基本语法" 3 | description: "这篇文章用于测试和列出多种不同的Markdown元素" 4 | publishDate: "1998-07-30" 5 | tags: ["示例"] 6 | ogImage: "/social-card.avif" 7 | --- 8 | 9 | ## 这是一个H2标题 10 | 11 | ### 这是一个H3标题 12 | 13 | #### 这是一个H4标题 14 | 15 | ##### 这是一个H5标题 16 | 17 | ###### 这是一个H6标题 18 | 19 | ## 水平线 20 | 21 | *** 22 | 23 | --- 24 | 25 | ___ 26 | 27 | ## 强调 28 | 29 | **这是粗体文本** 30 | 31 | _这是斜体文本_ 32 | 33 | ~~删除线~~ 34 | 35 | ## 引用 36 | 37 | "双引号" 和 '单引号' 38 | 39 | ## 块引用 40 | 41 | > 块引用也可以嵌套... 42 | > 43 | > > ...通过在每个块引用符号旁边使用额外的大于号... 44 | 45 | ## 参考文献 46 | 47 | 一个包含可点击参考文献[^1]并链接到来源的例子。 48 | 49 | 第二个包含参考文献[^2]并链接到来源的例子。 50 | 51 | [^1]: 第一个脚注的参考文献,带有返回内容的链接。 52 | 53 | [^2]: 第二个参考文献,带有一个链接。 54 | 55 | 如果你查看`src/content/post/markdown-elements/index.md`中的这个例子,你会发现参考文献和“脚注”标题是通过 [remark-rehype](https://github.com/remarkjs/remark-rehype#options) 插件添加到页面底部的。 56 | 57 | ## 列表 58 | 59 | 无序列表 60 | 61 | - 通过在行首使用 `+`, `-`, 或 `*` 来创建列表 62 | - 子列表通过缩进两个空格来实现: 63 | - 更改标记字符会强制开始新的列表: 64 | - Ac tristique libero volutpat at 65 | - Facilisis in pretium nisl aliquet 66 | - Nulla volutpat aliquam velit 67 | - 非常简单! 68 | 69 | 有序列表 70 | 71 | 1. Lorem ipsum dolor sit amet 72 | 2. Consectetur adipiscing elit 73 | 3. Integer molestie lorem at massa 74 | 75 | 4. 你可以使用连续的数字... 76 | 5. ...或者将所有数字都设为 `1.` 77 | 78 | 从偏移量开始编号: 79 | 80 | 57. foo 81 | 1. bar 82 | 83 | ## 代码 84 | 85 | 内联 `code` 86 | 87 | 缩进代码 88 | 89 | // Some comments 90 | line 1 of code 91 | line 2 of code 92 | line 3 of code 93 | 94 | 代码块 "fences" 95 | 96 | ``` 97 | Sample text here... 98 | ``` 99 | 100 | 语法高亮 101 | 102 | ```js 103 | var foo = function (bar) { 104 | return bar++; 105 | }; 106 | 107 | console.log(foo(5)); 108 | ``` 109 | 110 | ### 表达性代码示例 111 | 112 | 添加标题 113 | 114 | ```js title="file.js" 115 | console.log("Title example"); 116 | ``` 117 | 118 | Bash终端 119 | 120 | ```bash 121 | echo "A base terminal example" 122 | ``` 123 | 124 | 高亮代码行 125 | 126 | ```js title="line-markers.js" del={2} ins={3-4} {6} 127 | function demo() { 128 | console.log("this line is marked as deleted"); 129 | // This line and the next one are marked as inserted 130 | console.log("this is the second inserted line"); 131 | 132 | return "this line uses the neutral default marker type"; 133 | } 134 | ``` 135 | 136 | [Expressive Code](https://expressive-code.com/) 可以做比这里展示的多得多的事情,并且包括很多 [自定义选项](https://expressive-code.com/reference/configuration/)。 137 | 138 | ## 表格 139 | 140 | | Option | Description | 141 | | ------ | ------------------------------------------------------------------------- | 142 | | data | path to data files to supply the data that will be passed into templates. | 143 | | engine | engine to be used for processing templates. Handlebars is the default. | 144 | | ext | extension to be used for dest files. | 145 | 146 | ### 表格对齐 147 | 148 | | Item | Price | # In stock | 149 | | ------------ | :---: | ---------: | 150 | | Juicy Apples | 1.99 | 739 | 151 | | Bananas | 1.89 | 6 | 152 | 153 | ### 键盘元素 154 | 155 | | Action | Shortcut | 156 | | --------------------- | ------------------------------------------ | 157 | | Vertical split | Alt+Shift++ | 158 | | Horizontal split | Alt+Shift+- | 159 | | Auto split | Alt+Shift+d | 160 | | Switch between splits | Alt + arrow keys | 161 | | Resizing a split | Alt+Shift + arrow keys | 162 | | Close a split | Ctrl+Shift+W | 163 | | Maximize a pane | Ctrl+Shift+P + Toggle pane zoom | 164 | 165 | ## 图像 166 | 167 | 同一文件夹中的图像:`src/content/post/demo/markdown-elements/logo.png` 168 | 169 | ![Astro theme cactus logo](./logo.png) 170 | 171 | ## 链接 172 | 173 | [Markdown-it的内容](https://markdown-it.github.io/) 174 | -------------------------------------------------------------------------------- /src/content/post/demo/markdown-elements/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zouzonghao/Astro-theme-Cactus-zh_CN/b25a7399c3fadca5b176dd8e6afca6d805c866ce/src/content/post/demo/markdown-elements/logo.png -------------------------------------------------------------------------------- /src/content/post/demo/social-image/1215191008.avif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zouzonghao/Astro-theme-Cactus-zh_CN/b25a7399c3fadca5b176dd8e6afca6d805c866ce/src/content/post/demo/social-image/1215191008.avif -------------------------------------------------------------------------------- /src/content/post/demo/social-image/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "示例5 社交图片卡片" 3 | publishDate: "1998-07-26" 4 | description: "详细说明如何在 frontmatter 中添加自定义社交图片卡片" 5 | tags: ["示例"] 6 | ogImage: "/social-card.avif" 7 | --- 8 | 9 | ## 什么是社交图片卡片? 10 | 11 | 社交图片,也称为 OG(OpenGraph) 图片 12 | 13 | 当你想要分享你的文章到社交平台时,你可能会看到一张由网站自动生成的卡片。 14 | 15 | ![](./1215191008.avif) 16 | 17 | ## 添加自定义社交图片 18 | 19 | 在 Front Matter(最上面用`---`包裹的内容)里,添加一个 `ogImage` 属性,并设置路径(相对路径的根路径为 `src/public` 文件夹)。 20 | 21 | ```yaml 22 | --- 23 | title: "示例5 社交图片卡片" 24 | publishDate: "1998-07-26" 25 | description: "详细说明如何在 frontmatter 中添加自定义社交图片卡片" 26 | tags: ["示例"] 27 | ogImage: "/social-card.avif" 28 | --- 29 | ``` 30 | ## 如果不添加`ogImage`属性(不推荐) 31 | 32 | 如果 `ogImage` 属性没有设置,则项目会在构建的时候,根据文章标题、标签生成一张社交图片。 33 | 34 | 通过编辑 `src/pages/og-image/[...slug].png.ts` 控制生成规则。 35 | 36 | 此举会增加构建时间,极大地增加构建体积。 37 | 38 | 推荐全部文章使用一张图片,作为默认的社交图片。 39 | -------------------------------------------------------------------------------- /src/data/post.ts: -------------------------------------------------------------------------------- 1 | import { type CollectionEntry, getCollection } from "astro:content"; 2 | 3 | /** filter out draft posts based on the environment */ 4 | export async function getAllPosts(): Promise[]> { 5 | return await getCollection("post", ({ data }) => { 6 | return import.meta.env.PROD ? !data.draft : true; 7 | }); 8 | } 9 | 10 | /** groups posts by year (based on option siteConfig.sortPostsByUpdatedDate), using the year as the key 11 | * Note: This function doesn't filter draft posts, pass it the result of getAllPosts above to do so. 12 | */ 13 | export function groupPostsByYear(posts: CollectionEntry<"post">[]) { 14 | return posts.reduce[]>>((acc, post) => { 15 | const year = post.data.publishDate.getFullYear(); 16 | if (!acc[year]) { 17 | acc[year] = []; 18 | } 19 | acc[year]?.push(post); 20 | return acc; 21 | }, {}); 22 | } 23 | 24 | /** returns all tags created from posts (inc duplicate tags) 25 | * Note: This function doesn't filter draft posts, pass it the result of getAllPosts above to do so. 26 | * */ 27 | export function getAllTags(posts: CollectionEntry<"post">[]) { 28 | return posts.flatMap((post) => [...post.data.tags]); 29 | } 30 | 31 | /** returns all unique tags created from posts 32 | * Note: This function doesn't filter draft posts, pass it the result of getAllPosts above to do so. 33 | * */ 34 | export function getUniqueTags(posts: CollectionEntry<"post">[]) { 35 | return [...new Set(getAllTags(posts))]; 36 | } 37 | 38 | /** returns a count of each unique tag - [[tagName, count], ...] 39 | * Note: This function doesn't filter draft posts, pass it the result of getAllPosts above to do so. 40 | * */ 41 | export function getUniqueTagsWithCount(posts: CollectionEntry<"post">[]): [string, number][] { 42 | return [ 43 | ...getAllTags(posts).reduce( 44 | (acc, t) => acc.set(t, (acc.get(t) ?? 0) + 1), 45 | new Map(), 46 | ), 47 | ].sort((a, b) => b[1] - a[1]); 48 | } 49 | -------------------------------------------------------------------------------- /src/env.d.ts: -------------------------------------------------------------------------------- 1 | declare module "@pagefind/default-ui" { 2 | declare class PagefindUI { 3 | constructor(arg: unknown); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /src/layouts/Base.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import BaseHead from "@/components/BaseHead.astro"; 3 | import SkipLink from "@/components/SkipLink.astro"; 4 | import ThemeProvider from "@/components/ThemeProvider.astro"; 5 | import Footer from "@/components/layout/Footer.astro"; 6 | import Header from "@/components/layout/Header.astro"; 7 | import { siteConfig } from "@/site.config"; 8 | import type { SiteMeta } from "@/types"; 9 | 10 | interface Props { 11 | meta: SiteMeta; 12 | } 13 | 14 | const { 15 | meta: { articleDate, description = siteConfig.description, ogImage, title }, 16 | } = Astro.props; 17 | --- 18 | 19 | 20 | 21 | 22 | 27 | 28 | 31 | 32 | 33 |
    34 |
    35 | 36 |
    37 |