快速开始
开始使用 Astro Theme Pure
安装#
有两种安装方式。“模板”方式轻量且简单,但难以更新;而“Fork”方式易于更新但需要一些 git 技能。
使用模板安装#
-
安装主题
在你的用户目录下执行以下命令来安装主题:
shellbun create astro@latest --template cworld1/astro-theme-pure
shellpnpm create astro@latest --template cworld1/astro-theme-pure
shellyarn create astro --template cworld1/astro-theme-pure
shellnpm create astro@latest -- --template cworld1/astro-theme-pure默认情况下,此命令将使用模板仓库的主分支。要使用不同的分支名称,请将其作为
--template参数的一部分传递:cworld1/astro-theme-pure#<分支名>。 -
回答问题并遵循 CLI 向导的指示。
-
搞定!
你现在可以 启动 Astro 开发服务器 ↗ 并看到项目的实时预览,同时开始个性化你的项目!
使用 Fork 安装#
你只需 点击主题仓库的 fork 按钮 ↗ 创建你的项目;然后将 fork 的仓库克隆到本地机器。
git clone https://github.com/<你的用户名>/astro-theme-pure.gitshell然后,你就可以启动 Astro 开发服务器并看到项目的实时预览,同时开始个性化你的项目!
启动开发服务器#
进入你的项目目录:
cd ./<你的项目>shellbun devshellpnpm devshellyarn run devshellnpm run devshell接下来,请先阅读配置说明,然后继续配置主题。
迁移到 Astro#
主题文件结构#
主题的文件结构如下:
public:将被复制到根目录的静态资源src:assets:静态资源components:主题中使用的组件,也包括类似用户组件的组件,如Card、Collapse、Spoiler等layouts:基础站点布局pages:页面,如404、about、blog、docs、index等plugins:主题中使用的扩展插件types:TypeScript 类型定义utils:工具函数site.config.ts:主题配置文件astro.config.ts:Astro 配置文件eslint.config.mjs:ESLint 配置文件prettier.config.mjs:Prettier 配置文件uno.config.ts:UnoCSS 配置文件tsconfig.json:TypeScript 配置文件package.json:包信息
简单设置#
-
删除文档文件
- 删除
src/pages/docs目录 - 删除
src/site.config.ts中的菜单声明:
src/site.config.ts
tsexport const theme: ThemeUserConfig = { // ... /** 配置你网站的头部。 */ header: { menu: [ { title: '博客', link: '/blog' }, { title: '文档', link: '/docs' }, // ... ], }, }- 删除
src/content.config.ts中针对文档的内容集合:
src/content.config.ts
tsconst docs = defineCollection({ loader: glob({ base: './src/content/docs', pattern: '**/*.{md,mdx}' }), schema: ({ image }) => z.object({ ... }) }) export const collections = { blog, docs } export const collections = { blog } - 删除
-
删除
packages目录(这将被我们的 NPM 包导入)。记得更改
package.json中的workspaces字段:package.json
json{ "name": "astro-theme-pure", "workspaces": [ "packages/*" ], // ... } -
更改站点 favicon。
用你自己的 favicon 替换
public/favicon/*文件。 -
替换你的头像图片。
用你自己的头像图片替换
src/assets/avatar.png文件。 -
配置站点
你可以在
src/site.config.ts配置文件中配置你的项目:src/site.config.ts
tsexport const theme: ThemeUserConfig = { author: 'CWorld', title: 'Astro Theme Pure', site: 'https://astro-pure.js.org', description: '保持饥饿,保持愚蠢', // ... } export const integ: IntegrationUserConfig = { /* ... */ } // ... -
TypeScript 语法
配置文件
site.config.ts使用 TypeScript 语法。如果你不熟悉 TS 语法,请先阅读 这里 ↗。