-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(plugin-git): add built-in component <Contributors/>
<Changelog/>
, close #375
#384
Open
pengzhanbo
wants to merge
5
commits into
main
Choose a base branch
from
plugin-git-component
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,034
−146
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
436d904
feat(plugin-git): add built-in component `<Contributors/>` `<Changelo…
pengzhanbo 91a85f3
chore: tweak
pengzhanbo 6a61304
Merge branch 'main' into plugin-git-component
Mister-Hope 9ab0fa3
chore: tweak
pengzhanbo 894c87b
chore: tweak
pengzhanbo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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'), | ||
] |
137 changes: 137 additions & 0 deletions
137
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,137 @@ | ||
import { useToggle } from '@vueuse/core' | ||
import type { FunctionalComponent } from 'vue' | ||
import { computed, defineComponent, h } 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: String, | ||
}, | ||
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, toggle] = useToggle() | ||
|
||
const ChangelogHeader: FunctionalComponent = () => | ||
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: FunctionalComponent<{ item: ResolvedChangelog }> = ({ | ||
item, | ||
}) => | ||
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: FunctionalComponent<{ item: ResolvedChangelog }> = ({ | ||
item, | ||
}) => | ||
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think these names are proper. I do not know what should I fill in another language at a glance at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also don't know what would be a more appropriate name, please help me change the field name.