Skip to content

Commit

Permalink
refactor([...slug].astro): 去除文档编号
Browse files Browse the repository at this point in the history
  • Loading branch information
Yue-plus committed Sep 5, 2024
1 parent 61d7aef commit b247663
Show file tree
Hide file tree
Showing 14 changed files with 189 additions and 141 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
"@nanostores/react": "^0.7.3",
"@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0",
"astro": "^4.15.2",
"astro": "^4.15.3",
"nanostores": "^0.11.3",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"sass": "^1.77.8",
"sass": "^1.78.0",
"swiper": "^11.1.12",
"tailwindcss": "^3.4.10",
"typescript": "^5.5.4"
Expand Down
246 changes: 123 additions & 123 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/components/DocsLeftAside.astro
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ const allDocs = await getCollection("docs");
{allDocs.map(({id, slug, body, collection, data}, index) =>
<li class="hover:text-ark-blue line-clamp-3 duration-300">
<!-- TODO: 按文件夹分层可折叠 -->
<a target="_self" href={base + "docs/" + slug.split("-").slice(1).join("-")}>
<a target="_self" href={base + "docs/" + slug.split("/").map((item, index, array) => {
return item.includes("_") ? item.split("_").slice(1).join() : item
}).join("/")}>
{data.title ?? id}
</a>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ title: 项目介绍

代码部分使用 [MIT License](https://github.com/Yue-plus/astro-arknights/blob/main/LICENSE)

[内容集合(`src/content`](https://github.com/Yue-plus/astro-arknights/tree/main/src/content) 内的所有内容使用
[内容集合(`src/content`](https://github.com/Yue-plus/astro-arknights/tree/main/src/content) 中的所有内容均使用
<a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh-hans" target="_blank" rel="license noopener noreferrer" style="display:inline-block;">
CC BY-NC-SA 4.0
<img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/cc.svg?ref=chooser-v1" alt="">
Expand Down
11 changes: 11 additions & 0 deletions src/content/docs/01_用户文档/03_部署站点.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: 部署站点
---

# 部署站点

本项目基于 Astro,可以完全参照 [Astro 官方的部署文档](https://docs.astro.build/zh-cn/guides/deploy/)

<https://arknights.astro.yue.zone/> 站点托管于 GitHub Pages,可以参考
[`.github/workflows/deploy.yml`](https://github.com/Yue-plus/astro-arknights/blob/main/.github/workflows/deploy.yml)
文件。
9 changes: 9 additions & 0 deletions src/content/docs/01_用户文档/04_项目结构.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: 项目结构
---

# 项目结构

> 参考 Astro 官方文档:[项目结构 - 基础知识](https://docs.astro.build/zh-cn/basics/project-structure/)
TODO: 介绍 `arknights.config.tsx` 配置文件。
22 changes: 22 additions & 0 deletions src/content/docs/01_用户文档/05_开始写作.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
title: 开始写作
---

# 开始写作

> 参考 Astro 官方文档:[创作内容 - 管理你的内容](https://docs.astro.build/zh-cn/guides/content/)
## 默认的内容集合

> 参考:
> - Astro 官方文档:[内容集合 - 管理你的内容](https://docs.astro.build/zh-cn/guides/content-collections/)
> - [本项目的内容集合组织方式](https://github.com/Yue-plus/astro-arknights/tree/main/src/content)
本项目默认创建了 **文档(`docs/`****博客(`blog/`** 两个内容集合。
其中的内容条目 **推荐** 以下命名规范:

01. 文件名不要带空格(需要的话使用连词符(`-`)代替空格);
02. 使用下划线分隔 *编号**标题*

- 文档:`<n>_<dir1>/<n>_<dir2>/<n>_<title>.md`
- 博客:`<yyyy>-<MM>-<dd>_<title>.md`
2 changes: 1 addition & 1 deletion src/layouts/InfoLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ const subNavigationItems = Astro.props.subNavigationItems
box-sizing: border-box;
}

p, th, td {
p, li, th, td {
code {
background-color: rgba(255, 255, 255, 0.125);
padding: 0 3px;
Expand Down
20 changes: 12 additions & 8 deletions src/pages/docs/[...slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import {getCollection} from 'astro:content'
// import {Debug} from 'astro:components'
import type {SubNavigationItem} from "../../_types/SubNavigationItem"
import DocsLayout from "../../layouts/DocsLayout.astro"
import DocsToolPanel from "../../components/DocsToolPanel"
import DocsLeftAsideSwitch from "../../components/DocsLeftAsideSwitch"
export async function getStaticPaths() {
return (await getCollection("docs")).map(entry => ({
params: {slug: entry.slug.split("-").slice(1).join("-")},
params: {
slug: entry.slug.split("/").map((item, index, array) => {
return item.includes("_") ? item.split("_").slice(1).join() : item
}).join("/"),
},
props: {entry},
}))
}
Expand All @@ -20,13 +22,15 @@ const title = entry?.data?.title ?? "无标题"
const subNavigationItems: SubNavigationItem[] = (await getCollection("docs"))
.map(({id, slug, body, collection, data}, index) => ({
title: data.title ?? id,
href: base + "docs/" + slug.split("-").slice(1).join("-"),
href: base + "docs/" + slug.split("/").map((item, index, array) => {
return item.includes("_") ? item.split("_").slice(1).join() : item
}).join("/"),
}))
---

<DocsLayout {...{title, subNavigationItems, headings}}>
<!--<Debug {allDocs}/>-->
<article>
<Content/>
</article>
<!--<Debug {allDocs}/>-->
<article>
<Content/>
</article>
</DocsLayout>
10 changes: 5 additions & 5 deletions src/pages/docs/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ import {getCollection} from 'astro:content'
// import {Debug} from 'astro:components'
import type {SubNavigationItem} from "../../_types/SubNavigationItem"
import DocsLayout from "../../layouts/DocsLayout.astro"
import DocsLeftAside from "../../components/DocsLeftAside.astro"
import DocsLeftAsideSwitch from "../../components/DocsLeftAsideSwitch"
import {IconArrow} from "../../components/SvgIcons"
const base = import.meta.env.BASE_URL
const subNavigationItems: SubNavigationItem[] = (await getCollection("docs"))
.map(({id, slug, body, collection, data}, index) => ({
title: data.title ?? id,
href: base + "docs/" + slug.split("-").slice(1).join("-"),
href: base + "docs/" + slug.split("/").map((item, index, array) => {
return item.includes("_") ? item.split("_").slice(1).join() : item
}).join("/"),
}))
---

<DocsLayout title="首页" {...{subNavigationItems}}>
<!--<Debug />-->
<article class="h-full flex flex-col justify-center">
<!--<Debug/>-->
<h1 class="font-benderBold">Astro Arknights 文档</h1>
<p class="font-benderRegular">指南、资源和 API 参考,帮助你使用 Astro 进行构建。</p>
<a target="_self" href="./用户文档/01-项目介绍"
<a target="_self" href="./用户文档/项目介绍"
class="w-[18rem] h-[4.8rem] text-inherit no-underline hover:text-black hover:bg-ark-blue bg-[#5a5a5a] px-[2.5rem] flex items-center justify-between cursor-pointer transition-[color,background-color] duration-300">
<div>
<div class="text-[1.6rem] font-bold">开始使用</div>
Expand Down

0 comments on commit b247663

Please sign in to comment.