@cogita/theme-knowledge 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ARCHITECTURE.md +27 -0
- package/LICENSE +21 -0
- package/README.md +33 -0
- package/dist/components/Relations.js +73 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +66 -0
- package/dist/layouts/Home.js +213 -0
- package/dist/layouts/Search.js +116 -0
- package/dist/layouts/Tag.js +129 -0
- package/dist/theme.css +540 -0
- package/dist/utils.js +21 -0
- package/package.json +76 -0
package/ARCHITECTURE.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Knowledge 主题架构
|
|
2
|
+
|
|
3
|
+
`@cogita/theme-knowledge` 只负责知识库的信息架构和运行时展示,不扫描文件,也不解析
|
|
4
|
+
Markdown。内容数据由 Core 的统一 `ContentIndex` 提供,搜索、标签和关系由插件生成虚拟模块。
|
|
5
|
+
|
|
6
|
+
```text
|
|
7
|
+
posts/*.md + content/**/*.md
|
|
8
|
+
↓
|
|
9
|
+
ContentIndex
|
|
10
|
+
↙ ↓ ↘
|
|
11
|
+
search tags relations
|
|
12
|
+
↘ ↓ ↙
|
|
13
|
+
Knowledge 主题布局
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
主题默认注册 `pluginPostsFrontmatter`、`pluginContentCheck`、`pluginSearch`、
|
|
17
|
+
`pluginTags` 和 `pluginContentRelations`。搜索、标签和关系插件通过主题包装器提供合理默认配置,
|
|
18
|
+
内容诊断插件则只有在站点显式配置 `contentCheck` 后才执行。
|
|
19
|
+
|
|
20
|
+
## 页面边界
|
|
21
|
+
|
|
22
|
+
- 首页展示统一内容条目、主题标签和关系数量;
|
|
23
|
+
- 搜索页消费搜索虚拟模块,不在浏览器重新读取源文件;
|
|
24
|
+
- 标签页消费标签虚拟模块,可展示标签索引和标签详情;
|
|
25
|
+
- 全局关系组件在有出链或反向链接的内容页展示探索入口;
|
|
26
|
+
- 内容诊断插件对文章和文档统一生成质量报告,不把检查逻辑放入布局;
|
|
27
|
+
- 文章和文档的正文仍由 Rspress 内容页面负责。
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 wu9o
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# @cogita/theme-knowledge
|
|
2
|
+
|
|
3
|
+
面向知识库、个人 Wiki 和技术研究站点的 Cogita 主题。
|
|
4
|
+
|
|
5
|
+
主题默认组合以下能力:
|
|
6
|
+
|
|
7
|
+
- 统一文章与 `contentDir` 文档索引;
|
|
8
|
+
- 本地搜索;
|
|
9
|
+
- 标签聚合;
|
|
10
|
+
- 内容出链与反向链接;
|
|
11
|
+
- 可选的统一内容质量诊断;
|
|
12
|
+
- 首页内容探索、搜索页和标签页。
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add -D @cogita/cli @cogita/core @cogita/theme-knowledge
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { defineConfig } from '@cogita/core';
|
|
20
|
+
|
|
21
|
+
export default defineConfig({
|
|
22
|
+
site: {
|
|
23
|
+
title: '我的知识库',
|
|
24
|
+
description: '连接文章、文档和长期积累的知识。',
|
|
25
|
+
},
|
|
26
|
+
posts: { dir: 'posts', routePrefix: 'posts' },
|
|
27
|
+
contentDir: 'content',
|
|
28
|
+
theme: '@cogita/theme-knowledge',
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
搜索、标签和内容关系默认启用;站点仍可以通过 `search`、`tags` 和
|
|
33
|
+
`contentRelations` 配置覆盖路由或关闭对应能力。显式配置 `contentCheck` 后,主题会对文章和普通文档共同生成内容质量报告。
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { normalizeHrefInRuntime, usePageData } from "@rspress/runtime";
|
|
3
|
+
import { t } from "virtual-cogita-i18n-text";
|
|
4
|
+
import { getBacklinks, getContentRelations, getOutgoingLinks } from "virtual-content-relations-data";
|
|
5
|
+
import { getBase, getHref, getPageRoute } from "../utils.js";
|
|
6
|
+
function RelationList(param) {
|
|
7
|
+
let { title, items, base } = param;
|
|
8
|
+
if (0 === items.length) return null;
|
|
9
|
+
return /*#__PURE__*/ jsxs("section", {
|
|
10
|
+
className: "knowledge-relations-section",
|
|
11
|
+
children: [
|
|
12
|
+
/*#__PURE__*/ jsx("h3", {
|
|
13
|
+
children: title
|
|
14
|
+
}),
|
|
15
|
+
/*#__PURE__*/ jsx("ul", {
|
|
16
|
+
children: items.slice(0, 6).map((item)=>/*#__PURE__*/ jsxs("li", {
|
|
17
|
+
children: [
|
|
18
|
+
/*#__PURE__*/ jsx("a", {
|
|
19
|
+
href: normalizeHrefInRuntime(getHref(base, item.route)),
|
|
20
|
+
children: item.title
|
|
21
|
+
}),
|
|
22
|
+
/*#__PURE__*/ jsx("span", {
|
|
23
|
+
children: 'document' === item.kind ? t('knowledge.relations.document', "\u6587\u6863") : t('knowledge.relations.post', "\u6587\u7AE0")
|
|
24
|
+
})
|
|
25
|
+
]
|
|
26
|
+
}, `${title}-${item.route}`))
|
|
27
|
+
})
|
|
28
|
+
]
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
const Relations_Relations = ()=>{
|
|
32
|
+
const pageData = usePageData();
|
|
33
|
+
const base = getBase(pageData);
|
|
34
|
+
const route = getPageRoute(pageData, base);
|
|
35
|
+
const relation = getContentRelations(route);
|
|
36
|
+
const outbound = getOutgoingLinks(route);
|
|
37
|
+
const inbound = getBacklinks(route);
|
|
38
|
+
if (0 === relation.outbound.length && 0 === relation.inbound.length) return null;
|
|
39
|
+
return /*#__PURE__*/ jsxs("aside", {
|
|
40
|
+
className: "knowledge-relations",
|
|
41
|
+
"aria-label": t('knowledge.relations.ariaLabel', "\u5185\u5BB9\u5173\u7CFB"),
|
|
42
|
+
children: [
|
|
43
|
+
/*#__PURE__*/ jsxs("div", {
|
|
44
|
+
className: "knowledge-relations-heading",
|
|
45
|
+
children: [
|
|
46
|
+
/*#__PURE__*/ jsx("span", {
|
|
47
|
+
children: "Knowledge graph"
|
|
48
|
+
}),
|
|
49
|
+
/*#__PURE__*/ jsx("strong", {
|
|
50
|
+
children: t('knowledge.relations.continue', "\u7EE7\u7EED\u63A2\u7D22")
|
|
51
|
+
})
|
|
52
|
+
]
|
|
53
|
+
}),
|
|
54
|
+
/*#__PURE__*/ jsxs("div", {
|
|
55
|
+
className: "knowledge-relations-groups",
|
|
56
|
+
children: [
|
|
57
|
+
/*#__PURE__*/ jsx(RelationList, {
|
|
58
|
+
title: t('knowledge.relations.outbound', "\u672C\u6587\u94FE\u63A5\u5230"),
|
|
59
|
+
items: outbound,
|
|
60
|
+
base: base
|
|
61
|
+
}),
|
|
62
|
+
/*#__PURE__*/ jsx(RelationList, {
|
|
63
|
+
title: t('knowledge.relations.inbound', "\u53CD\u5411\u94FE\u63A5"),
|
|
64
|
+
items: inbound,
|
|
65
|
+
base: base
|
|
66
|
+
})
|
|
67
|
+
]
|
|
68
|
+
})
|
|
69
|
+
]
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
var Relations = Relations_Relations;
|
|
73
|
+
export { Relations as default };
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { fileURLToPath } from "url";
|
|
3
|
+
import { pluginContentCheck } from "@cogita/plugin-content-check";
|
|
4
|
+
import { pluginContentRelations } from "@cogita/plugin-content-relations";
|
|
5
|
+
import { pluginI18n } from "@cogita/plugin-i18n";
|
|
6
|
+
import { pluginPostsFrontmatter } from "@cogita/plugin-posts-frontmatter";
|
|
7
|
+
import { pluginSearch } from "@cogita/plugin-search";
|
|
8
|
+
import { pluginTags } from "@cogita/plugin-tags";
|
|
9
|
+
import { COGITA_CAPABILITIES } from "@cogita/shared";
|
|
10
|
+
function withDefaultConfig(key, defaults, factory) {
|
|
11
|
+
return (config)=>factory({
|
|
12
|
+
...config,
|
|
13
|
+
[key]: {
|
|
14
|
+
...defaults,
|
|
15
|
+
...config[key]
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
const knowledgeRelations = (config)=>pluginContentRelations({
|
|
20
|
+
...config,
|
|
21
|
+
contentRelations: {
|
|
22
|
+
enabled: true,
|
|
23
|
+
...config.contentRelations
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
const knowledgeSearch = withDefaultConfig('search', {
|
|
27
|
+
enabled: true,
|
|
28
|
+
includeContent: true
|
|
29
|
+
}, pluginSearch);
|
|
30
|
+
const knowledgeTags = withDefaultConfig('tags', {
|
|
31
|
+
enabled: true
|
|
32
|
+
}, pluginTags);
|
|
33
|
+
function getThemeConfig() {
|
|
34
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
35
|
+
return {
|
|
36
|
+
name: '@cogita/theme-knowledge',
|
|
37
|
+
capabilities: {
|
|
38
|
+
required: [
|
|
39
|
+
COGITA_CAPABILITIES.CONTENT_POSTS
|
|
40
|
+
],
|
|
41
|
+
optional: [
|
|
42
|
+
COGITA_CAPABILITIES.CONTENT_RELATIONS,
|
|
43
|
+
COGITA_CAPABILITIES.DISCOVERY_SEARCH,
|
|
44
|
+
COGITA_CAPABILITIES.DISCOVERY_TAGS
|
|
45
|
+
]
|
|
46
|
+
},
|
|
47
|
+
pageLayouts: {
|
|
48
|
+
home: './layouts/Home.js',
|
|
49
|
+
search: './layouts/Search.js',
|
|
50
|
+
tag: './layouts/Tag.js'
|
|
51
|
+
},
|
|
52
|
+
globalStyles: path.resolve(__dirname, './theme.css'),
|
|
53
|
+
globalUIComponents: [
|
|
54
|
+
path.resolve(__dirname, './components/Relations.js')
|
|
55
|
+
],
|
|
56
|
+
plugins: [
|
|
57
|
+
pluginI18n,
|
|
58
|
+
pluginPostsFrontmatter,
|
|
59
|
+
pluginContentCheck,
|
|
60
|
+
knowledgeRelations,
|
|
61
|
+
knowledgeSearch,
|
|
62
|
+
knowledgeTags
|
|
63
|
+
]
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export { getThemeConfig };
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { normalizeHrefInRuntime, usePageData } from "@rspress/runtime";
|
|
3
|
+
import { useMemo } from "react";
|
|
4
|
+
import { t } from "virtual-cogita-i18n-text";
|
|
5
|
+
import { contentRelations } from "virtual-content-relations-data";
|
|
6
|
+
import { searchConfig, searchDocuments } from "virtual-search-data";
|
|
7
|
+
import { allTags, tagsConfig } from "virtual-tags-data";
|
|
8
|
+
import { getBase, getHref, getKnowledgeCopy } from "../utils.js";
|
|
9
|
+
const HomeLayout = ()=>{
|
|
10
|
+
const pageData = usePageData();
|
|
11
|
+
const base = getBase(pageData);
|
|
12
|
+
const copy = getKnowledgeCopy(pageData);
|
|
13
|
+
const recentEntries = useMemo(()=>[
|
|
14
|
+
...searchDocuments
|
|
15
|
+
].sort((left, right)=>right.updateDate.localeCompare(left.updateDate)).slice(0, 8), []);
|
|
16
|
+
const relationCount = contentRelations.reduce((total, relation)=>total + relation.outbound.length, 0);
|
|
17
|
+
return /*#__PURE__*/ jsxs("main", {
|
|
18
|
+
className: "knowledge-home",
|
|
19
|
+
children: [
|
|
20
|
+
/*#__PURE__*/ jsxs("section", {
|
|
21
|
+
className: "knowledge-hero",
|
|
22
|
+
children: [
|
|
23
|
+
/*#__PURE__*/ jsxs("div", {
|
|
24
|
+
children: [
|
|
25
|
+
/*#__PURE__*/ jsxs("p", {
|
|
26
|
+
className: "knowledge-eyebrow",
|
|
27
|
+
children: [
|
|
28
|
+
copy.title,
|
|
29
|
+
" \xb7 KNOWLEDGE BASE"
|
|
30
|
+
]
|
|
31
|
+
}),
|
|
32
|
+
/*#__PURE__*/ jsx("h1", {
|
|
33
|
+
children: copy.description
|
|
34
|
+
}),
|
|
35
|
+
/*#__PURE__*/ jsx("p", {
|
|
36
|
+
className: "knowledge-lead",
|
|
37
|
+
children: copy.lead
|
|
38
|
+
}),
|
|
39
|
+
/*#__PURE__*/ jsxs("nav", {
|
|
40
|
+
className: "knowledge-actions",
|
|
41
|
+
"aria-label": t('knowledge.home.navigation', "\u77E5\u8BC6\u5E93\u5BFC\u822A"),
|
|
42
|
+
children: [
|
|
43
|
+
/*#__PURE__*/ jsx("a", {
|
|
44
|
+
href: normalizeHrefInRuntime(getHref(base, '/search')),
|
|
45
|
+
children: t('knowledge.home.search', "\u641C\u7D22\u77E5\u8BC6")
|
|
46
|
+
}),
|
|
47
|
+
/*#__PURE__*/ jsx("a", {
|
|
48
|
+
href: normalizeHrefInRuntime(getHref(base, `/${tagsConfig.routePrefix}`)),
|
|
49
|
+
children: t('knowledge.home.tags', "\u6D4F\u89C8\u6807\u7B7E")
|
|
50
|
+
})
|
|
51
|
+
]
|
|
52
|
+
})
|
|
53
|
+
]
|
|
54
|
+
}),
|
|
55
|
+
/*#__PURE__*/ jsxs("div", {
|
|
56
|
+
className: "knowledge-stats",
|
|
57
|
+
"aria-label": t('knowledge.home.stats', "\u77E5\u8BC6\u5E93\u7EDF\u8BA1"),
|
|
58
|
+
children: [
|
|
59
|
+
/*#__PURE__*/ jsxs("div", {
|
|
60
|
+
children: [
|
|
61
|
+
/*#__PURE__*/ jsx("strong", {
|
|
62
|
+
children: searchDocuments.length
|
|
63
|
+
}),
|
|
64
|
+
/*#__PURE__*/ jsx("span", {
|
|
65
|
+
children: t('knowledge.home.contentEntries', "\u5185\u5BB9\u6761\u76EE")
|
|
66
|
+
})
|
|
67
|
+
]
|
|
68
|
+
}),
|
|
69
|
+
/*#__PURE__*/ jsxs("div", {
|
|
70
|
+
children: [
|
|
71
|
+
/*#__PURE__*/ jsx("strong", {
|
|
72
|
+
children: allTags.length
|
|
73
|
+
}),
|
|
74
|
+
/*#__PURE__*/ jsx("span", {
|
|
75
|
+
children: t('knowledge.home.topicTags', "\u4E3B\u9898\u6807\u7B7E")
|
|
76
|
+
})
|
|
77
|
+
]
|
|
78
|
+
}),
|
|
79
|
+
/*#__PURE__*/ jsxs("div", {
|
|
80
|
+
children: [
|
|
81
|
+
/*#__PURE__*/ jsx("strong", {
|
|
82
|
+
children: relationCount
|
|
83
|
+
}),
|
|
84
|
+
/*#__PURE__*/ jsx("span", {
|
|
85
|
+
children: t('knowledge.home.contentLinks', "\u5185\u5BB9\u8FDE\u63A5")
|
|
86
|
+
})
|
|
87
|
+
]
|
|
88
|
+
})
|
|
89
|
+
]
|
|
90
|
+
})
|
|
91
|
+
]
|
|
92
|
+
}),
|
|
93
|
+
/*#__PURE__*/ jsxs("div", {
|
|
94
|
+
className: "knowledge-grid",
|
|
95
|
+
children: [
|
|
96
|
+
/*#__PURE__*/ jsxs("section", {
|
|
97
|
+
className: "knowledge-recent",
|
|
98
|
+
"aria-labelledby": "knowledge-recent-title",
|
|
99
|
+
children: [
|
|
100
|
+
/*#__PURE__*/ jsxs("div", {
|
|
101
|
+
className: "knowledge-section-heading",
|
|
102
|
+
children: [
|
|
103
|
+
/*#__PURE__*/ jsxs("div", {
|
|
104
|
+
children: [
|
|
105
|
+
/*#__PURE__*/ jsx("p", {
|
|
106
|
+
className: "knowledge-section-label",
|
|
107
|
+
children: t('knowledge.home.recentLabel', 'Recently updated')
|
|
108
|
+
}),
|
|
109
|
+
/*#__PURE__*/ jsx("h2", {
|
|
110
|
+
id: "knowledge-recent-title",
|
|
111
|
+
children: t('knowledge.home.recentTitle', "\u6700\u8FD1\u66F4\u65B0")
|
|
112
|
+
})
|
|
113
|
+
]
|
|
114
|
+
}),
|
|
115
|
+
/*#__PURE__*/ jsx("a", {
|
|
116
|
+
href: normalizeHrefInRuntime(getHref(base, '/search')),
|
|
117
|
+
children: t('knowledge.home.viewAll', "\u67E5\u770B\u5168\u90E8 \u2192")
|
|
118
|
+
})
|
|
119
|
+
]
|
|
120
|
+
}),
|
|
121
|
+
/*#__PURE__*/ jsx("div", {
|
|
122
|
+
className: "knowledge-entry-list",
|
|
123
|
+
children: recentEntries.map((entry)=>/*#__PURE__*/ jsxs("a", {
|
|
124
|
+
href: normalizeHrefInRuntime(getHref(base, entry.route)),
|
|
125
|
+
className: "knowledge-entry-card",
|
|
126
|
+
children: [
|
|
127
|
+
/*#__PURE__*/ jsx("span", {
|
|
128
|
+
className: "knowledge-entry-kind",
|
|
129
|
+
children: 'document' === entry.kind ? t('knowledge.home.document', "\u6587\u6863") : t('knowledge.home.post', "\u6587\u7AE0")
|
|
130
|
+
}),
|
|
131
|
+
/*#__PURE__*/ jsx("strong", {
|
|
132
|
+
children: entry.title
|
|
133
|
+
}),
|
|
134
|
+
/*#__PURE__*/ jsx("p", {
|
|
135
|
+
children: entry.description || entry.excerpt || t('knowledge.home.openEntry', "\u6253\u5F00\u6761\u76EE\u7EE7\u7EED\u9605\u8BFB\u3002")
|
|
136
|
+
}),
|
|
137
|
+
/*#__PURE__*/ jsx("small", {
|
|
138
|
+
children: entry.updateDate.slice(0, 10)
|
|
139
|
+
})
|
|
140
|
+
]
|
|
141
|
+
}, entry.route))
|
|
142
|
+
})
|
|
143
|
+
]
|
|
144
|
+
}),
|
|
145
|
+
/*#__PURE__*/ jsxs("aside", {
|
|
146
|
+
className: "knowledge-discovery",
|
|
147
|
+
children: [
|
|
148
|
+
/*#__PURE__*/ jsxs("section", {
|
|
149
|
+
className: "knowledge-discovery-card",
|
|
150
|
+
children: [
|
|
151
|
+
/*#__PURE__*/ jsxs("div", {
|
|
152
|
+
className: "knowledge-section-heading compact",
|
|
153
|
+
children: [
|
|
154
|
+
/*#__PURE__*/ jsxs("div", {
|
|
155
|
+
children: [
|
|
156
|
+
/*#__PURE__*/ jsx("p", {
|
|
157
|
+
className: "knowledge-section-label",
|
|
158
|
+
children: "Explore"
|
|
159
|
+
}),
|
|
160
|
+
/*#__PURE__*/ jsx("h2", {
|
|
161
|
+
children: t('knowledge.home.explore', "\u6309\u4E3B\u9898\u63A2\u7D22")
|
|
162
|
+
})
|
|
163
|
+
]
|
|
164
|
+
}),
|
|
165
|
+
/*#__PURE__*/ jsx("span", {
|
|
166
|
+
children: allTags.length
|
|
167
|
+
})
|
|
168
|
+
]
|
|
169
|
+
}),
|
|
170
|
+
/*#__PURE__*/ jsx("div", {
|
|
171
|
+
className: "knowledge-tag-list",
|
|
172
|
+
children: allTags.slice(0, 18).map((tag)=>/*#__PURE__*/ jsxs("a", {
|
|
173
|
+
href: normalizeHrefInRuntime(getHref(base, tag.route)),
|
|
174
|
+
children: [
|
|
175
|
+
tag.name,
|
|
176
|
+
/*#__PURE__*/ jsx("span", {
|
|
177
|
+
children: tag.count
|
|
178
|
+
})
|
|
179
|
+
]
|
|
180
|
+
}, tag.slug))
|
|
181
|
+
})
|
|
182
|
+
]
|
|
183
|
+
}),
|
|
184
|
+
/*#__PURE__*/ jsxs("section", {
|
|
185
|
+
className: "knowledge-discovery-card knowledge-search-card",
|
|
186
|
+
children: [
|
|
187
|
+
/*#__PURE__*/ jsx("p", {
|
|
188
|
+
className: "knowledge-section-label",
|
|
189
|
+
children: t('knowledge.home.findAnything', 'Find anything')
|
|
190
|
+
}),
|
|
191
|
+
/*#__PURE__*/ jsx("h2", {
|
|
192
|
+
children: t('knowledge.home.findStart', "\u4ECE\u4E00\u4E2A\u5173\u952E\u8BCD\u5F00\u59CB\u3002")
|
|
193
|
+
}),
|
|
194
|
+
/*#__PURE__*/ jsx("p", {
|
|
195
|
+
children: t('knowledge.home.searchCount', "\u5168\u6587\u7D22\u5F15 {{count}} \u4E2A\u5185\u5BB9\u6761\u76EE\u3002", {
|
|
196
|
+
count: searchDocuments.length
|
|
197
|
+
})
|
|
198
|
+
}),
|
|
199
|
+
/*#__PURE__*/ jsx("a", {
|
|
200
|
+
href: normalizeHrefInRuntime(getHref(base, `/${searchConfig.routePrefix}`)),
|
|
201
|
+
children: t('knowledge.home.openSearch', "\u6253\u5F00\u641C\u7D22 \u2192")
|
|
202
|
+
})
|
|
203
|
+
]
|
|
204
|
+
})
|
|
205
|
+
]
|
|
206
|
+
})
|
|
207
|
+
]
|
|
208
|
+
})
|
|
209
|
+
]
|
|
210
|
+
});
|
|
211
|
+
};
|
|
212
|
+
var Home = HomeLayout;
|
|
213
|
+
export { Home as default };
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { normalizeHrefInRuntime, usePageData } from "@rspress/runtime";
|
|
3
|
+
import { useMemo, useState } from "react";
|
|
4
|
+
import { t } from "virtual-cogita-i18n-text";
|
|
5
|
+
import { searchConfig, searchDocuments } from "virtual-search-data";
|
|
6
|
+
import { getBase, getHref, getKnowledgeCopy } from "../utils.js";
|
|
7
|
+
const SearchLayout = ()=>{
|
|
8
|
+
const pageData = usePageData();
|
|
9
|
+
const base = getBase(pageData);
|
|
10
|
+
const copy = getKnowledgeCopy(pageData);
|
|
11
|
+
const [query, setQuery] = useState('');
|
|
12
|
+
const normalizedQuery = query.trim().toLocaleLowerCase();
|
|
13
|
+
const meetsMinimumLength = normalizedQuery.length >= searchConfig.minQueryLength;
|
|
14
|
+
const results = useMemo(()=>{
|
|
15
|
+
if (!meetsMinimumLength) return [];
|
|
16
|
+
return searchDocuments.map((entry)=>{
|
|
17
|
+
const haystack = [
|
|
18
|
+
entry.title,
|
|
19
|
+
entry.description,
|
|
20
|
+
entry.excerpt,
|
|
21
|
+
entry.content,
|
|
22
|
+
...entry.tags || [],
|
|
23
|
+
...entry.categories || []
|
|
24
|
+
].filter(Boolean).join(' ').toLocaleLowerCase();
|
|
25
|
+
const titleHit = entry.title.toLocaleLowerCase().includes(normalizedQuery);
|
|
26
|
+
const score = titleHit ? 3 : haystack.includes(normalizedQuery) ? 1 : 0;
|
|
27
|
+
return {
|
|
28
|
+
entry,
|
|
29
|
+
score
|
|
30
|
+
};
|
|
31
|
+
}).filter((result)=>result.score > 0).sort((left, right)=>right.score - left.score).slice(0, searchConfig.maxResults);
|
|
32
|
+
}, [
|
|
33
|
+
meetsMinimumLength,
|
|
34
|
+
normalizedQuery
|
|
35
|
+
]);
|
|
36
|
+
return /*#__PURE__*/ jsxs("main", {
|
|
37
|
+
className: "knowledge-search",
|
|
38
|
+
children: [
|
|
39
|
+
/*#__PURE__*/ jsxs("header", {
|
|
40
|
+
className: "knowledge-search-header",
|
|
41
|
+
children: [
|
|
42
|
+
/*#__PURE__*/ jsxs("p", {
|
|
43
|
+
className: "knowledge-eyebrow",
|
|
44
|
+
children: [
|
|
45
|
+
copy.title,
|
|
46
|
+
" \xb7 ",
|
|
47
|
+
t('knowledge.search.eyebrow', 'SEARCH')
|
|
48
|
+
]
|
|
49
|
+
}),
|
|
50
|
+
/*#__PURE__*/ jsx("h1", {
|
|
51
|
+
children: t('knowledge.search.title', "\u627E\u5230\u4E0B\u4E00\u6761\u76F8\u5173\u77E5\u8BC6\u3002")
|
|
52
|
+
}),
|
|
53
|
+
/*#__PURE__*/ jsx("p", {
|
|
54
|
+
children: t("knowledge.search.description", "\u641C\u7D22\u6587\u7AE0\u3001\u6587\u6863\u3001\u6807\u7B7E\u548C\u6B63\u6587\u5185\u5BB9\u3002")
|
|
55
|
+
}),
|
|
56
|
+
/*#__PURE__*/ jsx("input", {
|
|
57
|
+
type: "search",
|
|
58
|
+
value: query,
|
|
59
|
+
onChange: (event)=>setQuery(event.target.value),
|
|
60
|
+
placeholder: t('knowledge.search.placeholder', "\u81F3\u5C11\u8F93\u5165 {{count}} \u4E2A\u5B57\u7B26", {
|
|
61
|
+
count: searchConfig.minQueryLength
|
|
62
|
+
}),
|
|
63
|
+
"aria-label": t('knowledge.search.ariaLabel', "\u641C\u7D22\u77E5\u8BC6\u5E93")
|
|
64
|
+
})
|
|
65
|
+
]
|
|
66
|
+
}),
|
|
67
|
+
/*#__PURE__*/ jsxs("section", {
|
|
68
|
+
className: "knowledge-search-results",
|
|
69
|
+
"aria-live": "polite",
|
|
70
|
+
children: [
|
|
71
|
+
!meetsMinimumLength && /*#__PURE__*/ jsx("p", {
|
|
72
|
+
className: "knowledge-empty",
|
|
73
|
+
children: normalizedQuery ? t('knowledge.search.minLength', "\u8BF7\u8F93\u5165\u81F3\u5C11 {{count}} \u4E2A\u5B57\u7B26\u3002", {
|
|
74
|
+
count: searchConfig.minQueryLength
|
|
75
|
+
}) : t('knowledge.search.empty', "\u8F93\u5165\u5173\u952E\u8BCD\u5F00\u59CB\u63A2\u7D22\u3002")
|
|
76
|
+
}),
|
|
77
|
+
meetsMinimumLength && 0 === results.length && /*#__PURE__*/ jsx("p", {
|
|
78
|
+
className: "knowledge-empty",
|
|
79
|
+
children: t('knowledge.search.noResults', "\u6CA1\u6709\u627E\u5230\u5339\u914D\u7684\u5185\u5BB9\u3002")
|
|
80
|
+
}),
|
|
81
|
+
results.map((param)=>{
|
|
82
|
+
let { entry } = param;
|
|
83
|
+
var _entry_content;
|
|
84
|
+
return /*#__PURE__*/ jsxs("article", {
|
|
85
|
+
className: "knowledge-search-result",
|
|
86
|
+
children: [
|
|
87
|
+
/*#__PURE__*/ jsx("span", {
|
|
88
|
+
children: 'document' === entry.kind ? t('knowledge.search.document', "\u6587\u6863") : t('knowledge.search.post', "\u6587\u7AE0")
|
|
89
|
+
}),
|
|
90
|
+
/*#__PURE__*/ jsx("h2", {
|
|
91
|
+
children: /*#__PURE__*/ jsx("a", {
|
|
92
|
+
href: normalizeHrefInRuntime(getHref(base, entry.route)),
|
|
93
|
+
children: entry.title
|
|
94
|
+
})
|
|
95
|
+
}),
|
|
96
|
+
/*#__PURE__*/ jsx("p", {
|
|
97
|
+
children: entry.description || entry.excerpt || (null == (_entry_content = entry.content) ? void 0 : _entry_content.slice(0, 180))
|
|
98
|
+
}),
|
|
99
|
+
/*#__PURE__*/ jsx("div", {
|
|
100
|
+
children: (entry.tags || []).slice(0, 4).map((tag)=>/*#__PURE__*/ jsxs("span", {
|
|
101
|
+
children: [
|
|
102
|
+
"#",
|
|
103
|
+
tag
|
|
104
|
+
]
|
|
105
|
+
}, tag))
|
|
106
|
+
})
|
|
107
|
+
]
|
|
108
|
+
}, entry.route);
|
|
109
|
+
})
|
|
110
|
+
]
|
|
111
|
+
})
|
|
112
|
+
]
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
var Search = SearchLayout;
|
|
116
|
+
export { Search as default };
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { normalizeHrefInRuntime, usePageData } from "@rspress/runtime";
|
|
3
|
+
import { t } from "virtual-cogita-i18n-text";
|
|
4
|
+
import { allTags, getRelatedTags, tagsConfig } from "virtual-tags-data";
|
|
5
|
+
import { getBase, getHref, getKnowledgeCopy, getPageRoute } from "../utils.js";
|
|
6
|
+
const TagLayout = ()=>{
|
|
7
|
+
const pageData = usePageData();
|
|
8
|
+
const base = getBase(pageData);
|
|
9
|
+
const prefix = tagsConfig.routePrefix.replace(/^\/+|\/+$/g, '');
|
|
10
|
+
const route = getPageRoute(pageData, base).replace(/^\/+/, '');
|
|
11
|
+
const slug = route.startsWith(`${prefix}/`) ? route.slice(prefix.length + 1) : '';
|
|
12
|
+
const tag = allTags.find((item)=>item.slug === slug);
|
|
13
|
+
const copy = getKnowledgeCopy(pageData);
|
|
14
|
+
if (!slug) return /*#__PURE__*/ jsxs("main", {
|
|
15
|
+
className: "knowledge-tag-page",
|
|
16
|
+
children: [
|
|
17
|
+
/*#__PURE__*/ jsxs("header", {
|
|
18
|
+
className: "knowledge-page-header",
|
|
19
|
+
children: [
|
|
20
|
+
/*#__PURE__*/ jsxs("p", {
|
|
21
|
+
className: "knowledge-eyebrow",
|
|
22
|
+
children: [
|
|
23
|
+
copy.title,
|
|
24
|
+
" \xb7 ",
|
|
25
|
+
t('knowledge.tag.eyebrow', 'TOPICS')
|
|
26
|
+
]
|
|
27
|
+
}),
|
|
28
|
+
/*#__PURE__*/ jsx("h1", {
|
|
29
|
+
children: t('knowledge.tag.title', "\u6309\u4E3B\u9898\u63A2\u7D22")
|
|
30
|
+
}),
|
|
31
|
+
/*#__PURE__*/ jsx("p", {
|
|
32
|
+
children: t("knowledge.tag.description", "\u6807\u7B7E\u628A\u5206\u6563\u7684\u6587\u7AE0\u548C\u6587\u6863\u805A\u5408\u6210\u53EF\u590D\u7528\u7684\u77E5\u8BC6\u5165\u53E3\u3002")
|
|
33
|
+
})
|
|
34
|
+
]
|
|
35
|
+
}),
|
|
36
|
+
/*#__PURE__*/ jsx("div", {
|
|
37
|
+
className: "knowledge-all-tags",
|
|
38
|
+
children: allTags.map((item)=>/*#__PURE__*/ jsxs("a", {
|
|
39
|
+
href: normalizeHrefInRuntime(getHref(base, item.route)),
|
|
40
|
+
children: [
|
|
41
|
+
/*#__PURE__*/ jsx("strong", {
|
|
42
|
+
children: item.name
|
|
43
|
+
}),
|
|
44
|
+
/*#__PURE__*/ jsx("span", {
|
|
45
|
+
children: t('knowledge.tag.contentCount', "{{count}} \u6761\u5185\u5BB9", {
|
|
46
|
+
count: item.count
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
]
|
|
50
|
+
}, item.slug))
|
|
51
|
+
})
|
|
52
|
+
]
|
|
53
|
+
});
|
|
54
|
+
if (!tag) return /*#__PURE__*/ jsxs("main", {
|
|
55
|
+
className: "knowledge-tag-page",
|
|
56
|
+
children: [
|
|
57
|
+
/*#__PURE__*/ jsx("a", {
|
|
58
|
+
href: normalizeHrefInRuntime(getHref(base, `/${prefix}`)),
|
|
59
|
+
children: t('knowledge.tag.back', "\u2190 \u8FD4\u56DE\u5168\u90E8\u4E3B\u9898")
|
|
60
|
+
}),
|
|
61
|
+
/*#__PURE__*/ jsx("h1", {
|
|
62
|
+
children: t('knowledge.tag.notFound', "\u4E3B\u9898\u4E0D\u5B58\u5728")
|
|
63
|
+
})
|
|
64
|
+
]
|
|
65
|
+
});
|
|
66
|
+
const relatedTags = getRelatedTags(tag.name, 8);
|
|
67
|
+
return /*#__PURE__*/ jsxs("main", {
|
|
68
|
+
className: "knowledge-tag-page",
|
|
69
|
+
children: [
|
|
70
|
+
/*#__PURE__*/ jsxs("header", {
|
|
71
|
+
className: "knowledge-page-header",
|
|
72
|
+
children: [
|
|
73
|
+
/*#__PURE__*/ jsx("a", {
|
|
74
|
+
href: normalizeHrefInRuntime(getHref(base, `/${prefix}`)),
|
|
75
|
+
children: t('knowledge.tag.back', "\u2190 \u8FD4\u56DE\u5168\u90E8\u4E3B\u9898")
|
|
76
|
+
}),
|
|
77
|
+
/*#__PURE__*/ jsx("p", {
|
|
78
|
+
className: "knowledge-eyebrow",
|
|
79
|
+
children: t('knowledge.tag.topic', 'TOPIC')
|
|
80
|
+
}),
|
|
81
|
+
/*#__PURE__*/ jsxs("h1", {
|
|
82
|
+
children: [
|
|
83
|
+
"#",
|
|
84
|
+
tag.name
|
|
85
|
+
]
|
|
86
|
+
}),
|
|
87
|
+
/*#__PURE__*/ jsx("p", {
|
|
88
|
+
children: t('knowledge.tag.around', "{{count}} \u6761\u5185\u5BB9\u56F4\u7ED5\u8FD9\u4E2A\u4E3B\u9898\u5C55\u5F00\u3002", {
|
|
89
|
+
count: tag.count
|
|
90
|
+
})
|
|
91
|
+
})
|
|
92
|
+
]
|
|
93
|
+
}),
|
|
94
|
+
/*#__PURE__*/ jsx("div", {
|
|
95
|
+
className: "knowledge-tag-entries",
|
|
96
|
+
children: tag.posts.map((entry)=>/*#__PURE__*/ jsxs("a", {
|
|
97
|
+
href: normalizeHrefInRuntime(getHref(base, entry.route)),
|
|
98
|
+
children: [
|
|
99
|
+
/*#__PURE__*/ jsx("strong", {
|
|
100
|
+
children: entry.title
|
|
101
|
+
}),
|
|
102
|
+
/*#__PURE__*/ jsx("span", {
|
|
103
|
+
children: entry.description || t('knowledge.tag.open', "\u6253\u5F00\u6761\u76EE\u7EE7\u7EED\u9605\u8BFB\u3002")
|
|
104
|
+
})
|
|
105
|
+
]
|
|
106
|
+
}, entry.route))
|
|
107
|
+
}),
|
|
108
|
+
relatedTags.length > 0 && /*#__PURE__*/ jsxs("section", {
|
|
109
|
+
className: "knowledge-related-tags",
|
|
110
|
+
children: [
|
|
111
|
+
/*#__PURE__*/ jsx("h2", {
|
|
112
|
+
children: t('knowledge.tag.related', "\u76F8\u5173\u4E3B\u9898")
|
|
113
|
+
}),
|
|
114
|
+
/*#__PURE__*/ jsx("div", {
|
|
115
|
+
children: relatedTags.map((item)=>/*#__PURE__*/ jsxs("a", {
|
|
116
|
+
href: normalizeHrefInRuntime(getHref(base, item.route)),
|
|
117
|
+
children: [
|
|
118
|
+
"#",
|
|
119
|
+
item.name
|
|
120
|
+
]
|
|
121
|
+
}, item.slug))
|
|
122
|
+
})
|
|
123
|
+
]
|
|
124
|
+
})
|
|
125
|
+
]
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
var Tag = TagLayout;
|
|
129
|
+
export { Tag as default };
|
package/dist/theme.css
ADDED
|
@@ -0,0 +1,540 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--rp-sidebar-width: 0px;
|
|
3
|
+
--rp-nav-width: 0px;
|
|
4
|
+
--cogita-knowledge-bg: #f4f6f2;
|
|
5
|
+
--cogita-knowledge-surface: #ffffff;
|
|
6
|
+
--cogita-knowledge-border: #dce4dc;
|
|
7
|
+
--cogita-knowledge-text: #1d2a24;
|
|
8
|
+
--cogita-knowledge-muted: #68776d;
|
|
9
|
+
--cogita-knowledge-accent: #276749;
|
|
10
|
+
--cogita-knowledge-accent-soft: #dcefe4;
|
|
11
|
+
--cogita-knowledge-shadow: 0 20px 60px rgba(35, 65, 46, 0.08);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/* 知识库没有默认文档侧栏,首页、搜索和标签页应占用完整内容宽度。 */
|
|
15
|
+
.rspress-doc:has(.knowledge-home),
|
|
16
|
+
.rspress-doc:has(.knowledge-search),
|
|
17
|
+
.rspress-doc:has(.knowledge-tag-page) {
|
|
18
|
+
max-width: none !important;
|
|
19
|
+
margin: 0 !important;
|
|
20
|
+
padding: 0 !important;
|
|
21
|
+
overflow-x: clip;
|
|
22
|
+
background: transparent;
|
|
23
|
+
border: 0;
|
|
24
|
+
border-radius: 0;
|
|
25
|
+
box-shadow: none;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/* 知识库内容页按实际内容收缩,避免短文章被默认视口高度撑出大块空白。 */
|
|
29
|
+
.rspress-doc {
|
|
30
|
+
min-height: 0 !important;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@media (min-width: 801px) {
|
|
34
|
+
aside.rspress-sidebar {
|
|
35
|
+
display: none !important;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
html,
|
|
40
|
+
body {
|
|
41
|
+
background: var(--cogita-knowledge-bg);
|
|
42
|
+
color: var(--cogita-knowledge-text);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.knowledge-home,
|
|
46
|
+
.knowledge-search,
|
|
47
|
+
.knowledge-tag-page {
|
|
48
|
+
max-width: 1180px;
|
|
49
|
+
min-height: 100vh;
|
|
50
|
+
margin: 0 auto;
|
|
51
|
+
padding: clamp(48px, 8vw, 104px) 24px;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.knowledge-hero {
|
|
55
|
+
display: grid;
|
|
56
|
+
grid-template-columns: minmax(0, 1fr) minmax(260px, 0.7fr);
|
|
57
|
+
gap: clamp(32px, 7vw, 100px);
|
|
58
|
+
align-items: end;
|
|
59
|
+
padding-bottom: 72px;
|
|
60
|
+
border-bottom: 1px solid var(--cogita-knowledge-border);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.knowledge-eyebrow,
|
|
64
|
+
.knowledge-section-label {
|
|
65
|
+
margin: 0 0 16px;
|
|
66
|
+
color: var(--cogita-knowledge-accent);
|
|
67
|
+
font-size: 12px;
|
|
68
|
+
font-weight: 750;
|
|
69
|
+
letter-spacing: 0.16em;
|
|
70
|
+
text-transform: uppercase;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.knowledge-hero h1,
|
|
74
|
+
.knowledge-search-header h1,
|
|
75
|
+
.knowledge-page-header h1 {
|
|
76
|
+
max-width: 760px;
|
|
77
|
+
margin: 0;
|
|
78
|
+
font-size: clamp(40px, 6vw, 78px);
|
|
79
|
+
letter-spacing: -0.06em;
|
|
80
|
+
line-height: 1.04;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.knowledge-lead,
|
|
84
|
+
.knowledge-search-header > p,
|
|
85
|
+
.knowledge-page-header > p {
|
|
86
|
+
max-width: 620px;
|
|
87
|
+
margin: 24px 0 0;
|
|
88
|
+
color: var(--cogita-knowledge-muted);
|
|
89
|
+
font-size: 18px;
|
|
90
|
+
line-height: 1.75;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.knowledge-actions {
|
|
94
|
+
display: flex;
|
|
95
|
+
flex-wrap: wrap;
|
|
96
|
+
gap: 12px;
|
|
97
|
+
margin-top: 32px;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.knowledge-actions a,
|
|
101
|
+
.knowledge-search-card a {
|
|
102
|
+
display: inline-flex;
|
|
103
|
+
align-items: center;
|
|
104
|
+
min-height: 44px;
|
|
105
|
+
padding: 0 20px;
|
|
106
|
+
border: 1px solid var(--cogita-knowledge-accent);
|
|
107
|
+
border-radius: 999px;
|
|
108
|
+
color: var(--cogita-knowledge-accent);
|
|
109
|
+
font-weight: 700;
|
|
110
|
+
text-decoration: none;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.knowledge-actions a:first-child {
|
|
114
|
+
background: var(--cogita-knowledge-accent);
|
|
115
|
+
color: #fff;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.knowledge-stats {
|
|
119
|
+
display: grid;
|
|
120
|
+
grid-template-columns: repeat(3, 1fr);
|
|
121
|
+
gap: 12px;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.knowledge-stats div {
|
|
125
|
+
display: flex;
|
|
126
|
+
flex-direction: column;
|
|
127
|
+
gap: 8px;
|
|
128
|
+
padding: 20px 0 0;
|
|
129
|
+
border-top: 2px solid var(--cogita-knowledge-accent);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.knowledge-stats strong {
|
|
133
|
+
font-size: 40px;
|
|
134
|
+
letter-spacing: -0.06em;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.knowledge-stats span,
|
|
138
|
+
.knowledge-entry-kind,
|
|
139
|
+
.knowledge-entry-card small,
|
|
140
|
+
.knowledge-search-result > span,
|
|
141
|
+
.knowledge-tag-entries span {
|
|
142
|
+
color: var(--cogita-knowledge-muted);
|
|
143
|
+
font-size: 13px;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.knowledge-grid {
|
|
147
|
+
display: grid;
|
|
148
|
+
grid-template-columns: minmax(0, 1fr) 300px;
|
|
149
|
+
gap: 48px;
|
|
150
|
+
margin-top: 64px;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.knowledge-section-heading {
|
|
154
|
+
display: flex;
|
|
155
|
+
align-items: end;
|
|
156
|
+
justify-content: space-between;
|
|
157
|
+
gap: 16px;
|
|
158
|
+
margin-bottom: 24px;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.knowledge-section-heading.compact {
|
|
162
|
+
align-items: start;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.knowledge-section-heading h2,
|
|
166
|
+
.knowledge-discovery-card h2,
|
|
167
|
+
.knowledge-related-tags h2 {
|
|
168
|
+
margin: 0;
|
|
169
|
+
font-size: 28px;
|
|
170
|
+
letter-spacing: -0.04em;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
.knowledge-section-heading > a,
|
|
174
|
+
.knowledge-page-header > a,
|
|
175
|
+
.knowledge-related-tags a {
|
|
176
|
+
color: var(--cogita-knowledge-accent);
|
|
177
|
+
font-weight: 700;
|
|
178
|
+
text-decoration: none;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
.knowledge-entry-list,
|
|
182
|
+
.knowledge-tag-entries {
|
|
183
|
+
display: grid;
|
|
184
|
+
gap: 12px;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.knowledge-entry-card,
|
|
188
|
+
.knowledge-tag-entries a {
|
|
189
|
+
display: grid;
|
|
190
|
+
grid-template-columns: 64px minmax(0, 1fr) auto;
|
|
191
|
+
gap: 12px 20px;
|
|
192
|
+
padding: 22px 0;
|
|
193
|
+
border-top: 1px solid var(--cogita-knowledge-border);
|
|
194
|
+
color: inherit;
|
|
195
|
+
text-decoration: none;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
.knowledge-entry-card:hover strong,
|
|
199
|
+
.knowledge-tag-entries a:hover strong,
|
|
200
|
+
.knowledge-search-result a:hover {
|
|
201
|
+
color: var(--cogita-knowledge-accent);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.knowledge-entry-card strong {
|
|
205
|
+
font-size: 20px;
|
|
206
|
+
line-height: 1.35;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.knowledge-entry-card p {
|
|
210
|
+
grid-column: 2 / -1;
|
|
211
|
+
margin: 0;
|
|
212
|
+
color: var(--cogita-knowledge-muted);
|
|
213
|
+
line-height: 1.6;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
.knowledge-entry-card small {
|
|
217
|
+
grid-column: 3;
|
|
218
|
+
grid-row: 1;
|
|
219
|
+
white-space: nowrap;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
.knowledge-discovery {
|
|
223
|
+
display: grid;
|
|
224
|
+
align-content: start;
|
|
225
|
+
gap: 16px;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
.knowledge-discovery-card {
|
|
229
|
+
padding: 24px;
|
|
230
|
+
border: 1px solid var(--cogita-knowledge-border);
|
|
231
|
+
border-radius: 20px;
|
|
232
|
+
background: var(--cogita-knowledge-surface);
|
|
233
|
+
box-shadow: var(--cogita-knowledge-shadow);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
.knowledge-section-heading span {
|
|
237
|
+
color: var(--cogita-knowledge-muted);
|
|
238
|
+
font-weight: 700;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
.knowledge-tag-list {
|
|
242
|
+
display: flex;
|
|
243
|
+
flex-wrap: wrap;
|
|
244
|
+
gap: 8px;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
.knowledge-tag-list a {
|
|
248
|
+
display: inline-flex;
|
|
249
|
+
align-items: center;
|
|
250
|
+
gap: 7px;
|
|
251
|
+
padding: 8px 10px;
|
|
252
|
+
border-radius: 8px;
|
|
253
|
+
background: var(--cogita-knowledge-accent-soft);
|
|
254
|
+
color: var(--cogita-knowledge-accent);
|
|
255
|
+
font-size: 13px;
|
|
256
|
+
text-decoration: none;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
.knowledge-tag-list span {
|
|
260
|
+
opacity: 0.65;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
.knowledge-search-card {
|
|
264
|
+
background: var(--cogita-knowledge-text);
|
|
265
|
+
color: #fff;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
.knowledge-search-card h2 {
|
|
269
|
+
color: #fff;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
.knowledge-search-card p {
|
|
273
|
+
color: #b9c8bf;
|
|
274
|
+
line-height: 1.6;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
.knowledge-search-card a {
|
|
278
|
+
border-color: #c5e3d0;
|
|
279
|
+
color: #d9f3e2;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/* 关系组件位于 Rspress 文档容器之外,需要独立建立与主题一致的内容宽度和层级。 */
|
|
283
|
+
.knowledge-relations {
|
|
284
|
+
display: grid;
|
|
285
|
+
grid-template-columns: minmax(220px, 0.7fr) minmax(0, 1.3fr);
|
|
286
|
+
gap: 32px;
|
|
287
|
+
max-width: 1180px;
|
|
288
|
+
margin: 64px auto 0;
|
|
289
|
+
padding: 32px 24px 72px;
|
|
290
|
+
border-top: 1px solid var(--cogita-knowledge-border);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
.knowledge-relations-heading {
|
|
294
|
+
display: flex;
|
|
295
|
+
flex-direction: column;
|
|
296
|
+
align-items: flex-start;
|
|
297
|
+
gap: 8px;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
.knowledge-relations-heading span {
|
|
301
|
+
color: var(--cogita-knowledge-accent);
|
|
302
|
+
font-size: 12px;
|
|
303
|
+
font-weight: 750;
|
|
304
|
+
letter-spacing: 0.16em;
|
|
305
|
+
text-transform: uppercase;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
.knowledge-relations-heading strong {
|
|
309
|
+
font-size: 24px;
|
|
310
|
+
letter-spacing: -0.04em;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
.knowledge-relations-groups {
|
|
314
|
+
display: grid;
|
|
315
|
+
grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
|
|
316
|
+
gap: 32px;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
.knowledge-relations-section {
|
|
320
|
+
min-width: 0;
|
|
321
|
+
padding-left: 24px;
|
|
322
|
+
border-left: 1px solid var(--cogita-knowledge-border);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
.knowledge-relations-section h3 {
|
|
326
|
+
margin: 0 0 16px;
|
|
327
|
+
color: var(--cogita-knowledge-muted);
|
|
328
|
+
font-size: 13px;
|
|
329
|
+
font-weight: 700;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
.knowledge-relations-section ul {
|
|
333
|
+
display: grid;
|
|
334
|
+
gap: 10px;
|
|
335
|
+
margin: 0;
|
|
336
|
+
padding: 0;
|
|
337
|
+
list-style: none;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
.knowledge-relations-section li {
|
|
341
|
+
display: flex;
|
|
342
|
+
align-items: baseline;
|
|
343
|
+
justify-content: space-between;
|
|
344
|
+
gap: 16px;
|
|
345
|
+
padding-bottom: 10px;
|
|
346
|
+
border-bottom: 1px solid var(--cogita-knowledge-border);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
.knowledge-relations-section li a {
|
|
350
|
+
min-width: 0;
|
|
351
|
+
overflow: hidden;
|
|
352
|
+
color: inherit;
|
|
353
|
+
font-weight: 700;
|
|
354
|
+
text-decoration: none;
|
|
355
|
+
text-overflow: ellipsis;
|
|
356
|
+
white-space: nowrap;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
.knowledge-relations-section li a:hover {
|
|
360
|
+
color: var(--cogita-knowledge-accent);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
.knowledge-relations-section li span {
|
|
364
|
+
flex: 0 0 auto;
|
|
365
|
+
color: var(--cogita-knowledge-muted);
|
|
366
|
+
font-size: 12px;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
.knowledge-search-header,
|
|
370
|
+
.knowledge-page-header {
|
|
371
|
+
padding-bottom: 48px;
|
|
372
|
+
border-bottom: 1px solid var(--cogita-knowledge-border);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
.knowledge-search-header input {
|
|
376
|
+
width: 100%;
|
|
377
|
+
max-width: 760px;
|
|
378
|
+
min-height: 58px;
|
|
379
|
+
margin-top: 32px;
|
|
380
|
+
padding: 0 18px;
|
|
381
|
+
border: 1px solid var(--cogita-knowledge-border);
|
|
382
|
+
border-radius: 12px;
|
|
383
|
+
background: var(--cogita-knowledge-surface);
|
|
384
|
+
color: inherit;
|
|
385
|
+
font: inherit;
|
|
386
|
+
box-shadow: var(--cogita-knowledge-shadow);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
.knowledge-search-results {
|
|
390
|
+
max-width: 820px;
|
|
391
|
+
padding-top: 24px;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
.knowledge-search-result {
|
|
395
|
+
padding: 26px 0;
|
|
396
|
+
border-bottom: 1px solid var(--cogita-knowledge-border);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
.knowledge-search-result h2 {
|
|
400
|
+
margin: 8px 0;
|
|
401
|
+
font-size: 24px;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
.knowledge-search-result h2 a {
|
|
405
|
+
color: inherit;
|
|
406
|
+
text-decoration: none;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
.knowledge-search-result p {
|
|
410
|
+
margin: 0;
|
|
411
|
+
color: var(--cogita-knowledge-muted);
|
|
412
|
+
line-height: 1.7;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
.knowledge-search-result div {
|
|
416
|
+
display: flex;
|
|
417
|
+
flex-wrap: wrap;
|
|
418
|
+
gap: 8px;
|
|
419
|
+
margin-top: 14px;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
.knowledge-search-result div span {
|
|
423
|
+
color: var(--cogita-knowledge-accent);
|
|
424
|
+
font-size: 13px;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
.knowledge-empty {
|
|
428
|
+
color: var(--cogita-knowledge-muted);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
.knowledge-page-header > a {
|
|
432
|
+
display: inline-block;
|
|
433
|
+
margin-bottom: 42px;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
.knowledge-all-tags {
|
|
437
|
+
display: grid;
|
|
438
|
+
grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
|
|
439
|
+
gap: 12px;
|
|
440
|
+
margin-top: 32px;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
.knowledge-all-tags a {
|
|
444
|
+
display: flex;
|
|
445
|
+
flex-direction: column;
|
|
446
|
+
gap: 8px;
|
|
447
|
+
padding: 20px;
|
|
448
|
+
border: 1px solid var(--cogita-knowledge-border);
|
|
449
|
+
border-radius: 14px;
|
|
450
|
+
background: var(--cogita-knowledge-surface);
|
|
451
|
+
color: inherit;
|
|
452
|
+
text-decoration: none;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
.knowledge-all-tags a:hover {
|
|
456
|
+
border-color: var(--cogita-knowledge-accent);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
.knowledge-all-tags span {
|
|
460
|
+
color: var(--cogita-knowledge-muted);
|
|
461
|
+
font-size: 13px;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
.knowledge-tag-entries {
|
|
465
|
+
margin-top: 32px;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
.knowledge-tag-entries a {
|
|
469
|
+
grid-template-columns: minmax(0, 1fr) auto;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
.knowledge-tag-entries span {
|
|
473
|
+
max-width: 360px;
|
|
474
|
+
text-align: right;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
.knowledge-related-tags {
|
|
478
|
+
margin-top: 56px;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
.knowledge-related-tags > div {
|
|
482
|
+
display: flex;
|
|
483
|
+
flex-wrap: wrap;
|
|
484
|
+
gap: 12px;
|
|
485
|
+
margin-top: 16px;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
@media (max-width: 760px) {
|
|
489
|
+
.knowledge-hero,
|
|
490
|
+
.knowledge-grid {
|
|
491
|
+
grid-template-columns: 1fr;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
.knowledge-grid {
|
|
495
|
+
gap: 32px;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
.knowledge-relations {
|
|
499
|
+
grid-template-columns: 1fr;
|
|
500
|
+
gap: 28px;
|
|
501
|
+
margin-top: 48px;
|
|
502
|
+
padding-top: 28px;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
.knowledge-relations-groups {
|
|
506
|
+
grid-template-columns: 1fr;
|
|
507
|
+
gap: 28px;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
.knowledge-relations-section {
|
|
511
|
+
padding: 0;
|
|
512
|
+
border-left: 0;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
.knowledge-entry-card {
|
|
516
|
+
grid-template-columns: 1fr auto;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
.knowledge-entry-kind,
|
|
520
|
+
.knowledge-entry-card p {
|
|
521
|
+
grid-column: 1 / -1;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
.knowledge-entry-card strong {
|
|
525
|
+
grid-column: 1;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
.knowledge-entry-card small {
|
|
529
|
+
grid-column: 2;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
.knowledge-tag-entries a {
|
|
533
|
+
grid-template-columns: 1fr;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
.knowledge-tag-entries span {
|
|
537
|
+
max-width: none;
|
|
538
|
+
text-align: left;
|
|
539
|
+
}
|
|
540
|
+
}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { getRouteFromPageData, normalizeSiteBase } from "@cogita/shared";
|
|
2
|
+
import { t } from "virtual-cogita-i18n-text";
|
|
3
|
+
function getBase(pageData) {
|
|
4
|
+
var _pageData_siteData;
|
|
5
|
+
return normalizeSiteBase(null == pageData ? void 0 : null == (_pageData_siteData = pageData.siteData) ? void 0 : _pageData_siteData.base);
|
|
6
|
+
}
|
|
7
|
+
function getPageRoute(pageData, base, pathname) {
|
|
8
|
+
return getRouteFromPageData(pageData, base, pathname);
|
|
9
|
+
}
|
|
10
|
+
function getHref(base, route) {
|
|
11
|
+
return `${base}${route.startsWith('/') ? route : `/${route}`}`;
|
|
12
|
+
}
|
|
13
|
+
function getKnowledgeCopy(pageData) {
|
|
14
|
+
var _pageData_siteData, _pageData_siteData1;
|
|
15
|
+
return {
|
|
16
|
+
title: (null == pageData ? void 0 : null == (_pageData_siteData = pageData.siteData) ? void 0 : _pageData_siteData.title) || 'Cogita Knowledge Base',
|
|
17
|
+
description: (null == pageData ? void 0 : null == (_pageData_siteData1 = pageData.siteData) ? void 0 : _pageData_siteData1.description) || "\u628A\u6587\u7AE0\u3001\u6587\u6863\u548C\u5B83\u4EEC\u4E4B\u95F4\u7684\u8FDE\u63A5\u7EC4\u7EC7\u6210\u53EF\u63A2\u7D22\u7684\u77E5\u8BC6\u7A7A\u95F4\u3002",
|
|
18
|
+
lead: t('knowledge.home.lead', "\u7528\u7EDF\u4E00\u5185\u5BB9\u7D22\u5F15\u8FDE\u63A5\u6587\u7AE0\u4E0E\u6587\u6863\uFF0C\u8BA9\u6BCF\u4E00\u6B21\u9605\u8BFB\u90FD\u80FD\u81EA\u7136\u62B5\u8FBE\u4E0B\u4E00\u6761\u76F8\u5173\u77E5\u8BC6\u3002")
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export { getBase, getHref, getKnowledgeCopy, getPageRoute };
|
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cogita/theme-knowledge",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Cogita 的知识库主题,组合统一内容索引、搜索、标签和内容关系。",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"cogita",
|
|
7
|
+
"theme",
|
|
8
|
+
"knowledge-base",
|
|
9
|
+
"wiki",
|
|
10
|
+
"search",
|
|
11
|
+
"backlinks"
|
|
12
|
+
],
|
|
13
|
+
"author": "wu9o <https://github.com/wu9o>",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/wu9o/cogita.git",
|
|
18
|
+
"directory": "themes/knowledge"
|
|
19
|
+
},
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/wu9o/cogita/issues"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://github.com/wu9o/cogita/tree/main/themes/knowledge#readme",
|
|
24
|
+
"type": "module",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"default": "./dist/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./package.json": "./package.json"
|
|
31
|
+
},
|
|
32
|
+
"main": "./dist/index.js",
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"README.md",
|
|
37
|
+
"ARCHITECTURE.md",
|
|
38
|
+
"LICENSE"
|
|
39
|
+
],
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=18.0.0"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
45
|
+
"react-dom": "^18.0.0 || ^19.0.0",
|
|
46
|
+
"@rspress/runtime": "^1.0.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@rslib/core": "0.11.2",
|
|
50
|
+
"@rspress/runtime": "^1.45.1",
|
|
51
|
+
"@rsbuild/plugin-react": "~1.3.5",
|
|
52
|
+
"@rsbuild/plugin-sass": "~1.3.5",
|
|
53
|
+
"@rsbuild/plugin-svgr": "^1.2.2",
|
|
54
|
+
"@types/react": "^19.1.9",
|
|
55
|
+
"@types/react-dom": "^19.1.7",
|
|
56
|
+
"react": "^19.1.1",
|
|
57
|
+
"react-dom": "^19.1.1",
|
|
58
|
+
"rsbuild-plugin-publint": "^0.3.3",
|
|
59
|
+
"typescript": "^5.0.4",
|
|
60
|
+
"@cogita/config": "0.0.0",
|
|
61
|
+
"@cogita/shared": "0.13.0"
|
|
62
|
+
},
|
|
63
|
+
"dependencies": {
|
|
64
|
+
"@cogita/plugin-content-check": "0.2.5",
|
|
65
|
+
"@cogita/plugin-content-relations": "0.2.1",
|
|
66
|
+
"@cogita/plugin-i18n": "0.2.0",
|
|
67
|
+
"@cogita/plugin-posts-frontmatter": "0.1.6",
|
|
68
|
+
"@cogita/plugin-search": "0.2.7",
|
|
69
|
+
"@cogita/plugin-tags": "1.0.7",
|
|
70
|
+
"@cogita/shared": "0.13.0"
|
|
71
|
+
},
|
|
72
|
+
"scripts": {
|
|
73
|
+
"build": "rslib build",
|
|
74
|
+
"dev": "rslib build -w"
|
|
75
|
+
}
|
|
76
|
+
}
|