Skip to content

Commit 07b1b64

Browse files
authored
Merge pull request #31 from devlive-community/dev
支持设置页面状态
2 parents c5af41b + 78c7fce commit 07b1b64

File tree

7 files changed

+168
-31
lines changed

7 files changed

+168
-31
lines changed

docs/content/setup/page.md

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
title: 页面设置
33
icon: book-open
4+
status:
5+
type: updated
46
---
57

68
PageForge 的材料包含许多强大的功能,使技术写作成为一项令人愉快的活动。文档的这一部分解释了如何设置页面,并展示了所有可以直接在 PageForge 文件中使用的可用样本。
@@ -26,6 +28,18 @@ icon: feather
2628

2729
生成的标题为 `page.title - site.title` 的格式。
2830

31+
### 设置 `description`
32+
33+
---
34+
35+
PageForge 支持设置当前页面的描述,格式如下:
36+
37+
```markdown
38+
---
39+
description: 这里是描述
40+
---
41+
```
42+
2943
### 设置 `icon`
3044

3145
---
@@ -112,4 +126,52 @@ config:
112126
---
113127
template: foo
114128
---
115-
```
129+
```
130+
131+
### 设置 `status`
132+
133+
---
134+
135+
PageForge 支持设置当前页面的状态,当前支持以下状态:
136+
137+
- `draft`: 草稿
138+
- `new`: 新添加
139+
- `updated`: 更新
140+
- `deprecated`: 已过期
141+
- `custom`: 自定义
142+
143+
通过配置 markdown 文件的元数据来支持,格式如下:
144+
145+
```markdown
146+
---
147+
status:
148+
type: updated
149+
---
150+
```
151+
152+
如果需要设置自定义提示的内容,可以修改为以下方式:
153+
154+
```markdown
155+
---
156+
status:
157+
type: updated
158+
text: 自定义提示
159+
---
160+
```
161+
162+
PageForge 还支持自定义状态,格式如下:
163+
164+
```markdown
165+
---
166+
status:
167+
type: custom
168+
icon: feather
169+
text: 自定义提示
170+
---
171+
```
172+
173+
!!! danger "注意"
174+
175+
自定义状态情况下如果 `feature.lucide.enable` 为 `true` 时,`icon` 将使用 Lucide 图标。否则需要传递自定义图标,比如完整的 svg。
176+
177+
!!!

templates/includes/footer.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<%= locals.siteData?.footer?.copyright %> 使用 ❤️ <a href="https://pageforge.devlive.org" class="hover:text-blue-600" target="_blank">PageForge</a> 构建
5757
5858
<% if (locals.siteData?.feature?.sitemap?.enable) { %>
59-
<a href="/sitemap.xml" target="_blank" class="ml-3 dark:hover:text-white hover:underline hover:text-blue-600">站点地图</a>
59+
<a href="<%= locals.siteData?.site?.baseUrl %>/sitemap.xml" target="_blank" class="ml-3 dark:hover:text-white hover:underline hover:text-blue-600">站点地图</a>
6060
<% } %>
6161
</span>
6262

templates/includes/page-edit.ejs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<% if (locals.siteData.feature?.edit?.enable) { %>
2+
<a href="<%= `${locals.siteData?.repo?.url}/edit/${locals.siteData?.repo?.branch || 'main'}/docs/content/${pageData.relativePath}` %>"
3+
target="_blank"
4+
rel="noopener noreferrer"
5+
class="text-gray-400 hover:text-blue-700 dark:text-gray-400 dark:hover:text-gray-300">
6+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
7+
stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-edit w-4 h-4">
8+
<path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/>
9+
<path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
10+
</svg>
11+
</a>
12+
<% } %>

templates/includes/page-source.ejs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<% if (locals.siteData.feature?.view?.enable) { %>
2+
<a href="<%= `${locals.siteData?.repo?.url}/blob/${locals.siteData?.repo?.branch || 'main'}/docs/content/${pageData.relativePath}` %>"
3+
target="_blank"
4+
rel="noopener noreferrer"
5+
class="text-gray-400 hover:text-blue-700 dark:text-gray-400 dark:hover:text-gray-300">
6+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
7+
stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-code w-4 h-4">
8+
<polyline points="16 18 22 12 16 6"/>
9+
<polyline points="8 6 2 12 8 18"/>
10+
</svg>
11+
</a>
12+
<% } %>

