-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugin-git): add built-in component
<Contributors/>
`<Changelo…
…g/>`, close #375
- Loading branch information
1 parent
4270cd9
commit 436d904
Showing
33 changed files
with
1,034 additions
and
166 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
import { rollupBundle } from '../../../scripts/rollup.js' | ||
|
||
export default rollupBundle('node/index', { | ||
external: ['execa'], | ||
}) | ||
export default [ | ||
...rollupBundle('node/index', { | ||
external: ['execa'], | ||
}), | ||
...rollupBundle('client/index'), | ||
] |
139 changes: 139 additions & 0 deletions
139
plugins/development/plugin-git/src/client/components/Changelog.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import type { VNode } from 'vue' | ||
import { computed, defineComponent, h, ref } from 'vue' | ||
import { usePageData, usePageFrontmatter, usePageLang } from 'vuepress/client' | ||
import type { | ||
GitChangelog, | ||
GitPluginFrontmatter, | ||
GitPluginPageData, | ||
} from '../../shared/index.js' | ||
import { useGitLocales } from '../composables/index.js' | ||
import { VPHeader } from './VPHeader.js' | ||
|
||
import '../styles/vars.css' | ||
import '../styles/changelog.css' | ||
|
||
type ResolvedChangelog = Omit<GitChangelog, 'date'> & { datetime: string } | ||
|
||
export const Changelog = defineComponent({ | ||
name: 'Changelog', | ||
props: { | ||
headerLevel: { | ||
type: Number, | ||
default: 2, | ||
}, | ||
title: { | ||
type: String, | ||
default: '', | ||
}, | ||
}, | ||
setup(props) { | ||
const page = usePageData<GitPluginPageData>() | ||
const lang = usePageLang() | ||
const frontmatter = usePageFrontmatter<GitPluginFrontmatter>() | ||
const locale = useGitLocales() | ||
|
||
const list = computed<ResolvedChangelog[]>(() => { | ||
if (frontmatter.value.changelog === false) return [] | ||
|
||
const formatter = new Intl.DateTimeFormat(lang.value, { | ||
dateStyle: 'short', | ||
}) | ||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition | ||
return (page.value.git?.changelog ?? []).map(({ date, ...item }) => { | ||
const datetime = formatter.format(date) | ||
return { datetime, ...item } | ||
}) | ||
}) | ||
|
||
const latestUpdated = computed(() => { | ||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition | ||
const latest = (page.value.git?.changelog ?? [])[0] | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition | ||
if (!latest) return '' | ||
|
||
const formatter = new Intl.DateTimeFormat(lang.value, { | ||
dateStyle: 'short', | ||
timeStyle: 'short', | ||
}) | ||
return formatter.format(latest.date) | ||
}) | ||
|
||
const active = ref(false) | ||
|
||
const toggle = (): void => { | ||
active.value = !active.value | ||
} | ||
|
||
const ChangelogHeader = (): VNode => | ||
h('div', { class: 'changelog-header', onClick: toggle }, [ | ||
h('div', { class: 'latest-updated' }, [ | ||
h('span', { class: 'vpi-changelog' }), | ||
h('span', [locale.value.latestUpdated || 'Latest updated:', ' ']), | ||
h('span', { 'data-allow-mismatch': true }, latestUpdated.value), | ||
]), | ||
h('div', [ | ||
h('span', { class: 'vpi-changelog-menu' }), | ||
h('span', locale.value.changelogButton || 'View All Changelog'), | ||
]), | ||
]) | ||
|
||
const ReleaseTag = ({ item }: { item: ResolvedChangelog }): VNode => | ||
h( | ||
'li', | ||
{ class: 'changelog release-tag' }, | ||
h('div', [ | ||
h('a', { class: 'link release-tag' }, h('code', item.tag)), | ||
h('span', { 'class': 'datetime', 'data-allow-mismatch': true }, [ | ||
locale.value.changelogOn || 'on', | ||
' ', | ||
item.datetime, | ||
]), | ||
]), | ||
) | ||
|
||
const Commit = ({ item }: { item: ResolvedChangelog }): VNode => | ||
h('li', { class: 'changelog commit' }, [ | ||
h( | ||
item.commitUrl ? 'a' : 'span', | ||
{ | ||
class: 'link hash', | ||
href: item.commitUrl, | ||
target: '_blank', | ||
rel: 'noreferrer', | ||
}, | ||
[h('code', item.hash.slice(0, 5))], | ||
), | ||
h('span', { class: 'divider' }, '-'), | ||
h('span', { class: 'message', innerHTML: item.message }), | ||
h('span', { 'class': 'datetime', 'data-allow-mismatch': true }, [ | ||
locale.value.changelogOn || 'on', | ||
' ', | ||
item.datetime, | ||
]), | ||
]) | ||
|
||
return () => | ||
list.value.length | ||
? [ | ||
h(VPHeader, { | ||
level: props.headerLevel, | ||
anchor: 'doc-changelog', | ||
title: props.title || locale.value.changelog || 'Changelog', | ||
}), | ||
|
||
h('div', { class: ['vp-changelog', { active: active.value }] }, [ | ||
h(ChangelogHeader), | ||
|
||
h('ul', { class: 'changelog-list' }, [ | ||
list.value.map((item) => | ||
item.tag | ||
? h(ReleaseTag, { item, key: item.tag }) | ||
: h(Commit, { item, key: item.hash }), | ||
), | ||
]), | ||
]), | ||
] | ||
: null | ||
}, | ||
}) |
Oops, something went wrong.