Skip to content

Commit e113f68

Browse files
authored
feat(theme): improve post draft status (#662)
1 parent fde9351 commit e113f68

11 files changed

Lines changed: 45 additions & 17 deletions

File tree

docs/demos.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ permalink: /demos/
55
readingTime: false
66
prev: false
77
next: false
8-
draft: true
8+
article: false
99
externalLinkIcon: false
1010
contributors: false
1111
changelog: false

docs/friends.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pageLayout: friends
33
title: 友情链接
44
description: 这里是友情链接的描述文字,此页面仅作为示例展示
55
permalink: /friends/
6-
draft: true
6+
article: true
77
list:
88
-
99
name: pengzhanbo

docs/notes/theme/config/frontmatter/post.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,19 @@ tags:
3030

3131
如果为 `number` ,则数字越大,文章置顶的位置越靠前。
3232

33-
### article <Badge type="warning" text="弃用" />
33+
### article
3434

3535
- 类型: `boolean`
3636
- 默认值: `true`
3737

38-
是否在文章列表中,显示当前文章。
39-
40-
由于该字段 表达的语义不明,已弃用,改为使用 `draft`
38+
是否在文章列表中显示当前文章。
4139

4240
### draft
4341

4442
- 类型: `boolean`
4543
- 默认值: `false`
4644

47-
标记文章是否为草稿。被标记为草稿的文章,不会出现在 博客文章列表页中
45+
标记文章是否为草稿。被标记为草稿的文章,仅在 **开发环境时显示在文章列表中**,生产环境不会显示
4846

4947
### tags
5048

docs/questions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: 常见问题
33
createTime: 2024/09/27 08:47:36
44
permalink: /faq/
5-
draft: true
5+
article: false
66
---
77

88
本文主要包含了使用主题的过程中可能会遇到的常见问题与解决方法。

docs/sponsor.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: 喝杯奶茶
33
createTime: 2024/04/18 18:03:50
44
permalink: /sponsor/
5-
draft: true
5+
article: false
66
aside: false
77
readingTime: false
88
contributors: false

theme/src/client/components/Blog/VPPostItem.vue

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const coverStyles = computed(() => {
9797
<template>
9898
<div
9999
class="vp-blog-post-item" data-allow-mismatch
100-
:class="{ 'has-cover': post.cover, [coverLayout]: cover }"
100+
:class="{ 'has-cover': post.cover, [coverLayout]: cover, 'draft': post.draft }"
101101
>
102102
<div
103103
v-if="post.cover" class="post-cover" data-allow-mismatch
@@ -108,6 +108,7 @@ const coverStyles = computed(() => {
108108
<div class="blog-post-item-content">
109109
<h3>
110110
<span v-if="sticky" class="sticky">TOP</span>
111+
<span v-if="post.draft" class="draft">DRAFT</span>
111112
<span v-if="post.encrypt" class="icon-lock vpi-lock" />
112113
<VPLink :href="post.path" :text="post.title" />
113114
</h3>
@@ -151,6 +152,10 @@ const coverStyles = computed(() => {
151152
transition: background-color var(--vp-t-color);
152153
}
153154
155+
.vp-blog-post-item.draft {
156+
background-color: var(--vp-c-warning-soft);
157+
}
158+
154159
.vp-blog-post-item.has-cover:where(.left, .right) {
155160
display: flex;
156161
gap: 20px;
@@ -231,7 +236,8 @@ const coverStyles = computed(() => {
231236
flex: 1 2;
232237
}
233238
234-
.blog-post-item-content .sticky {
239+
.blog-post-item-content .sticky,
240+
.blog-post-item-content .draft {
235241
display: inline-block;
236242
padding: 3px 6px;
237243
margin-right: 0.5rem;
@@ -245,6 +251,11 @@ const coverStyles = computed(() => {
245251
transition-property: color, background-color;
246252
}
247253
254+
.blog-post-item-content .draft {
255+
color: var(--vp-c-warning-1);
256+
background-color: var(--vp-c-warning-soft);
257+
}
258+
248259
.blog-post-item-content .icon-lock {
249260
width: 1em;
250261
height: 1em;

theme/src/client/components/VPDocMeta.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const hasMeta = computed(() =>
5454

5555
<template>
5656
<h1 class="vp-doc-title page-title" :class="{ padding: !hasMeta }">
57+
<VPBadge v-if="page.frontmatter.draft" type="warning" text="DRAFT" />
5758
{{ page.title }}
5859
<VPBadge v-if="badge" :type="badge.type || 'tip'" :text="badge.text" />
5960
</h1>

theme/src/node/pages/extendsPage.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ function cleanPageData(page: Page<ThemePageData>) {
3030
delete page.frontmatter.home
3131
}
3232

33-
if (page.frontmatter.article === false) {
34-
page.frontmatter.draft = true
35-
}
36-
delete page.frontmatter.article
33+
// if (page.frontmatter.article === false) {
34+
// page.frontmatter.draft = true
35+
// }
36+
// delete page.frontmatter.article
3737

3838
if (page.headers) {
3939
page.data.headers = []

theme/src/node/prepare/prepareBlogData.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function getTimestamp(time: Date): number {
2121
}
2222

2323
export async function preparedBlogData(app: App): Promise<void> {
24+
const isBuild = app.env.isBuild
2425
const options = getThemeConfig()
2526
const encrypt = options.encrypt
2627
if (options.blog === false) {
@@ -52,7 +53,8 @@ export async function preparedBlogData(app: App): Promise<void> {
5253
const pages = app.pages.filter(page =>
5354
page.filePathRelative
5455
&& filter(page.filePathRelative)
55-
&& page.frontmatter.draft !== true,
56+
&& page.frontmatter.article !== false
57+
&& (page.frontmatter.draft === true ? !isBuild : true),
5658
).sort((prev, next) =>
5759
getTimestamp((prev.frontmatter.createTime as Date) || prev.date)
5860
< getTimestamp(next.frontmatter.createTime as Date || next.date)
@@ -83,6 +85,10 @@ export async function preparedBlogData(app: App): Promise<void> {
8385
data.encrypt = true
8486
}
8587

88+
if (page.frontmatter.draft && !isBuild) {
89+
data.draft = true
90+
}
91+
8692
const fmExcerpt = page.frontmatter.excerpt
8793
if (fmExcerpt !== false) {
8894
if (typeof fmExcerpt === 'string') {

theme/src/shared/features/blog.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ export interface ThemeBlogPostItem {
9595
* 文章封面图样式
9696
*/
9797
coverStyle?: BlogPostCoverStyle
98+
99+
/**
100+
* 文章是否为草稿
101+
*/
102+
draft?: boolean
98103
}
99104

100105
/**

0 commit comments

Comments
 (0)