templates/includes/page-status.ejs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<%
2+
const getDefaultText = (type) => {
3+
switch (type) {
4+
case 'draft':
5+
return '草稿';
6+
case 'new':
7+
return '新添加';
8+
case 'deprecated':
9+
return '已过期';
10+
case 'updated':
11+
return '已更新';
12+
case 'custom':
13+
return '自定义';
14+
default:
15+
return '';
16+
}
17+
}
18+
19+
// 添加默认图标的渲染函数
20+
const renderDefaultIcon = (type) => {
21+
switch (type) {
22+
case 'draft':
23+
return `<svg class="w-4 h-4 text-gray-500 hover:opacity-80 cursor-pointer peer" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
24+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" />
25+
</svg>`;
26+
case 'new':
27+
return `<svg class="w-4 h-4 text-green-500 hover:opacity-80 cursor-pointer peer" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
28+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v3m0 0v3m0-3h3m-3 0H9m12 0a9 9 0 11-18 0 9 9 0 0118 0z" />
29+
</svg>`;
30+
case 'deprecated':
31+
return `<svg class="w-4 h-4 text-red-500 hover:opacity-80 cursor-pointer peer" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
32+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
33+
</svg>`;
34+
case 'updated':
35+
return `<svg class="w-4 h-4 text-blue-500 hover:opacity-80 cursor-pointer peer" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
36+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" />
37+
</svg>`;
38+
default:
39+
return '';
40+
}
41+
}
42+
%>
43+
44+
<% if (item.status?.type) { %>
45+
<div class="inline-flex items-center">
46+
<div class="relative">
47+
<% if (item.status.type === 'custom') { %>
48+
<% if (locals.siteData.feature?.lucide?.enable && item.status.icon) { %>
49+
<!-- Lucide 图标 -->
50+
<i data-lucide="<%= item.status.icon %>" class="w-4 h-4 text-gray-600 hover:opacity-80 cursor-pointer peer"></i>
51+
<% } else if (item.status.icon && item.status.icon.includes('<svg')) { %>
52+
<!-- 自定义 SVG 图标 -->
53+
<span class="inline-block w-4 h-4 hover:opacity-80 cursor-pointer peer">
54+
<%- item.status.icon %>
55+
</span>
56+
<% } else { %>
57+
<!-- 默认图标,当没有提供有效的图标时 -->
58+
<svg class="w-4 h-4 text-gray-500 hover:opacity-80 cursor-pointer peer" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
59+
stroke="currentColor">
60+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
61+
</svg>
62+
<% } %>
63+
<% } else { %>
64+
<%- renderDefaultIcon(item.status.type) %>
65+
<% } %>
66+
67+
<span class="absolute left-1/2 -translate-x-1/2 -top-8 px-2 py-1 bg-gray-900 text-white text-xs rounded scale-0 peer-hover:scale-100 transition-transform duration-100 origin-bottom pointer-events-none">
68+
<%= item.status.text || getDefaultText(item.status.type) %>
69+
</span>
70+
</div>
71+
</div>
72+
<% } %>

templates/includes/page-title.ejs

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,14 @@
99
<%- include('./page-share') %>
1010
1111
<!-- 编辑源码 -->
12-
<% if (locals.siteData.feature?.edit?.enable) { %>
13-
<a href="<%= `${locals.siteData?.repo?.url}/edit/${locals.siteData?.repo?.branch || 'main'}/docs/content/${pageData.relativePath}` %>"
14-
target="_blank"
15-
rel="noopener noreferrer"
16-
class="text-gray-400 hover:text-blue-700 dark:text-gray-400 dark:hover:text-gray-300">
17-
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
18-
stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-edit w-4 h-4">
19-
<path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/>
20-
<path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
21-
</svg>
22-
</a>
23-
<% } %>
12+
<%- include('./page-edit') %>
2413
2514
<!-- 查看源码 -->
26-
<% if (locals.siteData.feature?.view?.enable) { %>
27-
<a href="<%= `${locals.siteData?.repo?.url}/blob/${locals.siteData?.repo?.branch || 'main'}/docs/content/${pageData.relativePath}` %>"
28-
target="_blank"
29-
rel="noopener noreferrer"
30-
class="text-gray-400 hover:text-blue-700 dark:text-gray-400 dark:hover:text-gray-300">
31-
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
32-
stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-code w-4 h-4">
33-
<polyline points="16 18 22 12 16 6"/>
34-
<polyline points="8 6 2 12 8 18"/>
35-
</svg>
36-
</a>
37-
<% } %>
15+
<%- include('./page-source') %>
3816
</div>
3917
</div>
4018
<% if (pageData.description) { %>
41-
<p class="mt-4 text-lg text-gray-600 dark:text-gray-400">
19+
<p class="mt-6 text-sm sm:text-base leading-6 text-gray-500 dark:text-gray-400 border-l-4 border-gray-200 dark:border-gray-700 pl-4 py-1 italic">
4220
<%- pageData.description %>
4321
</p>
4422
<% } %>

templates/includes/sidebar.ejs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ sidebar = siteData.nav.find(item => {
4545
<!-- 骨架屏 -->
4646
<div class="w-3 h-3 sm:w-4 sm:h-4 animate-pulse bg-gray-200 dark:bg-gray-700 rounded"></div>
4747
48-
<!-- 图标 -->
48+
<!-- 图标 -->
4949
<i data-lucide="<%= item.icon %>"
5050
style="display: none;"
5151
class="w-3 h-3 sm:w-4 sm:h-4
@@ -57,9 +57,10 @@ sidebar = siteData.nav.find(item => {
5757
</span>
5858
<% } %>
5959
60-
<span class="flex-grow <%= level > 0 ? 'text-xs sm:text-sm md:text-base' : 'text-sm sm:text-base' %> whitespace-nowrap">
61-
<%= item.title %>
62-
</span>
60+
<span class="flex flex-grow items-center space-x-4 <%= level > 0 ? 'text-xs sm:text-sm md:text-base' : 'text-sm sm:text-base' %> whitespace-nowrap">
61+
<span><%= item.title %></span>
62+
<%- include('./page-status', { item: item }) %>
63+
</span>
6364
6465
<% if (item.items && item.items.length > 0) { %>
6566
<svg xmlns="http://www.w3.org/2000/svg"

0 commit comments

Comments
 (0)