@sugarat/theme 0.4.12 → 0.5.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/node.d.ts +16 -74
- package/node.js +148 -51
- package/node.mjs +753 -0
- package/package.json +10 -6
- package/src/components/BlogAlert.vue +10 -9
- package/src/components/BlogApp.vue +0 -2
- package/src/components/BlogArticleAnalyze.vue +8 -9
- package/src/components/BlogAuthor.vue +6 -5
- package/src/components/BlogBackToTop.vue +8 -10
- package/src/components/BlogButtonAfterArticle.vue +5 -14
- package/src/components/BlogCommentWrapper.vue +11 -28
- package/src/components/BlogDocCover.vue +3 -3
- package/src/components/BlogFooter.vue +3 -1
- package/src/components/BlogFriendLink.vue +4 -3
- package/src/components/BlogHomeBanner.vue +7 -6
- package/src/components/BlogHomeHeaderAvatar.vue +3 -3
- package/src/components/BlogHomeOverview.vue +3 -3
- package/src/components/BlogHomeTags.vue +5 -5
- package/src/components/BlogHotArticle.vue +4 -7
- package/src/components/BlogItem.vue +1 -1
- package/src/components/BlogList.vue +7 -6
- package/src/components/BlogRecommendArticle.vue +11 -14
- package/src/components/BlogSidebar.vue +9 -15
- package/src/components/CommentArtalk.vue +7 -5
- package/src/components/CommentGiscus.vue +7 -8
- package/src/components/Icon.vue +33 -0
- package/src/composables/config/blog.ts +203 -87
- package/src/composables/config/index.ts +12 -79
- package/src/hooks/useOml2d.ts +15 -8
- package/src/index.ts +3 -0
- package/src/node.ts +5 -1
- package/src/styles/index.scss +6 -6
- package/src/utils/node/hot-reload-plugin.ts +31 -1
- package/src/utils/node/index.ts +0 -2
- package/src/utils/node/mdPlugins.ts +4 -0
- package/src/utils/node/theme.ts +15 -18
- package/src/utils/node/vitePlugins.ts +122 -33
- package/src/components/BlogPopover.vue +0 -290
|
@@ -3,27 +3,21 @@ import { computed, onMounted, ref } from 'vue'
|
|
|
3
3
|
import { useRoute, useRouter, withBase } from 'vitepress'
|
|
4
4
|
import { ElButton } from 'element-plus'
|
|
5
5
|
import { wrapperCleanUrls } from '../utils/client'
|
|
6
|
-
import { useArticles,
|
|
6
|
+
import { useArticles, useCleanUrls, useFormatShowDate, useRecommendConfig, useShowRecommend } from '../composables/config/blog'
|
|
7
7
|
import { recommendSVG } from '../constants/svg'
|
|
8
8
|
import type { Theme } from '../composables/config/index'
|
|
9
9
|
|
|
10
10
|
const formatShowDate = useFormatShowDate()
|
|
11
11
|
|
|
12
|
-
const
|
|
12
|
+
const recommend = useRecommendConfig()
|
|
13
|
+
const show = useShowRecommend()
|
|
13
14
|
|
|
14
15
|
const sidebarStyle = computed(() =>
|
|
15
|
-
|
|
16
|
+
recommend.value?.style ?? 'sidebar'
|
|
16
17
|
)
|
|
17
18
|
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
)
|
|
21
|
-
const recommend = computed(() =>
|
|
22
|
-
_recommend === false ? undefined : _recommend
|
|
23
|
-
)
|
|
24
|
-
|
|
25
|
-
const showDate = computed(() => (_recommend && _recommend?.showDate) ?? true)
|
|
26
|
-
const showNum = computed(() => (_recommend && _recommend?.showNum) ?? true)
|
|
19
|
+
const showDate = computed(() => recommend.value?.showDate ?? true)
|
|
20
|
+
const showNum = computed(() => recommend.value?.showNum ?? true)
|
|
27
21
|
|
|
28
22
|
const title = computed(() => recommend.value?.title ?? (`<span class="svg-icon">${recommendSVG}</span>` + '相关文章'))
|
|
29
23
|
const pageSize = computed(() => recommend.value?.pageSize || 9)
|
|
@@ -162,7 +156,7 @@ function handleLinkClick(link: string) {
|
|
|
162
156
|
|
|
163
157
|
<template>
|
|
164
158
|
<div
|
|
165
|
-
v-if="
|
|
159
|
+
v-if="show && (recommendList.length || emptyText)" class="recommend"
|
|
166
160
|
:class="{ card: sidebarStyle === 'card' }" data-pagefind-ignore="all"
|
|
167
161
|
>
|
|
168
162
|
<!-- 头部 -->
|
|
@@ -233,7 +227,10 @@ function handleLinkClick(link: string) {
|
|
|
233
227
|
|
|
234
228
|
.recommend {
|
|
235
229
|
flex-direction: column;
|
|
236
|
-
padding:
|
|
230
|
+
padding: 0px;
|
|
231
|
+
}
|
|
232
|
+
.recommend.card{
|
|
233
|
+
padding: 10px;
|
|
237
234
|
}
|
|
238
235
|
|
|
239
236
|
.recommend-container {
|
|
@@ -1,35 +1,29 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import { computed } from 'vue'
|
|
3
|
-
import {
|
|
3
|
+
import { useRecommendConfig, useShowRecommend } from '../composables/config/blog'
|
|
4
4
|
import BlogRecommendArticle from './BlogRecommendArticle.vue'
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
|
|
6
|
+
const recommend = useRecommendConfig()
|
|
7
|
+
const show = useShowRecommend()
|
|
8
8
|
const sidebarStyle = computed(() =>
|
|
9
|
-
|
|
10
|
-
)
|
|
11
|
-
const marginTop = computed(() =>
|
|
12
|
-
sidebarStyle.value === 'card' ? '40px' : '0px'
|
|
13
|
-
)
|
|
14
|
-
const marginTopMini = computed(() =>
|
|
15
|
-
sidebarStyle.value === 'card' ? '60px' : '0px'
|
|
9
|
+
recommend.value?.style || 'sidebar'
|
|
16
10
|
)
|
|
17
11
|
</script>
|
|
18
12
|
|
|
19
13
|
<template>
|
|
20
|
-
<div v-if="
|
|
14
|
+
<div v-if="show" class="sidebar" :class="{ card: sidebarStyle === 'card' }" data-pagefind-ignore="all">
|
|
21
15
|
<BlogRecommendArticle />
|
|
22
16
|
</div>
|
|
23
17
|
</template>
|
|
24
18
|
|
|
25
19
|
<style lang="scss" scoped>
|
|
26
|
-
.sidebar {
|
|
27
|
-
margin-top:
|
|
20
|
+
.sidebar.card {
|
|
21
|
+
margin-top: 40px;
|
|
28
22
|
}
|
|
29
23
|
|
|
30
24
|
@media screen and (min-width: 960px) and (max-width: 1120px) {
|
|
31
|
-
.sidebar {
|
|
32
|
-
margin-top:
|
|
25
|
+
.sidebar.card {
|
|
26
|
+
margin-top: 60px;
|
|
33
27
|
}
|
|
34
28
|
}
|
|
35
29
|
</style>
|
|
@@ -3,7 +3,7 @@ import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
|
|
|
3
3
|
import { useData, useRoute } from 'vitepress'
|
|
4
4
|
import type Artalk from 'artalk'
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { useCommentConfig, useOpenCommentConfig } from '../composables/config/blog'
|
|
7
7
|
|
|
8
8
|
const { isDark, page } = useData()
|
|
9
9
|
const el = ref<HTMLDivElement>()
|
|
@@ -12,14 +12,16 @@ const route = useRoute()
|
|
|
12
12
|
|
|
13
13
|
const artalk = ref<Artalk>()
|
|
14
14
|
|
|
15
|
-
const
|
|
15
|
+
const comment = useCommentConfig()
|
|
16
|
+
|
|
16
17
|
const commentConfig = computed(() => {
|
|
17
|
-
if (comment && 'type' in comment && comment.type === 'artalk') {
|
|
18
|
-
return comment.options
|
|
18
|
+
if (comment.value && 'type' in comment.value && comment.value?.type === 'artalk') {
|
|
19
|
+
return comment.value.options
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
return false
|
|
22
23
|
})
|
|
24
|
+
const open = useOpenCommentConfig()
|
|
23
25
|
|
|
24
26
|
onMounted(() => {
|
|
25
27
|
// CDN 异步加载,有优化空间
|
|
@@ -64,7 +66,7 @@ watch(isDark, () => {
|
|
|
64
66
|
</script>
|
|
65
67
|
|
|
66
68
|
<template>
|
|
67
|
-
<div v-if="
|
|
69
|
+
<div v-if="open" ref="el" class="artalk-container" />
|
|
68
70
|
</template>
|
|
69
71
|
|
|
70
72
|
<style lang="scss" scoped>
|
|
@@ -2,19 +2,18 @@
|
|
|
2
2
|
import { useData, useRoute } from 'vitepress'
|
|
3
3
|
import { computed, nextTick, ref, watch } from 'vue'
|
|
4
4
|
import Giscus from '@giscus/vue'
|
|
5
|
-
import {
|
|
5
|
+
import { useCommentConfig } from '../composables/config/blog'
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
const { comment } = useBlogConfig()
|
|
7
|
+
const comment = useCommentConfig()
|
|
9
8
|
const commentConfig = computed(() => {
|
|
10
|
-
if (!comment) {
|
|
9
|
+
if (!comment.value) {
|
|
11
10
|
return false
|
|
12
11
|
}
|
|
13
|
-
if ('type' in comment && comment.type === 'giscus') {
|
|
14
|
-
return comment.options
|
|
12
|
+
if ('type' in comment.value && comment.value?.type === 'giscus') {
|
|
13
|
+
return comment.value.options
|
|
15
14
|
}
|
|
16
|
-
else if (!('type' in comment)) {
|
|
17
|
-
return comment
|
|
15
|
+
else if (!('type' in comment.value)) {
|
|
16
|
+
return comment.value
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
return false
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { computed } from 'vue'
|
|
3
|
+
|
|
4
|
+
const props = defineProps<{
|
|
5
|
+
size?: string | number
|
|
6
|
+
icon?: string
|
|
7
|
+
}>()
|
|
8
|
+
|
|
9
|
+
const size = computed(() => props.size && (typeof props.size === 'number' ? `${props.size}px` : props.size))
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<template>
|
|
13
|
+
<i v-if="props.icon" class="sugar-theme-icon" :style="{ fontSize: size }" v-html="props.icon" />
|
|
14
|
+
<i v-else class="sugar-theme-icon" :style="{ fontSize: size }">
|
|
15
|
+
<slot />
|
|
16
|
+
</i>
|
|
17
|
+
</template>
|
|
18
|
+
|
|
19
|
+
<style lang="css" scoped>
|
|
20
|
+
.sugar-theme-icon {
|
|
21
|
+
--color: inherit;
|
|
22
|
+
align-items: center;
|
|
23
|
+
display: inline-flex;
|
|
24
|
+
height: 1em;
|
|
25
|
+
justify-content: center;
|
|
26
|
+
line-height: 1em;
|
|
27
|
+
position: relative;
|
|
28
|
+
width: 1em;
|
|
29
|
+
fill: currentColor;
|
|
30
|
+
color: var(--color);
|
|
31
|
+
font-size: inherit;
|
|
32
|
+
}
|
|
33
|
+
</style>
|
|
@@ -14,7 +14,8 @@ import {
|
|
|
14
14
|
onUnmounted,
|
|
15
15
|
provide,
|
|
16
16
|
reactive,
|
|
17
|
-
ref
|
|
17
|
+
ref,
|
|
18
|
+
watch,
|
|
18
19
|
} from 'vue'
|
|
19
20
|
import { useColorMode } from '@vueuse/core'
|
|
20
21
|
|
|
@@ -27,28 +28,14 @@ const activeTagSymbol: InjectionKey<Ref<Theme.activeTag>> = Symbol('active-tag')
|
|
|
27
28
|
|
|
28
29
|
const currentPageNum: InjectionKey<Ref<number>> = Symbol('home-page-num')
|
|
29
30
|
|
|
30
|
-
const userWorks: InjectionKey<Ref<Theme.UserWorks>> = Symbol('user-works')
|
|
31
|
-
|
|
32
|
-
const homeFooter: InjectionKey<Theme.Footer | Theme.Footer[] | undefined> = Symbol('home-footer')
|
|
33
|
-
|
|
34
31
|
export function withConfigProvider(App: Component) {
|
|
35
32
|
return defineComponent({
|
|
36
33
|
name: 'ConfigProvider',
|
|
37
34
|
setup(_, { slots }) {
|
|
38
|
-
const { theme } = useData()
|
|
39
|
-
const config = computed(() => resolveConfig(theme.value))
|
|
40
|
-
|
|
35
|
+
const { theme, localeIndex } = useData()
|
|
36
|
+
const config = computed(() => resolveConfig(theme.value, localeIndex.value))
|
|
37
|
+
|
|
41
38
|
provide(configSymbol, config)
|
|
42
|
-
provide(
|
|
43
|
-
userWorks,
|
|
44
|
-
ref(
|
|
45
|
-
config.value.blog?.works || {
|
|
46
|
-
title: '',
|
|
47
|
-
description: '',
|
|
48
|
-
list: []
|
|
49
|
-
}
|
|
50
|
-
)
|
|
51
|
-
)
|
|
52
39
|
|
|
53
40
|
const activeTag = ref<Theme.activeTag>({
|
|
54
41
|
label: '',
|
|
@@ -73,37 +60,122 @@ export function withConfigProvider(App: Component) {
|
|
|
73
60
|
'el-red': 'el-red'
|
|
74
61
|
}
|
|
75
62
|
})
|
|
76
|
-
|
|
63
|
+
watch(config, () => {
|
|
64
|
+
mode.value = config.value.blog?.themeColor ?? 'vp-default'
|
|
65
|
+
}, {
|
|
66
|
+
immediate: true
|
|
67
|
+
})
|
|
68
|
+
|
|
77
69
|
return () => h(App, null, slots)
|
|
78
70
|
}
|
|
79
71
|
})
|
|
80
72
|
}
|
|
73
|
+
|
|
74
|
+
export function useGlobalAuthor() {
|
|
75
|
+
const blogConfig = useBlogConfig()
|
|
76
|
+
return computed(() => blogConfig.value?.author || '')
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function useArticleConfig() {
|
|
80
|
+
const blogConfig = useBlogConfig()
|
|
81
|
+
return computed(() => blogConfig.value?.article)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function useAuthorList() {
|
|
85
|
+
const blogConfig = useBlogConfig()
|
|
86
|
+
return computed(() => blogConfig.value?.authorList)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function useHotArticleConfig() {
|
|
90
|
+
const blogConfig = useBlogConfig()
|
|
91
|
+
return computed(() => {
|
|
92
|
+
const cfg = blogConfig.value?.hotArticle
|
|
93
|
+
return cfg === false ? undefined : cfg
|
|
94
|
+
})
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function useShowHotArticle() {
|
|
98
|
+
const blogConfig = useBlogConfig()
|
|
99
|
+
return computed(() => {
|
|
100
|
+
const cfg = blogConfig.value?.hotArticle
|
|
101
|
+
return cfg !== false
|
|
102
|
+
})
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function useRecommendConfig() {
|
|
106
|
+
const blogConfig = useBlogConfig()
|
|
107
|
+
return computed(() => {
|
|
108
|
+
const cfg = blogConfig.value?.recommend
|
|
109
|
+
return cfg === false ? undefined : cfg
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function useShowRecommend() {
|
|
114
|
+
const blogConfig = useBlogConfig()
|
|
115
|
+
return computed(() => {
|
|
116
|
+
const cfg = blogConfig.value?.recommend
|
|
117
|
+
return cfg !== false
|
|
118
|
+
})
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function useAlertConfig() {
|
|
122
|
+
const blogConfig = useBlogConfig()
|
|
123
|
+
return computed(() => blogConfig.value?.alert)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function useHomeConfig() {
|
|
127
|
+
const blogConfig = useBlogConfig()
|
|
128
|
+
return computed(() => blogConfig.value?.home)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function useHomeTagsConfig() {
|
|
132
|
+
const blogConfig = useBlogConfig()
|
|
133
|
+
return computed(() => blogConfig.value?.homeTags)
|
|
134
|
+
}
|
|
135
|
+
|
|
81
136
|
export function useDocMetaInsertSelector() {
|
|
82
137
|
const blogConfig = useConfig()
|
|
83
138
|
const { frontmatter } = useData()
|
|
84
|
-
return computed(() => frontmatter.value?.docMetaInsertSelector || blogConfig
|
|
139
|
+
return computed(() => frontmatter.value?.docMetaInsertSelector || blogConfig?.value?.blog?.docMetaInsertSelector || 'h1')
|
|
85
140
|
}
|
|
86
141
|
|
|
87
142
|
export function useDocMetaInsertPosition() {
|
|
88
143
|
const blogConfig = useConfig()
|
|
89
144
|
const { frontmatter } = useData()
|
|
90
|
-
return computed(() => frontmatter.value?.docMetaInsertPosition || blogConfig
|
|
145
|
+
return computed(() => frontmatter.value?.docMetaInsertPosition || blogConfig?.value?.blog?.docMetaInsertPosition || 'after')
|
|
91
146
|
}
|
|
92
147
|
|
|
93
148
|
export function useConfig() {
|
|
94
|
-
return
|
|
95
|
-
config: inject(configSymbol)!.value
|
|
96
|
-
}
|
|
149
|
+
return inject(configSymbol)
|
|
97
150
|
}
|
|
98
151
|
|
|
99
152
|
export function useBlogConfig() {
|
|
100
|
-
|
|
153
|
+
const resolveConfig = useConfig()
|
|
154
|
+
return computed(() => resolveConfig?.value?.blog)
|
|
101
155
|
}
|
|
156
|
+
|
|
157
|
+
export function useButtonAfterConfig() {
|
|
158
|
+
const blogConfig = useBlogConfig()
|
|
159
|
+
const { frontmatter } = useData()
|
|
160
|
+
const frontmatterConfig = computed(() => frontmatter.value.buttonAfterArticle)
|
|
161
|
+
|
|
162
|
+
const buttonAfterArticleConfig = computed<Theme.ButtonAfterArticleConfig | false>(() => {
|
|
163
|
+
if (frontmatterConfig.value === false || (!frontmatterConfig.value && !blogConfig.value?.buttonAfterArticle)) {
|
|
164
|
+
return false
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return { ...blogConfig.value?.buttonAfterArticle, ...frontmatterConfig.value }
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
return buttonAfterArticleConfig
|
|
171
|
+
}
|
|
172
|
+
|
|
102
173
|
/**
|
|
103
174
|
* 获取 oh-my-live2d的配置选项
|
|
104
175
|
*/
|
|
105
176
|
export function useOml2dOptions() {
|
|
106
|
-
|
|
177
|
+
const blogConfig = useBlogConfig()
|
|
178
|
+
return computed(() => blogConfig.value?.oml2d)
|
|
107
179
|
}
|
|
108
180
|
|
|
109
181
|
export function useDarkTransitionConfig() {
|
|
@@ -116,7 +188,16 @@ export function useBlogThemeMode() {
|
|
|
116
188
|
|
|
117
189
|
export function useArticles() {
|
|
118
190
|
const blogConfig = useConfig()
|
|
119
|
-
const
|
|
191
|
+
const { localeIndex, site } = useData()
|
|
192
|
+
|
|
193
|
+
const localeKeys = computed(() => Object.keys(site.value.locales))
|
|
194
|
+
|
|
195
|
+
const articles = computed(() => {
|
|
196
|
+
if (localeKeys.value.length === 0) {
|
|
197
|
+
return (blogConfig?.value?.blog?.pagesData || [])
|
|
198
|
+
}
|
|
199
|
+
return blogConfig?.value?.blog?.locales?.[localeIndex.value]?.pagesData || []
|
|
200
|
+
})
|
|
120
201
|
return articles
|
|
121
202
|
}
|
|
122
203
|
|
|
@@ -128,10 +209,9 @@ export function useCurrentPageNum() {
|
|
|
128
209
|
}
|
|
129
210
|
|
|
130
211
|
export function useCurrentArticle() {
|
|
131
|
-
const blogConfig = useConfig()
|
|
132
212
|
const route = useRoute()
|
|
133
213
|
|
|
134
|
-
const docs =
|
|
214
|
+
const docs = useArticles()
|
|
135
215
|
const currentArticle = computed(() => {
|
|
136
216
|
const currentPath = route.path.replace(/.html$/, '')
|
|
137
217
|
// 兼容中文路径
|
|
@@ -149,16 +229,25 @@ export function useCurrentArticle() {
|
|
|
149
229
|
}
|
|
150
230
|
|
|
151
231
|
export function useUserWorks() {
|
|
152
|
-
|
|
232
|
+
const blogConfig = useBlogConfig()
|
|
233
|
+
|
|
234
|
+
return computed(() => blogConfig.value?.works || {
|
|
235
|
+
title: '',
|
|
236
|
+
description: '',
|
|
237
|
+
list: []
|
|
238
|
+
})
|
|
153
239
|
}
|
|
154
|
-
function resolveConfig(config: Theme.Config): Theme.Config {
|
|
155
|
-
|
|
240
|
+
function resolveConfig(config: Theme.Config, locale: string = 'root'): Theme.Config {
|
|
241
|
+
const mergeConfig = {
|
|
156
242
|
...config,
|
|
157
243
|
blog: {
|
|
158
244
|
...config?.blog,
|
|
159
|
-
pagesData: config?.blog?.pagesData || []
|
|
245
|
+
pagesData: config?.blog?.pagesData || [],
|
|
246
|
+
// i18n 支持
|
|
247
|
+
...config?.blog?.locales?.[locale]
|
|
160
248
|
}
|
|
161
249
|
}
|
|
250
|
+
return mergeConfig
|
|
162
251
|
}
|
|
163
252
|
|
|
164
253
|
/**
|
|
@@ -220,11 +309,36 @@ export function useAutoUpdateAnchor() {
|
|
|
220
309
|
}
|
|
221
310
|
|
|
222
311
|
export function useHomeFooterConfig() {
|
|
223
|
-
|
|
312
|
+
const blogConfig = useBlogConfig()
|
|
313
|
+
return computed(() => blogConfig.value?.footer)
|
|
224
314
|
}
|
|
225
315
|
|
|
226
316
|
export function useBackToTopConfig() {
|
|
227
|
-
|
|
317
|
+
const blogConfig = useBlogConfig()
|
|
318
|
+
return computed(() => typeof blogConfig.value?.backToTop === 'boolean' ? undefined : blogConfig.value?.backToTop)
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export function useOpenBackToTop() {
|
|
322
|
+
const blogConfig = useBlogConfig()
|
|
323
|
+
return computed(() => blogConfig.value?.backToTop !== false)
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export function useCommentConfig() {
|
|
327
|
+
const blogConfig = useBlogConfig()
|
|
328
|
+
return computed(() => {
|
|
329
|
+
return blogConfig.value?.comment === false ? undefined : blogConfig.value?.comment
|
|
330
|
+
})
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export function useOpenCommentConfig() {
|
|
334
|
+
const blogConfig = useBlogConfig()
|
|
335
|
+
const { frontmatter } = useData()
|
|
336
|
+
return computed(() => !!blogConfig.value?.comment && frontmatter.value.comment !== false)
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
export function useFriendData() {
|
|
340
|
+
const blogConfig = useBlogConfig()
|
|
341
|
+
return computed(() => blogConfig.value?.friend)
|
|
228
342
|
}
|
|
229
343
|
|
|
230
344
|
export function useCleanUrls() {
|
|
@@ -241,42 +355,42 @@ export function useHomeAnalysis() {
|
|
|
241
355
|
}
|
|
242
356
|
|
|
243
357
|
export function useAnalyzeTitles(wordCount: Ref<number>, readTime: ComputedRef<number>) {
|
|
244
|
-
const
|
|
358
|
+
const article = computed(() => useConfig()?.value.blog?.article)
|
|
245
359
|
|
|
246
360
|
const topWordCount = computed(() =>
|
|
247
|
-
replaceValue(article?.analyzeTitles?.topWordCount || '字数:{{value}} 个字', wordCount.value)
|
|
361
|
+
replaceValue(article.value?.analyzeTitles?.topWordCount || '字数:{{value}} 个字', wordCount.value)
|
|
248
362
|
)
|
|
249
363
|
const topReadTime = computed(() =>
|
|
250
|
-
replaceValue(article?.analyzeTitles?.topReadTime || '预计:{{value}} 分钟', readTime.value)
|
|
364
|
+
replaceValue(article.value?.analyzeTitles?.topReadTime || '预计:{{value}} 分钟', readTime.value)
|
|
251
365
|
)
|
|
252
366
|
const inlineWordCount = computed(() =>
|
|
253
|
-
replaceValue(article?.analyzeTitles?.inlineWordCount || '{{value}} 个字', wordCount.value)
|
|
367
|
+
replaceValue(article.value?.analyzeTitles?.inlineWordCount || '{{value}} 个字', wordCount.value)
|
|
254
368
|
)
|
|
255
369
|
const inlineReadTime = computed(() =>
|
|
256
|
-
replaceValue(article?.analyzeTitles?.inlineReadTime || '{{value}} 分钟', readTime.value)
|
|
370
|
+
replaceValue(article.value?.analyzeTitles?.inlineReadTime || '{{value}} 分钟', readTime.value)
|
|
257
371
|
)
|
|
258
372
|
|
|
259
373
|
const wordCountTitle = computed(() =>
|
|
260
|
-
article?.analyzeTitles?.wordCount || '文章字数'
|
|
374
|
+
article.value?.analyzeTitles?.wordCount || '文章字数'
|
|
261
375
|
)
|
|
262
376
|
const readTimeTitle = computed(() =>
|
|
263
|
-
article?.analyzeTitles?.readTime || '预计阅读时间'
|
|
377
|
+
article.value?.analyzeTitles?.readTime || '预计阅读时间'
|
|
264
378
|
)
|
|
265
379
|
|
|
266
380
|
const authorTitle = computed(() =>
|
|
267
|
-
article?.analyzeTitles?.author || '本文作者'
|
|
381
|
+
article.value?.analyzeTitles?.author || '本文作者'
|
|
268
382
|
)
|
|
269
383
|
|
|
270
384
|
const publishDateTitle = computed(() =>
|
|
271
|
-
article?.analyzeTitles?.publishDate || '发布时间'
|
|
385
|
+
article.value?.analyzeTitles?.publishDate || '发布时间'
|
|
272
386
|
)
|
|
273
387
|
|
|
274
388
|
const lastUpdatedTitle = computed(() =>
|
|
275
|
-
article?.analyzeTitles?.lastUpdated || '最近修改时间'
|
|
389
|
+
article.value?.analyzeTitles?.lastUpdated || '最近修改时间'
|
|
276
390
|
)
|
|
277
391
|
|
|
278
392
|
const tagTitle = computed(() =>
|
|
279
|
-
article?.analyzeTitles?.tag || '标签'
|
|
393
|
+
article.value?.analyzeTitles?.tag || '标签'
|
|
280
394
|
)
|
|
281
395
|
|
|
282
396
|
return {
|
|
@@ -295,48 +409,50 @@ export function useAnalyzeTitles(wordCount: Ref<number>, readTime: ComputedRef<n
|
|
|
295
409
|
|
|
296
410
|
export function useFormatShowDate() {
|
|
297
411
|
const blog = useBlogConfig()
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
function formatShowDate(date: any) {
|
|
303
|
-
const source = +new Date(date)
|
|
304
|
-
const now = +new Date()
|
|
305
|
-
const diff = now - source
|
|
306
|
-
const oneSeconds = 1000
|
|
307
|
-
const oneMinute = oneSeconds * 60
|
|
308
|
-
const oneHour = oneMinute * 60
|
|
309
|
-
const oneDay = oneHour * 24
|
|
310
|
-
const oneWeek = oneDay * 7
|
|
311
|
-
|
|
312
|
-
const langMap = {
|
|
313
|
-
justNow: '刚刚',
|
|
314
|
-
secondsAgo: '秒前',
|
|
315
|
-
minutesAgo: '分钟前',
|
|
316
|
-
hoursAgo: '小时前',
|
|
317
|
-
daysAgo: '天前',
|
|
318
|
-
weeksAgo: '周前',
|
|
319
|
-
...blog.formatShowDate
|
|
412
|
+
return computed(() => {
|
|
413
|
+
if (typeof blog.value?.formatShowDate === 'function') {
|
|
414
|
+
return blog.value.formatShowDate
|
|
320
415
|
}
|
|
321
|
-
const mapValue = langMap
|
|
322
416
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
417
|
+
function formatShowDate(date: any) {
|
|
418
|
+
const source = +new Date(date)
|
|
419
|
+
const now = +new Date()
|
|
420
|
+
const diff = now - source
|
|
421
|
+
const oneSeconds = 1000
|
|
422
|
+
const oneMinute = oneSeconds * 60
|
|
423
|
+
const oneHour = oneMinute * 60
|
|
424
|
+
const oneDay = oneHour * 24
|
|
425
|
+
const oneWeek = oneDay * 7
|
|
426
|
+
|
|
427
|
+
const langMap = {
|
|
428
|
+
justNow: '刚刚',
|
|
429
|
+
secondsAgo: '秒前',
|
|
430
|
+
minutesAgo: '分钟前',
|
|
431
|
+
hoursAgo: '小时前',
|
|
432
|
+
daysAgo: '天前',
|
|
433
|
+
weeksAgo: '周前',
|
|
434
|
+
...blog.value?.formatShowDate
|
|
435
|
+
}
|
|
436
|
+
const mapValue = langMap
|
|
338
437
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
438
|
+
if (diff < 10) {
|
|
439
|
+
return mapValue.justNow
|
|
440
|
+
}
|
|
441
|
+
if (diff < oneMinute) {
|
|
442
|
+
return `${Math.floor(diff / oneSeconds)}${mapValue.secondsAgo}`
|
|
443
|
+
}
|
|
444
|
+
if (diff < oneHour) {
|
|
445
|
+
return `${Math.floor(diff / oneMinute)}${mapValue.minutesAgo}`
|
|
446
|
+
}
|
|
447
|
+
if (diff < oneDay) {
|
|
448
|
+
return `${Math.floor(diff / oneHour)}${mapValue.hoursAgo}`
|
|
449
|
+
}
|
|
450
|
+
if (diff < oneWeek) {
|
|
451
|
+
return `${Math.floor(diff / oneDay)}${mapValue.daysAgo}`
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
return formatDate(new Date(date), 'yyyy-MM-dd')
|
|
455
|
+
}
|
|
456
|
+
return formatShowDate
|
|
457
|
+
})
|
|
342
458
|
}
|