fix: changelog path parsing error
parent
7224c15dd5
commit
8cca70ed23
|
@ -15,7 +15,7 @@ export function ChangeLog({
|
|||
maxGitLogCount = 200
|
||||
} = {}): Plugin {
|
||||
return {
|
||||
name: 'vueuse-changelog',
|
||||
name: 'git-changelog',
|
||||
resolveId(id) {
|
||||
return id === ID ? ID : null
|
||||
},
|
||||
|
|
|
@ -35,8 +35,8 @@ const isFreshChange = computed(() => {
|
|||
<em v-if="!commits.length" opacity="70">暂无最近变更历史</em>
|
||||
|
||||
<details v-else class="details custom-block [&_svg]:open:-rotate-180" :class="isFreshChange && '!bg-green/16'">
|
||||
<summary style="list-style: none" class="flex justify-between items-center">
|
||||
<span class="inline-flex items-center gap-3">
|
||||
<summary style="list-style: none" class="flex justify-between items-center select-none hover:text-$vp-c-brand-1">
|
||||
<span class="inline-flex items-center gap-3 text-$vp-custom-block-details-text">
|
||||
<span class="i-octicon:history-16" />
|
||||
<span v-if="commits[0]">
|
||||
此文档最后编辑于 {{ lastChangeDate?.fromNow() }}
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
import { rootDir } from "../../meta"
|
||||
import { CommitInfo } from "../../types"
|
||||
import { type MaybeRefOrGetter, computed, toValue } from 'vue'
|
||||
|
||||
export function useCommits(allCommits: CommitInfo[], path: MaybeRefOrGetter<string>) {
|
||||
return computed<CommitInfo[]>(() => {
|
||||
let currentPath = toValue(path)
|
||||
currentPath = (rootDir ? rootDir + '/' : '') + currentPath
|
||||
|
||||
const commits = allCommits.filter(c => {
|
||||
return c.version || c.path?.find(p => {
|
||||
const action = p[0], path1 = p[1]?.toLowerCase(), path2 = p[2]?.toLowerCase()
|
||||
|
|
|
@ -1,9 +1,26 @@
|
|||
import { useRoute } from 'vitepress'
|
||||
import { computed } from 'vue'
|
||||
import { rootDir } from '../../meta'
|
||||
|
||||
export function useRawPath() {
|
||||
const route = useRoute()
|
||||
return computed(() => (
|
||||
decodeURIComponent(route.path).replace(/^\/(.+)\.html$/, '$1.md').toLowerCase()
|
||||
))
|
||||
return computed(() => {
|
||||
let path = decodeURIComponent(route.path).toLowerCase()
|
||||
if (path.endsWith('/')) {
|
||||
path += 'index.md'
|
||||
} else {
|
||||
path = path.replace(/^\/(.+?)(\.html)?$/s, '$1.md')
|
||||
}
|
||||
return pathJoin(rootDir, path).toLowerCase()
|
||||
})
|
||||
}
|
||||
|
||||
export function pathJoin(...args: string[]) {
|
||||
return args.map((part, i) => {
|
||||
if (i === 0) {
|
||||
return part.trim().replace(/[\/]*$/g, '')
|
||||
} else {
|
||||
return part.trim().replace(/(^[\/]*|[\/]*$)/g, '')
|
||||
}
|
||||
}).filter(x=>x.length).join('/')
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue