Skip to content

Commit 12da52a

Browse files
committed
fix
1 parent a221f8b commit 12da52a

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

docs/.vitepress/plugins/markdownTransform.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ export function MarkdownTransform(): PluginOption {
2727

2828
// replace markdown img link
2929
// code reference: https://github.com/unjs/ungh/blob/main/utils/markdown.ts
30-
const { name, owner, branch: defaultBranch } = repositoryMeta.find(({ name }) => name === basename(id, '.md'))!
31-
const _defaultBranch = defaultBranch || 'main'
30+
const { name, owner, branch = 'main' } = repositoryMeta.find(({ name }) => name === basename(id, '.md'))!
3231
code = code.replaceAll(MARKDOWN_LINK_RE, (match, _, url: string | undefined, url2: string) => {
3332
const path = url || url2
3433
// If path is already a URL, return the match
@@ -37,8 +36,8 @@ export function MarkdownTransform(): PluginOption {
3736

3837
// handle images and links differently
3938
return match.includes('<img') || images.some(ext => match.includes(ext))
40-
? match.replace(path, `${GH_RAW_URL}/${owner}/${name}/${_defaultBranch}/${path.replace(/^\.\//, '')}`)
41-
: match.replace(path, `${GH_URL}/${name}/tree/${_defaultBranch}/${path.replace(/^\.\//, '')}`)
39+
? match.replace(path, `${GH_RAW_URL}/${owner}/${name}/${branch}/${path.replace(/^\.\//, '')}`)
40+
: match.replace(path, `${GH_URL}/${name}/tree/${branch}/${path.replace(/^\.\//, '')}`)
4241
})
4342

4443
let useCode = code

0 commit comments

Comments
 (0)