@sugarat/theme 0.1.9 → 0.1.10
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 +2 -2
- package/node.js +54 -0
- package/package.json +2 -2
- package/src/components/BlogAlert.vue +1 -1
- package/src/components/BlogApp.vue +1 -1
- package/src/components/BlogArticleAnalyze.vue +1 -1
- package/src/components/BlogComment.vue +6 -1
- package/src/components/BlogHomeInfo.vue +1 -1
- package/src/components/BlogHomeTags.vue +1 -1
- package/src/components/BlogHotArticle.vue +5 -1
- package/src/components/BlogList.vue +3 -3
- package/src/components/BlogPopover.vue +1 -1
- package/src/components/BlogRecommendArticle.vue +5 -1
- package/src/components/BlogSearch.vue +49 -10
- package/src/components/BlogSidebar.vue +1 -1
- package/src/composables/config/index.ts +1 -1
- package/src/node.ts +57 -0
package/node.d.ts
CHANGED
|
@@ -139,7 +139,7 @@ declare namespace Theme {
|
|
|
139
139
|
author?: string;
|
|
140
140
|
hotArticle?: HotArticle;
|
|
141
141
|
home?: HomeBlog;
|
|
142
|
-
search?: boolean;
|
|
142
|
+
search?: boolean | 'pagefind';
|
|
143
143
|
/**
|
|
144
144
|
* 配置评论
|
|
145
145
|
* power by https://giscus.app/zh-CN
|
|
@@ -170,7 +170,7 @@ declare function getThemeConfig(cfg?: Partial<Theme.BlogConfig>): {
|
|
|
170
170
|
author?: string | undefined;
|
|
171
171
|
hotArticle?: Theme.HotArticle | undefined;
|
|
172
172
|
home?: Theme.HomeBlog | undefined;
|
|
173
|
-
search?: boolean | undefined;
|
|
173
|
+
search?: boolean | "pagefind" | undefined;
|
|
174
174
|
comment?: false | Theme.GiscusConfig | undefined;
|
|
175
175
|
recommend?: Theme.RecommendArticle | undefined;
|
|
176
176
|
article?: Theme.ArticleConfig | undefined;
|
package/node.js
CHANGED
|
@@ -183,6 +183,60 @@ function getTextSummary(text, count = 100) {
|
|
|
183
183
|
return clearMatterContent(text).match(/^# ([\s\S]+)/m)?.[1]?.replace(/#/g, "")?.replace(/!\[.*?\]\(.*?\)/g, "")?.replace(/\[(.*?)\]\(.*?\)/g, "$1")?.replace(/\*\*(.*?)\*\*/g, "$1")?.split("\n")?.filter((v) => !!v)?.slice(1)?.join("\n")?.replace(/>(.*)/, "")?.slice(0, count);
|
|
184
184
|
}
|
|
185
185
|
function defineConfig(config) {
|
|
186
|
+
if (config?.themeConfig?.blog?.search === "pagefind") {
|
|
187
|
+
config.head = (config.head || []).concat([
|
|
188
|
+
[
|
|
189
|
+
"script",
|
|
190
|
+
{},
|
|
191
|
+
`import('/_pagefind/pagefind.js')
|
|
192
|
+
.then((module) => {
|
|
193
|
+
window.__pagefind__ = module
|
|
194
|
+
})
|
|
195
|
+
.catch(() => {
|
|
196
|
+
console.log('not load /_pagefind/pagefind.js')
|
|
197
|
+
})`
|
|
198
|
+
]
|
|
199
|
+
]);
|
|
200
|
+
let flag = true;
|
|
201
|
+
let originLog = null;
|
|
202
|
+
config.vite = {
|
|
203
|
+
...config.vite,
|
|
204
|
+
plugins: [
|
|
205
|
+
...config.vite?.plugins || [],
|
|
206
|
+
{
|
|
207
|
+
name: "@sugarar/theme-plugin-pagefind",
|
|
208
|
+
buildEnd() {
|
|
209
|
+
const { log } = console;
|
|
210
|
+
if (flag) {
|
|
211
|
+
flag = false;
|
|
212
|
+
originLog = log;
|
|
213
|
+
Object.defineProperty(console, "log", {
|
|
214
|
+
value() {
|
|
215
|
+
if (`${arguments[0]}`.includes("build complete")) {
|
|
216
|
+
console.log = originLog;
|
|
217
|
+
setTimeout(() => {
|
|
218
|
+
originLog();
|
|
219
|
+
originLog("=== pagefind: https://pagefind.app/ ===");
|
|
220
|
+
const command = `npx pagefind --source ${import_path.default.join(
|
|
221
|
+
process.argv.slice(2)?.[1] || ".",
|
|
222
|
+
".vitepress/dist"
|
|
223
|
+
)}`;
|
|
224
|
+
originLog(command);
|
|
225
|
+
originLog();
|
|
226
|
+
(0, import_child_process.execSync)(command, {
|
|
227
|
+
stdio: "inherit"
|
|
228
|
+
});
|
|
229
|
+
}, 100);
|
|
230
|
+
}
|
|
231
|
+
return log.apply(this, arguments);
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
]
|
|
238
|
+
};
|
|
239
|
+
}
|
|
186
240
|
return config;
|
|
187
241
|
}
|
|
188
242
|
// Annotate the CommonJS export names for ESM import in node:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sugarat/theme",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "简约风的 Vitepress 博客主题,sugarat vitepress blog theme",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"exports": {
|
|
@@ -52,6 +52,6 @@
|
|
|
52
52
|
"build": "npm run build:node && npm run build:docs",
|
|
53
53
|
"build:docs": "vitepress build demo",
|
|
54
54
|
"build:node": "npx tsup src/node.ts --dts --out-dir=./",
|
|
55
|
-
"serve": "
|
|
55
|
+
"serve": "vitepress serve demo"
|
|
56
56
|
}
|
|
57
57
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div
|
|
2
|
+
<div
|
|
3
|
+
class="card recommend"
|
|
4
|
+
v-if="recommendList.length || empty"
|
|
5
|
+
data-pagefind-ignore="all"
|
|
6
|
+
>
|
|
3
7
|
<!-- 头部 -->
|
|
4
8
|
<div class="card-header">
|
|
5
9
|
<span class="title">{{ title }}</span>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<ul>
|
|
2
|
+
<ul data-pagefind-ignore="all">
|
|
3
3
|
<li v-for="v in currentWikiData" :key="v.route">
|
|
4
4
|
<blog-item
|
|
5
5
|
:route="v.route"
|
|
@@ -44,8 +44,8 @@ const activeTag = useActiveTag()
|
|
|
44
44
|
const activeTagLabel = computed(() => activeTag.value.label)
|
|
45
45
|
|
|
46
46
|
const wikiList = computed(() => {
|
|
47
|
-
const topList = docs.value.filter((v) => v.meta.top)
|
|
48
|
-
topList.sort((a, b) => a.meta
|
|
47
|
+
const topList = docs.value.filter((v) => !!v.meta.top)
|
|
48
|
+
topList.sort((a, b) => a.meta!.top - b.meta!.top)
|
|
49
49
|
const data = docs.value.filter(
|
|
50
50
|
(v) => v.meta.date && v.meta.title && !v.meta.top && !v.meta.hidden
|
|
51
51
|
)
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div
|
|
2
|
+
<div
|
|
3
|
+
class="card recommend"
|
|
4
|
+
v-if="recommendList.length || emptyText"
|
|
5
|
+
data-pagefind-ignore="all"
|
|
6
|
+
>
|
|
3
7
|
<!-- 头部 -->
|
|
4
8
|
<div class="card-header">
|
|
5
9
|
<span class="title">{{ title }}</span>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div class="blog-search" v-if="openSearch">
|
|
2
|
+
<div class="blog-search" v-if="openSearch" data-pagefind-ignore="all">
|
|
3
3
|
<div class="nav-search-btn-wait" @click="searchModal = true">
|
|
4
4
|
<el-icon size="22px">
|
|
5
5
|
<Search />
|
|
@@ -47,9 +47,7 @@
|
|
|
47
47
|
{{ formatDate(item.meta.date, 'yyyy-MM-dd') }}</span
|
|
48
48
|
>
|
|
49
49
|
</div>
|
|
50
|
-
<div class="des">
|
|
51
|
-
{{ item.meta.description }}
|
|
52
|
-
</div>
|
|
50
|
+
<div class="des" v-html="item.meta.description"></div>
|
|
53
51
|
</a>
|
|
54
52
|
</el-card>
|
|
55
53
|
</li>
|
|
@@ -73,6 +71,7 @@ import {
|
|
|
73
71
|
import { useWindowSize } from '@vueuse/core'
|
|
74
72
|
import { formatDate } from '../utils'
|
|
75
73
|
import { useArticles, useBlogConfig } from '../composables/config/blog'
|
|
74
|
+
import { Theme } from '../composables/config'
|
|
76
75
|
|
|
77
76
|
const { search: openSearch = true } = useBlogConfig()
|
|
78
77
|
|
|
@@ -96,16 +95,56 @@ watch(
|
|
|
96
95
|
|
|
97
96
|
const docs = useArticles()
|
|
98
97
|
|
|
99
|
-
const searchResult =
|
|
100
|
-
|
|
101
|
-
|
|
98
|
+
const searchResult = ref<Theme.PageData[]>([])
|
|
99
|
+
const inlineSearch = () => {
|
|
100
|
+
if (!searchWords.value) {
|
|
101
|
+
searchResult.value = []
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
searchResult.value = docs.value.filter((v) =>
|
|
102
105
|
`${v.meta.description}${v.meta.title}`.includes(searchWords.value)
|
|
103
106
|
)
|
|
104
|
-
|
|
107
|
+
searchResult.value.sort((a, b) => {
|
|
105
108
|
return +new Date(b.meta.date) - +new Date(a.meta.date)
|
|
106
109
|
})
|
|
107
|
-
|
|
108
|
-
|
|
110
|
+
}
|
|
111
|
+
watch(
|
|
112
|
+
() => searchWords.value,
|
|
113
|
+
() => {
|
|
114
|
+
if (openSearch === 'pagefind') {
|
|
115
|
+
// dev-server兜底
|
|
116
|
+
// @ts-ignore
|
|
117
|
+
if (!window?.__pagefind__?.search) {
|
|
118
|
+
inlineSearch()
|
|
119
|
+
return
|
|
120
|
+
}
|
|
121
|
+
// @ts-ignore
|
|
122
|
+
window?.__pagefind__
|
|
123
|
+
?.search?.(searchWords.value)
|
|
124
|
+
.then(async (search: any) => {
|
|
125
|
+
const result = await Promise.all(
|
|
126
|
+
search.results.map((v: any) => v.data())
|
|
127
|
+
)
|
|
128
|
+
searchResult.value = []
|
|
129
|
+
docs.value.forEach((v) => {
|
|
130
|
+
const match = result.find((r) => r.url.startsWith(v.route))
|
|
131
|
+
if (match) {
|
|
132
|
+
searchResult.value.push({
|
|
133
|
+
...v,
|
|
134
|
+
meta: {
|
|
135
|
+
...v.meta,
|
|
136
|
+
description: match.excerpt
|
|
137
|
+
}
|
|
138
|
+
})
|
|
139
|
+
}
|
|
140
|
+
})
|
|
141
|
+
})
|
|
142
|
+
} else {
|
|
143
|
+
inlineSearch()
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
)
|
|
147
|
+
|
|
109
148
|
const pageSize = ref(6)
|
|
110
149
|
const currentPage = ref(0)
|
|
111
150
|
const showSearchResult = computed(() => {
|
package/src/node.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable prefer-rest-params */
|
|
1
2
|
import glob from 'fast-glob'
|
|
2
3
|
import matter from 'gray-matter'
|
|
3
4
|
import fs from 'fs'
|
|
@@ -188,5 +189,61 @@ function getTextSummary(text: string, count = 100) {
|
|
|
188
189
|
}
|
|
189
190
|
|
|
190
191
|
export function defineConfig(config: UserConfig<Theme.Config>) {
|
|
192
|
+
if (config?.themeConfig?.blog?.search === 'pagefind') {
|
|
193
|
+
config.head = (config.head || []).concat([
|
|
194
|
+
[
|
|
195
|
+
'script',
|
|
196
|
+
{},
|
|
197
|
+
`import('/_pagefind/pagefind.js')
|
|
198
|
+
.then((module) => {
|
|
199
|
+
window.__pagefind__ = module
|
|
200
|
+
})
|
|
201
|
+
.catch(() => {
|
|
202
|
+
console.log('not load /_pagefind/pagefind.js')
|
|
203
|
+
})`
|
|
204
|
+
]
|
|
205
|
+
])
|
|
206
|
+
let flag = true
|
|
207
|
+
let originLog: any = null
|
|
208
|
+
config.vite = {
|
|
209
|
+
...config.vite,
|
|
210
|
+
plugins: [
|
|
211
|
+
...(config.vite?.plugins || []),
|
|
212
|
+
{
|
|
213
|
+
name: '@sugarar/theme-plugin-pagefind',
|
|
214
|
+
buildEnd() {
|
|
215
|
+
const { log } = console
|
|
216
|
+
// TODO: hack
|
|
217
|
+
if (flag) {
|
|
218
|
+
flag = false
|
|
219
|
+
originLog = log
|
|
220
|
+
Object.defineProperty(console, 'log', {
|
|
221
|
+
value() {
|
|
222
|
+
if (`${arguments[0]}`.includes('build complete')) {
|
|
223
|
+
console.log = originLog
|
|
224
|
+
setTimeout(() => {
|
|
225
|
+
originLog()
|
|
226
|
+
originLog('=== pagefind: https://pagefind.app/ ===')
|
|
227
|
+
const command = `npx pagefind --source ${path.join(
|
|
228
|
+
process.argv.slice(2)?.[1] || '.',
|
|
229
|
+
'.vitepress/dist'
|
|
230
|
+
)}`
|
|
231
|
+
originLog(command)
|
|
232
|
+
originLog()
|
|
233
|
+
execSync(command, {
|
|
234
|
+
stdio: 'inherit'
|
|
235
|
+
})
|
|
236
|
+
}, 100)
|
|
237
|
+
}
|
|
238
|
+
// @ts-ignore
|
|
239
|
+
return log.apply(this, arguments)
|
|
240
|
+
}
|
|
241
|
+
})
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
]
|
|
246
|
+
}
|
|
247
|
+
}
|
|
191
248
|
return config
|
|
192
249
|
}
|