Skip to content

Commit a9ae3b3

Browse files
committed
chore: tweaks
1 parent 76470fa commit a9ae3b3

File tree

11 files changed

+77
-85
lines changed

11 files changed

+77
-85
lines changed

plugins/development/plugin-git/src/client/components/GitChangelog.ts

+14-35
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
import { useToggle } from '@vueuse/core'
22
import type { FunctionalComponent } from 'vue'
3-
import { computed, defineComponent, h } from 'vue'
4-
import { usePageData, usePageFrontmatter, usePageLang } from 'vuepress/client'
5-
import type {
6-
GitChangelogItem,
7-
GitPluginFrontmatter,
8-
GitPluginPageData,
9-
} from '../../shared/index.js'
10-
import { useGitLocaleConfig, useLastUpdated } from '../composables/index.js'
3+
import { defineComponent, h } from 'vue'
4+
import type { ChangelogItem } from '../composables/index.js'
5+
import {
6+
useChangelog,
7+
useGitLocaleConfig,
8+
useLastUpdated,
9+
} from '../composables/index.js'
1110
import { VPHeader } from './VPHeader.js'
1211

1312
import '../styles/vars.css'
1413
import '../styles/changelog.css'
1514

16-
type ResolvedChangelog = Omit<GitChangelogItem, 'date'> & { datetime: string }
17-
1815
export const GitChangelog = defineComponent({
1916
name: 'GitChangelog',
2017

@@ -30,25 +27,9 @@ export const GitChangelog = defineComponent({
3027
},
3128

3229
setup(props) {
30+
const changelog = useChangelog()
3331
const locale = useGitLocaleConfig()
3432
const latestUpdated = useLastUpdated()
35-
const frontmatter = usePageFrontmatter<GitPluginFrontmatter>()
36-
const page = usePageData<GitPluginPageData>()
37-
const lang = usePageLang()
38-
39-
const list = computed<ResolvedChangelog[]>(() => {
40-
if (frontmatter.value.changelog === false) return []
41-
42-
const formatter = new Intl.DateTimeFormat(lang.value, {
43-
dateStyle: 'short',
44-
})
45-
46-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
47-
return (page.value.git?.changelog ?? []).map(({ date, ...item }) => {
48-
const datetime = formatter.format(date)
49-
return { datetime, ...item }
50-
})
51-
})
5233

5334
const [active, toggle] = useToggle()
5435

@@ -64,7 +45,7 @@ export const GitChangelog = defineComponent({
6445
]),
6546
])
6647

67-
const ReleaseTag: FunctionalComponent<{ item: ResolvedChangelog }> = ({
48+
const ReleaseTag: FunctionalComponent<{ item: ChangelogItem }> = ({
6849
item,
6950
}) =>
7051
h(
@@ -75,14 +56,12 @@ export const GitChangelog = defineComponent({
7556
h('span', { 'class': 'datetime', 'data-allow-mismatch': '' }, [
7657
locale.value.timeOn,
7758
' ',
78-
item.datetime,
59+
item.date,
7960
]),
8061
]),
8162
)
8263

83-
const Commit: FunctionalComponent<{ item: ResolvedChangelog }> = ({
84-
item,
85-
}) =>
64+
const Commit: FunctionalComponent<{ item: ChangelogItem }> = ({ item }) =>
8665
h('li', { class: 'changelog commit' }, [
8766
h(
8867
item.commitUrl ? 'a' : 'span',
@@ -99,12 +78,12 @@ export const GitChangelog = defineComponent({
9978
h('span', { 'class': 'datetime', 'data-allow-mismatch': '' }, [
10079
locale.value.timeOn || 'on',
10180
' ',
102-
item.datetime,
81+
item.date,
10382
]),
10483
])
10584

10685
return () =>
107-
list.value.length
86+
changelog.value.length
10887
? [
10988
h(VPHeader, {
11089
level: props.headerLevel,
@@ -116,7 +95,7 @@ export const GitChangelog = defineComponent({
11695
h(ChangelogHeader),
11796

11897
h('ul', { class: 'changelog-list' }, [
119-
list.value.map((item) =>
98+
changelog.value.map((item) =>
12099
item.tag
121100
? h(ReleaseTag, { item, key: item.tag })
122101
: h(Commit, { item, key: item.hash }),

plugins/development/plugin-git/src/client/components/GitContributors.ts

+9-19
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import type { FunctionalComponent } from 'vue'
2-
import { computed, defineComponent, h } from 'vue'
3-
import { usePageData, usePageFrontmatter } from 'vuepress/client'
4-
import type {
5-
GitContributorInfo,
6-
GitPluginFrontmatter,
7-
GitPluginPageData,
8-
} from '../../shared/index.js'
9-
import { useGitLocaleConfig } from '../composables/index.js'
2+
import { defineComponent, h } from 'vue'
3+
import type { GitContributorInfo } from '../../shared/index.js'
4+
import { useContributors, useGitLocaleConfig } from '../composables/index.js'
105
import { VPHeader } from './VPHeader.js'
116

127
import '../styles/contributors.css'
@@ -22,11 +17,13 @@ export const GitContributor: FunctionalComponent<GitContributorInfo> = ({
2217
href: url,
2318
target: '_blank',
2419
rel: 'noreferrer',
25-
class: 'contributor',
20+
class: 'vp-contributor',
2621
},
2722
[
28-
avatar ? h('img', { src: avatar, alt: name, class: 'avatar' }) : null,
29-
h('span', { class: 'name' }, name),
23+
avatar
24+
? h('img', { src: avatar, alt: name, class: 'vp-contributor-avatar' })
25+
: null,
26+
h('span', { class: 'vp-contributor-name' }, name),
3027
],
3128
)
3229

@@ -45,15 +42,8 @@ export const GitContributors = defineComponent({
4542
},
4643

4744
setup(props) {
45+
const contributors = useContributors()
4846
const locale = useGitLocaleConfig()
49-
const frontmatter = usePageFrontmatter<GitPluginFrontmatter>()
50-
const page = usePageData<GitPluginPageData>()
51-
52-
const contributors = computed(() => {
53-
if (frontmatter.value.contributors === false) return []
54-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
55-
return page.value.git?.contributors ?? []
56-
})
5747

5848
return () =>
5949
contributors.value.length
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
11
import type { ComputedRef } from 'vue'
22
import { computed } from 'vue'
3-
import { usePageData } from 'vuepress/client'
4-
import type { GitChangelogItem, GitPluginPageData } from '../../shared/index.js'
3+
import { usePageData, usePageFrontmatter, usePageLang } from 'vuepress/client'
4+
import type {
5+
GitChangelogItem,
6+
GitPluginFrontmatter,
7+
GitPluginPageData,
8+
} from '../../shared/index.js'
59

6-
export const useChangelog = (): ComputedRef<GitChangelogItem[] | null> => {
10+
export interface ChangelogItem extends GitChangelogItem {
11+
date: string
12+
}
13+
14+
export const useChangelog = (): ComputedRef<ChangelogItem[]> => {
15+
const frontmatter = usePageFrontmatter<GitPluginFrontmatter>()
16+
const lang = usePageLang()
717
const page = usePageData<GitPluginPageData>()
818

919
return computed(() => {
20+
if (frontmatter.value.changelog === false) return []
21+
22+
const formatter = new Intl.DateTimeFormat(lang.value, {
23+
dateStyle: 'short',
24+
})
25+
1026
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
11-
return page.value.git?.changelog ?? null
27+
return (page.value.git?.changelog ?? []).map((item) => ({
28+
date: formatter.format(item.time),
29+
...item,
30+
}))
1231
})
1332
}
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
import type { ComputedRef } from 'vue'
22
import { computed } from 'vue'
3-
import { usePageData } from 'vuepress/client'
3+
import { usePageData, usePageFrontmatter } from 'vuepress/client'
44
import type {
55
GitContributorInfo,
6+
GitPluginFrontmatter,
67
GitPluginPageData,
78
} from '../../shared/index.js'
89

9-
export const useContributors = (): ComputedRef<GitContributorInfo[] | null> => {
10+
export const useContributors = (): ComputedRef<GitContributorInfo[]> => {
11+
const frontmatter = usePageFrontmatter<GitPluginFrontmatter>()
1012
const page = usePageData<GitPluginPageData>()
1113

1214
return computed(() => {
15+
if (frontmatter.value.contributors === false) return []
16+
1317
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
14-
return page.value.git?.contributors ?? null
18+
return page.value.git?.contributors ?? []
1519
})
1620
}

plugins/development/plugin-git/src/client/composables/useLastUpdated.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const useLastUpdated = (): ComputedRef<LastUpdated | null> => {
1818
return computed(() => {
1919
const timeStamp =
2020
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
21-
page.value.git?.updatedTime ?? page.value.git?.changelog?.[0].date
21+
page.value.git?.updatedTime ?? page.value.git?.changelog?.[0].time
2222

2323
if (!timeStamp) return null
2424

plugins/development/plugin-git/src/client/styles/contributors.scss

+16-16
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@
66
justify-content: flex-start;
77

88
margin: 2rem 0 1rem;
9+
}
910

10-
.contributor {
11-
display: flex;
12-
gap: 0.25rem;
13-
align-items: center;
14-
15-
&::after {
16-
display: none !important;
17-
}
11+
.vp-contributor {
12+
display: flex;
13+
gap: 0.25rem;
14+
align-items: center;
1815

19-
.avatar {
20-
object-fit: contain;
21-
width: 36px;
22-
height: 36px;
23-
border-radius: 50%;
24-
}
16+
&::after {
17+
display: none !important;
2518
}
2619

27-
a.contributor {
28-
text-decoration: none !important;
20+
&-avatar {
21+
object-fit: contain;
22+
width: 36px;
23+
height: 36px;
24+
border-radius: 50%;
2925
}
3026
}
27+
28+
a.vp-contributor {
29+
text-decoration: none !important;
30+
}

plugins/development/plugin-git/src/node/gitPlugin.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ export const gitPlugin =
7979
if (commits.length === 0) return
8080

8181
if (createdTime) {
82-
page.data.git.createdTime = commits[commits.length - 1].date
82+
page.data.git.createdTime = commits[commits.length - 1].time
8383
}
8484

8585
if (updatedTime) {
86-
page.data.git.updatedTime = commits[0].date
86+
page.data.git.updatedTime = commits[0].time
8787
}
8888

8989
const contributorsOptions = isPlainObject(contributors)

plugins/development/plugin-git/src/node/resolveChangelog.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ export const resolveChangelog = (
7979
: commits
8080

8181
for (const commit of sliceCommits) {
82-
const { hash, message, date, author, email, refs, coAuthors } = commit
82+
const { hash, message, time, author, email, refs, coAuthors } = commit
8383
const tag = parseTagName(refs)
8484
const contributor = getContributorInfo(
8585
getUserNameWithNoreplyEmail(email) ?? author,
8686
contributors,
8787
)
8888
const resolved: GitChangelogItem = {
8989
hash,
90-
date,
90+
time,
9191
email,
9292
author: contributor?.name ?? contributor?.username ?? author,
9393
message: app.markdown.renderInline(message),

plugins/development/plugin-git/src/node/typings.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface RawCommit {
1616
/**
1717
* Unix timestamp in milliseconds
1818
*/
19-
date: number
19+
time: number
2020
/**
2121
* Commit message
2222
*/

plugins/development/plugin-git/src/node/utils/getCommits.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,6 @@ export const getCommits = async (
106106
)
107107

108108
return mergeRawCommits(rawCommits.flat()).sort((a, b) =>
109-
b.date - a.date > 0 ? 1 : -1,
109+
b.time - a.time > 0 ? 1 : -1,
110110
)
111111
}

plugins/development/plugin-git/src/shared/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export interface GitChangelogItem {
4444
/**
4545
* Unix timestamp in milliseconds
4646
*/
47-
date: number
47+
time: number
4848
/**
4949
* Commit message
5050
*/

0 commit comments

Comments
 (0)