快速开始
开始使用 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默认情况下,此命令将使用模板仓库的
main分支。要使用其他分支名称,请将其作为--template参数的一部分传递:cworld1/astro-theme-pure#<branch>。 -
回答问题并按照 CLI 向导的说明进行操作。
-
大功告成!
您现在可以 启动 Astro 开发服务器 ↗ 并查看项目的实时预览,同时将其打造为您自己的风格!
使用 Fork 安装#
您只需 点击主题仓库中的 fork 按钮 ↗ 来创建您的项目;然后将 fork 后的仓库克隆到您的本地机器。
git clone https://github.com/<your-username>/astro-theme-pure.gitshell然后,您可以启动 Astro 开发服务器并查看项目的实时预览!
启动开发服务器#
进入您的项目目录:
cd ./<your-project>shellbun devshellpnpm devshellyarn run devshellnpm run devshell接下来,请先阅读配置说明并继续配置主题。
迁移到 Astro#
主题文件结构#
主题文件结构如下:
public: 静态资源,将直接复制到根目录src:assets: 静态资源(经过 Astro 处理)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 = { // ... /** Configure the header of your site. */ header: { menu: [ { title: 'Blog', link: '/blog' }, { title: 'Docs', link: '/docs' }, // ... ], }, }- 移除
src/content.config.ts中 docs 的内容集合 (Content Collection):
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。
将
public/favicon/*文件替换为您自己的 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: 'Stay hungry, stay foolish', // ... } export const integ: IntegrationUserConfig = { /* ... */ } // ... -
Typescript 语法
配置文件
site.config.ts使用 Typescript 语法。如果您不熟悉 TS 语法,请先阅读 此处 ↗ 的相关内容。