跳转到内容

手动安装

本指南将引导您手动安装和配置 Lunaria 到现有项目中。

1. 添加 @lunariajs/core

Lunaria 通过 npm 仓库中的 @lunariajs/core 包发布。请在项目根目录中运行以下命令,将其添加到您的项目中:

Terminal window
npm install @lunariajs/core

然后,在您的 package.jsonscripts 字段中添加以下 lunaria 命令:

package.json
"scripts": {
"dev": "astro dev",
"build": "astro build",
"preview": "astro preview",
"lunaria:build": "lunaria build",
"lunaria:preview": "lunaria preview",
}

2. 创建 lunaria.config.json

Lunaria 使用 lunaria.config.json 进行配置。此文件是必需的,以便 Lunaria 了解您的仓库结构以及需要追踪的内容。

lunaria.config.json
{
"$schema": "./node_modules/@lunariajs/core/config.schema.json"
}

3. 配置包

在生成第一个本地化仪表板之前,您必须设置 lunaria.config.json 文件中的 repositorydefaultLocalelocales 字段。

以下示例将 Lunaria 配置为在一个示例项目中追踪英文和葡萄牙语的 Markdown/MDX 内容,该项目托管在 https://github.com/me/cool-project/

lunaria.config.json
{
"$schema": "./node_modules/@lunariajs/core/config.schema.json",
"repository": {
"name": "me/cool-docs"
},
"files": [
{
"location": "content/**/*.md",
"pattern": "content/@lang/@path",
"type": "universal"
}
],
"defaultLocale": {
"label": "英语",
"lang": "en"
},
"locales": [
{
"label": "葡萄牙语",
"lang": "pt"
}
]
}

详细了解所有可用选项,请参阅 配置参考指南

4. 下一步

成功!您现在已经准备好在项目中使用 Lunaria 了!

如果您已完整遵循本指南,可以直接跳转至 构建您的第一个仪表板,学习如何生成本地化仪表板、在浏览器中查看,并了解我们的推荐下一步操作。