@sugarat/theme 0.1.25 → 0.1.27
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.1.
|
|
3
|
+
"version": "0.1.27",
|
|
4
4
|
"description": "简约风的 Vitepress 博客主题,sugarat vitepress blog theme",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"exports": {
|
|
@@ -41,12 +41,12 @@
|
|
|
41
41
|
"vue-command-palette": "^0.1.4"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@element-plus/icons-vue": "^2.0
|
|
45
|
-
"element-plus": "^2.
|
|
44
|
+
"@element-plus/icons-vue": "^2.1.0",
|
|
45
|
+
"element-plus": "^2.3.4",
|
|
46
46
|
"sass": "^1.56.1",
|
|
47
47
|
"tsup": " ^6.5.0",
|
|
48
48
|
"typescript": "^4.8.2",
|
|
49
|
-
"vitepress": "1.0.0-alpha.
|
|
49
|
+
"vitepress": "1.0.0-alpha.74",
|
|
50
50
|
"vue": "^3.2.45"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
@@ -43,7 +43,9 @@ const { Layout } = Theme
|
|
|
43
43
|
<BlogHomeBanner />
|
|
44
44
|
</div>
|
|
45
45
|
<div class="content-wrapper">
|
|
46
|
-
<div class="blog-list-wrapper"
|
|
46
|
+
<div class="blog-list-wrapper">
|
|
47
|
+
<BlogList />
|
|
48
|
+
</div>
|
|
47
49
|
<div class="blog-info-wrapper"><BlogHomeInfo /></div>
|
|
48
50
|
</div>
|
|
49
51
|
</div>
|
|
@@ -33,7 +33,11 @@ import { computed, watch } from 'vue'
|
|
|
33
33
|
import { ElTag } from 'element-plus'
|
|
34
34
|
import { useBrowserLocation, useDark } from '@vueuse/core'
|
|
35
35
|
import { useRouter } from 'vitepress'
|
|
36
|
-
import {
|
|
36
|
+
import {
|
|
37
|
+
useActiveTag,
|
|
38
|
+
useArticles,
|
|
39
|
+
useCurrentPageNum
|
|
40
|
+
} from '../composables/config/blog'
|
|
37
41
|
|
|
38
42
|
const docs = useArticles()
|
|
39
43
|
|
|
@@ -50,14 +54,18 @@ const isDark = useDark({
|
|
|
50
54
|
const colorMode = computed(() => (isDark.value ? 'light' : 'dark'))
|
|
51
55
|
|
|
52
56
|
const tagType: any = ['', 'info', 'success', 'warning', 'danger']
|
|
57
|
+
const currentPage = useCurrentPageNum()
|
|
53
58
|
|
|
54
59
|
const handleCloseTag = () => {
|
|
55
60
|
activeTag.value.label = ''
|
|
56
61
|
activeTag.value.type = ''
|
|
62
|
+
currentPage.value = 1
|
|
57
63
|
router.go(`${window.location.origin}${router.route.path}`)
|
|
58
64
|
}
|
|
59
65
|
|
|
60
66
|
const router = useRouter()
|
|
67
|
+
const location = useBrowserLocation()
|
|
68
|
+
|
|
61
69
|
const handleTagClick = (tag: string, type: string) => {
|
|
62
70
|
if (tag === activeTag.value.label) {
|
|
63
71
|
handleCloseTag()
|
|
@@ -65,14 +73,14 @@ const handleTagClick = (tag: string, type: string) => {
|
|
|
65
73
|
}
|
|
66
74
|
activeTag.value.type = type
|
|
67
75
|
activeTag.value.label = tag
|
|
68
|
-
|
|
76
|
+
currentPage.value = 1
|
|
69
77
|
router.go(
|
|
70
|
-
`${
|
|
78
|
+
`${location.value.origin}${router.route.path}?tag=${tag}&type=${type}`
|
|
71
79
|
)
|
|
72
80
|
}
|
|
73
|
-
|
|
81
|
+
|
|
74
82
|
watch(
|
|
75
|
-
|
|
83
|
+
location,
|
|
76
84
|
() => {
|
|
77
85
|
if (location.value.href) {
|
|
78
86
|
const url = new URL(location.value.href!)
|
|
@@ -13,25 +13,32 @@
|
|
|
13
13
|
/>
|
|
14
14
|
</li>
|
|
15
15
|
</ul>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
<!-- 解决element-ui bug -->
|
|
17
|
+
<ClientOnly>
|
|
18
|
+
<el-pagination
|
|
19
|
+
v-if="wikiList.length >= pageSize"
|
|
20
|
+
small
|
|
21
|
+
background
|
|
22
|
+
:default-current-page="1"
|
|
23
|
+
:current-page="currentPage"
|
|
24
|
+
@update:current-page="handleUpdatePageNum"
|
|
25
|
+
:page-size="pageSize"
|
|
26
|
+
:total="filterData.length"
|
|
27
|
+
layout="prev, pager, next, jumper"
|
|
28
|
+
/>
|
|
29
|
+
</ClientOnly>
|
|
25
30
|
</template>
|
|
26
31
|
<script setup lang="ts">
|
|
27
|
-
import { computed,
|
|
32
|
+
import { computed, watch } from 'vue'
|
|
28
33
|
import { ElPagination } from 'element-plus'
|
|
29
|
-
import { useData } from 'vitepress'
|
|
34
|
+
import { useData, useRouter } from 'vitepress'
|
|
35
|
+
import { useBrowserLocation } from '@vueuse/core'
|
|
30
36
|
import BlogItem from './BlogItem.vue'
|
|
31
37
|
import {
|
|
32
38
|
useArticles,
|
|
33
39
|
useActiveTag,
|
|
34
|
-
useBlogConfig
|
|
40
|
+
useBlogConfig,
|
|
41
|
+
useCurrentPageNum
|
|
35
42
|
} from '../composables/config/blog'
|
|
36
43
|
import { Theme } from '../composables/config'
|
|
37
44
|
|
|
@@ -68,11 +75,43 @@ const { home } = useBlogConfig()
|
|
|
68
75
|
const pageSize = computed(
|
|
69
76
|
() => frontmatter.value.blog?.pageSize || home?.pageSize || 6
|
|
70
77
|
)
|
|
71
|
-
const currentPage =
|
|
72
|
-
|
|
78
|
+
const currentPage = useCurrentPageNum()
|
|
73
79
|
const currentWikiData = computed(() => {
|
|
74
80
|
const startIdx = (currentPage.value - 1) * pageSize.value
|
|
75
81
|
const endIdx = startIdx + pageSize.value
|
|
76
82
|
return filterData.value.slice(startIdx, endIdx)
|
|
77
83
|
})
|
|
84
|
+
|
|
85
|
+
const router = useRouter()
|
|
86
|
+
const location = useBrowserLocation()
|
|
87
|
+
const queryPageNumKey = 'pageNum'
|
|
88
|
+
const handleUpdatePageNum = (current: number) => {
|
|
89
|
+
if (currentPage.value === current) {
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
currentPage.value = current
|
|
93
|
+
const { searchParams } = new URL(window.location.href!)
|
|
94
|
+
searchParams.delete(queryPageNumKey)
|
|
95
|
+
searchParams.append(queryPageNumKey, String(current))
|
|
96
|
+
router.go(
|
|
97
|
+
`${location.value.origin}${router.route.path}?${searchParams.toString()}`
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
watch(
|
|
102
|
+
location,
|
|
103
|
+
() => {
|
|
104
|
+
if (location.value.href) {
|
|
105
|
+
const { searchParams } = new URL(location.value.href)
|
|
106
|
+
if (searchParams.has(queryPageNumKey)) {
|
|
107
|
+
currentPage.value = Number(searchParams.get(queryPageNumKey))
|
|
108
|
+
} else {
|
|
109
|
+
currentPage.value = 1
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
immediate: true
|
|
115
|
+
}
|
|
116
|
+
)
|
|
78
117
|
</script>
|
|
@@ -16,6 +16,7 @@ const configSymbol: InjectionKey<Ref<Theme.Config>> = Symbol('theme-config')
|
|
|
16
16
|
|
|
17
17
|
const activeTagSymbol: InjectionKey<Ref<Theme.activeTag>> = Symbol('active-tag')
|
|
18
18
|
|
|
19
|
+
const currentPageNum: InjectionKey<Ref<number>> = Symbol('home-page-num')
|
|
19
20
|
const homeConfigSymbol: InjectionKey<Theme.HomeConfig> = Symbol('home-config')
|
|
20
21
|
|
|
21
22
|
export function withConfigProvider(App: Component) {
|
|
@@ -39,6 +40,10 @@ export function withConfigProvider(App: Component) {
|
|
|
39
40
|
type: ''
|
|
40
41
|
})
|
|
41
42
|
provide(activeTagSymbol, activeTag)
|
|
43
|
+
|
|
44
|
+
const pageNum = ref(1)
|
|
45
|
+
provide(currentPageNum, pageNum)
|
|
46
|
+
|
|
42
47
|
return () => h(App, null, slots)
|
|
43
48
|
}
|
|
44
49
|
})
|
|
@@ -75,6 +80,9 @@ export function useArticles() {
|
|
|
75
80
|
export function useActiveTag() {
|
|
76
81
|
return inject(activeTagSymbol)!
|
|
77
82
|
}
|
|
83
|
+
export function useCurrentPageNum() {
|
|
84
|
+
return inject(currentPageNum)!
|
|
85
|
+
}
|
|
78
86
|
|
|
79
87
|
export function useCurrentArticle() {
|
|
80
88
|
const blogConfig = useConfig()
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
<script lang="ts" setup>
|
|
2
|
-
import { useData, useRoute } from 'vitepress'
|
|
3
|
-
import { computed, onMounted, ref, watch } from 'vue'
|
|
4
|
-
import { useBlogConfig } from '../composables/config/blog'
|
|
5
|
-
|
|
6
|
-
const routeData = useRoute()
|
|
7
|
-
const { frontmatter } = useData()
|
|
8
|
-
const { article } = useBlogConfig()
|
|
9
|
-
const openLazy = computed(() => {
|
|
10
|
-
return (frontmatter.value.lazy || article?.lazy) ?? true
|
|
11
|
-
})
|
|
12
|
-
const imageList = ref<HTMLImageElement[]>([])
|
|
13
|
-
const currentObserver = ref<IntersectionObserver>()
|
|
14
|
-
const refresh = () => {
|
|
15
|
-
if (openLazy.value) {
|
|
16
|
-
const docDomContainer = window.document.querySelector('#VPContent')
|
|
17
|
-
const imgs = docDomContainer?.querySelectorAll<HTMLImageElement>(
|
|
18
|
-
'.content-container .main img'
|
|
19
|
-
)
|
|
20
|
-
// 销毁旧的
|
|
21
|
-
imageList.value.forEach((v) => currentObserver.value?.unobserve(v))
|
|
22
|
-
|
|
23
|
-
// 存新的
|
|
24
|
-
imageList.value = Array.from(imgs as unknown as HTMLImageElement[])
|
|
25
|
-
|
|
26
|
-
// 初始化
|
|
27
|
-
imageList.value.forEach((img) => {
|
|
28
|
-
const src = img.getAttribute('src')
|
|
29
|
-
if (src) {
|
|
30
|
-
img.removeAttribute('src')
|
|
31
|
-
img.setAttribute('data-src', src)
|
|
32
|
-
}
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
const observer = new IntersectionObserver((entries) => {
|
|
36
|
-
entries.forEach((entry) => {
|
|
37
|
-
if (entry.isIntersecting) {
|
|
38
|
-
const img = entry.target
|
|
39
|
-
const src = img.getAttribute('data-src')
|
|
40
|
-
if (src) {
|
|
41
|
-
img.setAttribute('src', src)
|
|
42
|
-
}
|
|
43
|
-
observer.unobserve(img)
|
|
44
|
-
|
|
45
|
-
console.log('render', src)
|
|
46
|
-
}
|
|
47
|
-
})
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
// 监听
|
|
51
|
-
imageList.value.forEach((img) => {
|
|
52
|
-
observer.observe(img)
|
|
53
|
-
})
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
watch(routeData, () => {
|
|
57
|
-
refresh()
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
onMounted(() => {
|
|
61
|
-
refresh()
|
|
62
|
-
})
|
|
63
|
-
</script>
|