@sugarat/theme 0.1.38 → 0.1.39

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 CHANGED
@@ -101,11 +101,16 @@ declare namespace Theme {
101
101
  nextText?: string;
102
102
  /**
103
103
  * 是否展示当前正在浏览的文章在左侧
104
- * @default false
104
+ * @default true
105
105
  */
106
106
  showSelf?: boolean;
107
107
  filter?: (page: Theme.PageData) => boolean;
108
108
  empty?: string | boolean;
109
+ /**
110
+ * 设置推荐文章的展示风格
111
+ * @default 'card'
112
+ */
113
+ style?: 'card' | 'sidebar';
109
114
  }
110
115
  interface HomeBlog {
111
116
  name?: string;
@@ -244,6 +249,11 @@ declare namespace Theme {
244
249
  * @default false
245
250
  */
246
251
  mermaid?: any;
252
+ /**
253
+ * 设置解析 frontmatter 里 date 的时区
254
+ * @default 8 => 'UTC+8'
255
+ * */
256
+ timeZone?: number;
247
257
  }
248
258
  interface Config extends DefaultTheme.Config {
249
259
  blog?: BlogConfig;
package/node.js CHANGED
@@ -42,7 +42,7 @@ var import_fs = __toESM(require("fs"));
42
42
  var import_child_process = require("child_process");
43
43
  var import_path = __toESM(require("path"));
44
44
 
45
- // ../../node_modules/.pnpm/vitepress-plugin-tabs@0.2.0_vitepress@1.0.0-beta.2_vue@3.2.45/node_modules/vitepress-plugin-tabs/dist/index.js
45
+ // ../../node_modules/.pnpm/vitepress-plugin-tabs@0.2.0_vitepress@1.0.0-beta.7_vue@3.3.4/node_modules/vitepress-plugin-tabs/dist/index.js
46
46
  var tabsMarker = "=tabs";
47
47
  var tabsMarkerLen = tabsMarker.length;
48
48
  var ruleBlockTabs = (state, startLine, endLine, silent) => {
@@ -268,8 +268,9 @@ function getThemeConfig(cfg) {
268
268
  if (!meta.date) {
269
269
  meta.date = getFileBirthTime(v);
270
270
  } else {
271
+ const timeZone = cfg?.timeZone ?? 8;
271
272
  meta.date = formatDate(
272
- new Date(`${new Date(meta.date).toUTCString()}+8`)
273
+ new Date(`${new Date(meta.date).toUTCString()}+${timeZone}`)
273
274
  );
274
275
  }
275
276
  meta.categories = typeof meta.categories === "string" ? [meta.categories] : meta.categories;
@@ -436,7 +437,7 @@ function getTextSummary(text, count = 100) {
436
437
  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);
437
438
  }
438
439
  function assignMermaid(config) {
439
- if (!config.mermaid)
440
+ if (!config?.mermaid)
440
441
  return;
441
442
  if (!config.vite)
442
443
  config.vite = {};
@@ -475,7 +476,7 @@ function defineConfig(config) {
475
476
  console.warn("https://theme.sugarat.top/config/global.html");
476
477
  }, 1200);
477
478
  }
478
- const extendThemeConfig = config.extends?.themeConfig?.blog;
479
+ const extendThemeConfig = config.extends?.themeConfig?.blog || {};
479
480
  const resultConfig = extendThemeConfig.mermaid === false ? config : {
480
481
  ...config,
481
482
  mermaid: extendThemeConfig.mermaid === true ? {} : extendThemeConfig.mermaid
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sugarat/theme",
3
- "version": "0.1.38",
3
+ "version": "0.1.39",
4
4
  "description": "简约风的 Vitepress 博客主题,sugarat vitepress blog theme",
5
5
  "main": "src/index.ts",
6
6
  "exports": {
@@ -50,9 +50,9 @@
50
50
  "sass": "^1.56.1",
51
51
  "tsup": " ^6.5.0",
52
52
  "typescript": "^4.8.2",
53
- "vitepress": "1.0.0-beta.2",
53
+ "vitepress": "1.0.0-beta.7",
54
54
  "vitepress-plugin-tabs": "^0.2.0",
55
- "vue": "^3.2.45"
55
+ "vue": "^3.3.4"
56
56
  },
57
57
  "scripts": {
58
58
  "dev": "npm run build:node && npm run dev:docs",
@@ -10,7 +10,7 @@
10
10
  </span>
11
11
  </div>
12
12
  <div class="meta-des" ref="$des" id="hack-article-des">
13
- <!-- TODO:是否需要原创?转载等标签,理论上可以添加标签解决 -->
13
+ <!-- TODO:是否需要原创?转载等标签,理论上可以添加标签解决,可以参考 charles7c -->
14
14
  <span v-if="author && !hiddenAuthor" class="author">
15
15
  <el-icon title="本文作者"><UserFilled /></el-icon>
16
16
  <a
@@ -1,12 +1,13 @@
1
1
  <template>
2
2
  <div
3
- class="card recommend"
3
+ class="recommend"
4
+ :class="{ card: sidebarStyle === 'card' }"
4
5
  v-if="_recommend !== false && (recommendList.length || emptyText)"
5
6
  data-pagefind-ignore="all"
6
7
  >
7
8
  <!-- 头部 -->
8
9
  <div class="card-header">
9
- <span class="title">{{ title }}</span>
10
+ <span class="title" v-if="title">{{ title }}</span>
10
11
  <el-button
11
12
  v-if="showChangeBtn"
12
13
  size="small"
@@ -20,7 +21,7 @@
20
21
  <ol class="recommend-container" v-if="currentWikiData.length">
21
22
  <li v-for="(v, idx) in currentWikiData" :key="v.route">
22
23
  <!-- 序号 -->
23
- <i class="num">{{ idx + 1 }}</i>
24
+ <i class="num">{{ startIdx + idx + 1 }}</i>
24
25
  <!-- 简介 -->
25
26
  <div class="des">
26
27
  <!-- title -->
@@ -47,20 +48,27 @@
47
48
 
48
49
  <script lang="ts" setup>
49
50
  import { ref, computed } from 'vue'
50
- import { ElButton, ElLink } from 'element-plus'
51
51
  import { useRoute, withBase } from 'vitepress'
52
+ import { ElButton, ElLink } from 'element-plus'
52
53
  import { formatShowDate } from '../utils/index'
53
54
  import { useArticles, useBlogConfig } from '../composables/config/blog'
54
55
 
55
56
  const { recommend: _recommend } = useBlogConfig()
56
57
 
58
+ const sidebarStyle = computed(() =>
59
+ _recommend && _recommend?.style ? _recommend.style : 'card'
60
+ )
61
+
62
+ const recommendPadding = computed(() =>
63
+ sidebarStyle.value === 'card' ? '10px' : '0px'
64
+ )
57
65
  const recommend = computed(() =>
58
66
  _recommend === false ? undefined : _recommend
59
67
  )
60
- const title = computed(() => recommend.value?.title || '🔍 相关文章')
68
+ const title = computed(() => recommend.value?.title ?? '🔍 相关文章')
61
69
  const pageSize = computed(() => recommend.value?.pageSize || 9)
62
70
  const nextText = computed(() => recommend.value?.nextText || '换一组')
63
- const emptyText = computed(() => recommend.value?.empty ?? '暂无推荐文章')
71
+ const emptyText = computed(() => recommend.value?.empty ?? '暂无相关文章')
64
72
 
65
73
  const docs = useArticles()
66
74
 
@@ -110,6 +118,8 @@ const changePage = () => {
110
118
  currentPage.value % Math.ceil(recommendList.value.length / pageSize.value)
111
119
  currentPage.value = newIdx + 1
112
120
  }
121
+ // 当前页开始的序号
122
+ const startIdx = computed(() => (currentPage.value - 1) * pageSize.value)
113
123
 
114
124
  const currentWikiData = computed(() => {
115
125
  const startIdx = (currentPage.value - 1) * pageSize.value
@@ -143,7 +153,7 @@ const showChangeBtn = computed(() => {
143
153
 
144
154
  .recommend {
145
155
  flex-direction: column;
146
- padding: 16px 10px;
156
+ padding: v-bind(recommendPadding);
147
157
  }
148
158
 
149
159
  .recommend-container {
@@ -163,7 +173,7 @@ const showChangeBtn = computed(() => {
163
173
  color: var(--description-font-color);
164
174
  font-weight: 600;
165
175
  margin: 6px 8px 10px 0;
166
- width: 18px;
176
+ width: 22px;
167
177
  height: 18px;
168
178
  line-height: 18px;
169
179
  text-align: center;
@@ -1,19 +1,35 @@
1
- <template>
2
- <div class="sidebar" data-pagefind-ignore="all"><BlogRecommendArticle /></div>
3
- </template>
4
-
5
1
  <script lang="ts" setup>
2
+ import { computed } from 'vue'
3
+ import { useBlogConfig } from '../composables/config/blog'
6
4
  import BlogRecommendArticle from './BlogRecommendArticle.vue'
5
+
6
+ const { recommend: _recommend } = useBlogConfig()
7
+
8
+ const sidebarStyle = computed(() =>
9
+ _recommend && _recommend?.style ? _recommend.style : 'card'
10
+ )
11
+ const marginTop = computed(() =>
12
+ sidebarStyle.value === 'card' ? '40px' : '0px'
13
+ )
14
+ const marginTopMini = computed(() =>
15
+ sidebarStyle.value === 'card' ? '60px' : '0px'
16
+ )
7
17
  </script>
8
18
 
19
+ <template>
20
+ <div v-if="_recommend !== false" class="sidebar" data-pagefind-ignore="all">
21
+ <BlogRecommendArticle />
22
+ </div>
23
+ </template>
24
+
9
25
  <style lang="scss" scoped>
10
26
  .sidebar {
11
- margin-top: 40px;
27
+ margin-top: v-bind(marginTop);
12
28
  }
13
29
 
14
30
  @media screen and (min-width: 960px) and (max-width: 1120px) {
15
31
  .sidebar {
16
- margin-top: 60px;
32
+ margin-top: v-bind(marginTopMini);
17
33
  }
18
34
  }
19
35
  </style>
@@ -106,11 +106,16 @@ export namespace Theme {
106
106
  nextText?: string
107
107
  /**
108
108
  * 是否展示当前正在浏览的文章在左侧
109
- * @default false
109
+ * @default true
110
110
  */
111
111
  showSelf?: boolean
112
112
  filter?: (page: Theme.PageData) => boolean
113
113
  empty?: string | boolean
114
+ /**
115
+ * 设置推荐文章的展示风格
116
+ * @default 'card'
117
+ */
118
+ style?: 'card' | 'sidebar'
114
119
  }
115
120
 
116
121
  export interface HomeBlog {
@@ -264,6 +269,11 @@ export namespace Theme {
264
269
  * @default false
265
270
  */
266
271
  mermaid?: any
272
+ /**
273
+ * 设置解析 frontmatter 里 date 的时区
274
+ * @default 8 => 'UTC+8'
275
+ * */
276
+ timeZone?: number
267
277
  }
268
278
 
269
279
  export interface Config extends DefaultTheme.Config {
package/src/node.ts CHANGED
@@ -45,7 +45,6 @@ export function getThemeConfig(cfg?: Partial<Theme.BlogConfig>) {
45
45
 
46
46
  const fileContent = fs.readFileSync(v, 'utf-8')
47
47
 
48
- // TODO: 支持JSON
49
48
  const meta: Partial<Theme.PageMeta> = {
50
49
  ...matter(fileContent).data
51
50
  }
@@ -59,9 +58,9 @@ export function getThemeConfig(cfg?: Partial<Theme.BlogConfig>) {
59
58
  // })
60
59
  meta.date = getFileBirthTime(v)
61
60
  } else {
62
- // TODO: 开放配置,设置时区
61
+ const timeZone = cfg?.timeZone ?? 8
63
62
  meta.date = formatDate(
64
- new Date(`${new Date(meta.date).toUTCString()}+8`)
63
+ new Date(`${new Date(meta.date).toUTCString()}+${timeZone}`)
65
64
  )
66
65
  }
67
66
 
@@ -310,7 +309,7 @@ function getTextSummary(text: string, count = 100) {
310
309
  }
311
310
 
312
311
  export function assignMermaid(config: any) {
313
- if (!config.mermaid) return
312
+ if (!config?.mermaid) return
314
313
 
315
314
  if (!config.vite) config.vite = {}
316
315
  if (!config.vite.plugins) config.vite.plugins = []
@@ -353,8 +352,8 @@ export function defineConfig(config: UserConfig<Theme.Config>): any {
353
352
  }, 1200)
354
353
  }
355
354
  // @ts-ignore
356
- const extendThemeConfig = config.extends?.themeConfig
357
- ?.blog as Theme.BlogConfig
355
+ const extendThemeConfig = (config.extends?.themeConfig?.blog ||
356
+ {}) as Theme.BlogConfig
358
357
 
359
358
  // 开关支持Mermaid
360
359
  const resultConfig =