Skip to content

Commit

Permalink
Merge pull request #20 from this-is-tobi/develop
Browse files Browse the repository at this point in the history
fix: do not transform link if it refers to a local section
  • Loading branch information
this-is-tobi authored Nov 9, 2024
2 parents b38e1f9 + 17d70f2 commit 6219155
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/lib/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,11 @@ export function parseVitepressConfig(path: string) {
}

export function generateVitepressFiles(vitepressConfig: Partial<ReturnType<typeof defineConfig>>, index: Index) {
const separator = '---\n'
createDir(dirname(VITEPRESS_CONFIG))

log(` Generate Vitepress config.`, 'info')
writeFileSync(VITEPRESS_CONFIG, `export default ${JSON.stringify(vitepressConfig, null, 2)}\n`)
log(` Generate index file.`, 'info')
writeFileSync(INDEX_FILE, '---\n'.concat(YAML.stringify(index)))
writeFileSync(INDEX_FILE, separator.concat(YAML.stringify(index), separator))
}
2 changes: 1 addition & 1 deletion src/utils/regex.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('file Path Replacements', () => {
it('should not modify content if there are no matching paths', () => {
const file = 'README.md'
const url = 'https://example.com'
const content = '[Link](https://google.com)'
const content = '[Link](https://google.com) and [Section](#section)'

;(readFileSync as any).mockReturnValue(content)

Expand Down
2 changes: 1 addition & 1 deletion src/utils/regex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function replaceRelativePath(file: string, url: string) {
export function replaceReadmePath(file: string, url: string) {
const readmeContent = readFileSync(file, 'utf8')
const updatedContent = readmeContent
.replace(/\[([^\]]+)\]\((?!\.?\/docs\/|docs\/|http)(\.?\/)?([^/][^)]+)\)/g, (_match, p1, _p2, p3) => {
.replace(/\[([^\]]+)\]\((?!\.?\/docs\/|docs\/|http|#)(\.?\/)?([^/][^)]+)\)/g, (_match, p1, _p2, p3) => {
return `[${p1}](${url}/${p3})`
})
.replace(/\[([^\]]+)\]\((\.?\/docs\/|docs\/)([^)]*)\)/g, (_match, p1, _p2, p3) => {
Expand Down

0 comments on commit 6219155

Please sign in to comment.