1
1
import { useToggle } from '@vueuse/core'
2
2
import type { FunctionalComponent } from 'vue'
3
- import { computed , defineComponent , h } from 'vue'
4
- import { usePageData , usePageFrontmatter , usePageLang } from 'vuepress/client'
5
- import type {
6
- GitChangelog ,
7
- GitPluginFrontmatter ,
8
- GitPluginPageData ,
9
- } from '../../shared/index.js'
10
- import { useGitLocaleConfig } from '../composables/index.js'
3
+ import { defineComponent , h } from 'vue'
4
+ import type { GitChangelogItem } from '../composables/index.js'
5
+ import {
6
+ useChangelog ,
7
+ useGitLocaleConfig ,
8
+ useLastUpdated ,
9
+ } from '../composables/index.js'
11
10
import { VPHeader } from './VPHeader.js'
12
11
13
12
import '../styles/vars.css'
14
13
import '../styles/changelog.css'
15
14
16
- type ResolvedChangelog = Omit < GitChangelog , 'date' > & { datetime : string }
17
-
18
- export const Changelog = defineComponent ( {
19
- name : 'Changelog' ,
15
+ export const GitChangelog = defineComponent ( {
16
+ name : 'GitChangelog' ,
20
17
21
18
props : {
22
19
/** Title of changelog */
@@ -30,55 +27,25 @@ export const Changelog = defineComponent({
30
27
} ,
31
28
32
29
setup ( props ) {
30
+ const changelog = useChangelog ( )
33
31
const locale = useGitLocaleConfig ( )
34
- const frontmatter = usePageFrontmatter < GitPluginFrontmatter > ( )
35
- const page = usePageData < GitPluginPageData > ( )
36
- const lang = usePageLang ( )
37
-
38
- const list = computed < ResolvedChangelog [ ] > ( ( ) => {
39
- if ( frontmatter . value . changelog === false ) return [ ]
40
-
41
- const formatter = new Intl . DateTimeFormat ( lang . value , {
42
- dateStyle : 'short' ,
43
- } )
44
-
45
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
46
- return ( page . value . git ?. changelog ?? [ ] ) . map ( ( { date, ...item } ) => {
47
- const datetime = formatter . format ( date )
48
- return { datetime, ...item }
49
- } )
50
- } )
51
-
52
- const latestUpdated = computed ( ( ) => {
53
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
54
- const latest = ( page . value . git ?. changelog ?? [ ] ) [ 0 ]
55
-
56
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
57
- if ( ! latest ) return ''
58
-
59
- const formatter = new Intl . DateTimeFormat ( lang . value , {
60
- dateStyle : 'short' ,
61
- timeStyle : 'short' ,
62
- } )
63
- return formatter . format ( latest . date )
64
- } )
32
+ const latestUpdated = useLastUpdated ( )
65
33
66
34
const [ active , toggleActive ] = useToggle ( )
67
35
68
36
const ChangelogHeader : FunctionalComponent = ( ) =>
69
37
h ( 'div' , { class : 'changelog-header' , onClick : ( ) => toggleActive ( ) } , [
70
38
h ( 'div' , { class : 'latest-updated' } , [
71
39
h ( 'span' , { class : 'vpi-changelog' } ) ,
72
- h ( 'span' , [ locale . value . latestUpdateAt , ' ' ] ) ,
73
- h ( 'span' , { 'data-allow-mismatch' : '' } , latestUpdated . value ) ,
40
+ h ( 'span' , { 'data-allow-mismatch' : '' } , latestUpdated . value ! . text ) ,
74
41
] ) ,
75
42
h ( 'div' , [
76
43
h ( 'span' , { class : 'vpi-changelog-menu' } ) ,
77
44
h ( 'span' , locale . value . viewChangelog ) ,
78
45
] ) ,
79
46
] )
80
47
81
- const ReleaseTag : FunctionalComponent < { item : ResolvedChangelog } > = ( {
48
+ const ReleaseTag : FunctionalComponent < { item : GitChangelogItem } > = ( {
82
49
item,
83
50
} ) =>
84
51
h (
@@ -89,12 +56,12 @@ export const Changelog = defineComponent({
89
56
h ( 'span' , { 'class' : 'datetime' , 'data-allow-mismatch' : '' } , [
90
57
locale . value . timeOn ,
91
58
' ' ,
92
- item . datetime ,
59
+ item . date ,
93
60
] ) ,
94
61
] ) ,
95
62
)
96
63
97
- const Commit : FunctionalComponent < { item : ResolvedChangelog } > = ( {
64
+ const Commit : FunctionalComponent < { item : GitChangelogItem } > = ( {
98
65
item,
99
66
} ) =>
100
67
h ( 'li' , { class : 'changelog commit' } , [
@@ -113,12 +80,12 @@ export const Changelog = defineComponent({
113
80
h ( 'span' , { 'class' : 'datetime' , 'data-allow-mismatch' : '' } , [
114
81
locale . value . timeOn || 'on' ,
115
82
' ' ,
116
- item . datetime ,
83
+ item . date ,
117
84
] ) ,
118
85
] )
119
86
120
87
return ( ) =>
121
- list . value . length
88
+ changelog . value . length
122
89
? [
123
90
h ( VPHeader , {
124
91
level : props . headerLevel ,
@@ -130,7 +97,7 @@ export const Changelog = defineComponent({
130
97
h ( ChangelogHeader ) ,
131
98
132
99
h ( 'ul' , { class : 'changelog-list' } , [
133
- list . value . map ( ( item ) =>
100
+ changelog . value . map ( ( item ) =>
134
101
item . tag
135
102
? h ( ReleaseTag , { item, key : item . tag } )
136
103
: h ( Commit , { item, key : item . hash } ) ,
0 commit comments