@sugarat/theme 0.2.28 → 0.2.29

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sugarat/theme",
3
- "version": "0.2.28",
3
+ "version": "0.2.29",
4
4
  "description": "简约风的 Vitepress 博客主题,sugarat vitepress blog theme",
5
5
  "author": "sugar",
6
6
  "license": "MIT",
@@ -2,8 +2,8 @@
2
2
  import { computed, ref } from 'vue'
3
3
  import { ElButton, ElLink } from 'element-plus'
4
4
  import { withBase } from 'vitepress'
5
- import { useArticles, useBlogConfig } from '../composables/config/blog'
6
- import { formatShowDate } from '../utils/client'
5
+ import { useArticles, useBlogConfig, useCleanUrls } from '../composables/config/blog'
6
+ import { formatShowDate, wrapperCleanUrls } from '../utils/client'
7
7
  import { fireSVG } from '../constants/svg'
8
8
 
9
9
  const { hotArticle } = useBlogConfig()
@@ -27,10 +27,14 @@ function changePage() {
27
27
  currentPage.value = newIdx + 1
28
28
  }
29
29
 
30
+ const cleanUrls = useCleanUrls()
30
31
  const currentWikiData = computed(() => {
31
32
  const startIdx = (currentPage.value - 1) * pageSize.value
32
33
  const endIdx = startIdx + pageSize.value
33
- return recommendList.value.slice(startIdx, endIdx)
34
+ return recommendList.value.slice(startIdx, endIdx).map(v => ({
35
+ ...v,
36
+ route: wrapperCleanUrls(cleanUrls, v.route)
37
+ }))
34
38
  })
35
39
 
36
40
  const showChangeBtn = computed(() => {
@@ -2,7 +2,8 @@
2
2
  import { withBase } from 'vitepress'
3
3
  import { computed } from 'vue'
4
4
  import { useWindowSize } from '@vueuse/core'
5
- import { formatShowDate } from '../utils/client'
5
+ import { formatShowDate, wrapperCleanUrls } from '../utils/client'
6
+ import { useCleanUrls } from '../composables/config/blog'
6
7
 
7
8
  const props = defineProps<{
8
9
  route: string
@@ -22,22 +23,12 @@ const showTime = computed(() => {
22
23
  return formatShowDate(props.date)
23
24
  })
24
25
 
25
- // function isWrappedWithPreventDefault(element: HTMLElement) {
26
- // let parent = element.parentElement
27
-
28
- // while (parent) {
29
- // if (parent.hasAttribute('preventDefault')) {
30
- // return true
31
- // }
32
- // parent = parent.parentElement
33
- // }
34
-
35
- // return false
36
- // }
26
+ const cleanUrls = useCleanUrls()
27
+ const link = computed(() => withBase(wrapperCleanUrls(!!cleanUrls, props.route)))
37
28
  </script>
38
29
 
39
30
  <template>
40
- <a class="blog-item" :href="withBase(route)">
31
+ <a class="blog-item" :href="link">
41
32
  <i v-if="!!pin" class="pin" />
42
33
  <!-- 标题 -->
43
34
  <p v-if="inMobile" class="title">{{ title }}</p>
@@ -2,8 +2,8 @@
2
2
  import { computed, onMounted, ref } from 'vue'
3
3
  import { useRoute, withBase } from 'vitepress'
4
4
  import { ElButton, ElLink } from 'element-plus'
5
- import { formatShowDate } from '../utils/client'
6
- import { useArticles, useBlogConfig } from '../composables/config/blog'
5
+ import { formatShowDate, wrapperCleanUrls } from '../utils/client'
6
+ import { useArticles, useBlogConfig, useCleanUrls } from '../composables/config/blog'
7
7
  import { recommendSVG } from '../constants/svg'
8
8
  import type { Theme } from '../composables/config/index'
9
9
 
@@ -145,6 +145,8 @@ onMounted(() => {
145
145
  const currentPageNum = Math.floor(currentPageIndex / pageSize.value) + 1
146
146
  currentPage.value = currentPageNum
147
147
  })
148
+
149
+ const cleanUrls = useCleanUrls()
148
150
  </script>
149
151
 
150
152
  <template>
@@ -170,7 +172,7 @@ onMounted(() => {
170
172
  <ElLink
171
173
  type="info" class="title" :class="{
172
174
  current: isCurrentDoc(v.route),
173
- }" :href="v.route"
175
+ }" :href="wrapperCleanUrls(cleanUrls, v.route)"
174
176
  >
175
177
  {{ v.meta.title }}
176
178
  </ElLink>
@@ -225,3 +225,8 @@ export function useHomeFooterConfig() {
225
225
  export function useBackToTopConfig() {
226
226
  return useBlogConfig().backToTop
227
227
  }
228
+
229
+ export function useCleanUrls() {
230
+ const { site } = useData()
231
+ return !!site.value.cleanUrls
232
+ }
package/src/index.ts CHANGED
@@ -31,7 +31,9 @@ export const BlogTheme: Theme = {
31
31
  DefaultTheme.enhanceApp(ctx)
32
32
  ctx.app.component('TimelinePage', TimelinePage)
33
33
  ctx.app.component('UserWorksPage', UserWorksPage)
34
- ctx.app.component('Mermaid', Mermaid as any)
34
+ if (!ctx.app.component('Mermaid')) {
35
+ ctx.app.component('Mermaid', Mermaid as any)
36
+ }
35
37
  }
36
38
  }
37
39
 
@@ -172,3 +172,8 @@ export function getImageUrl(
172
172
  } // 如果 ThemeableImage 类型不是上述情况,则返回空字符串
173
173
  return ''
174
174
  }
175
+
176
+ export function wrapperCleanUrls(cleanUrls: boolean, route: string) {
177
+ const tempUrl = route.replace(/\.html$/, '')
178
+ return cleanUrls ? tempUrl : `${tempUrl}.html`
179
+ }