Skip to content
This repository has been archived by the owner on Jul 8, 2023. It is now read-only.

Commit

Permalink
Fix default nesting for relative links
Browse files Browse the repository at this point in the history
  • Loading branch information
luisorbaiceta committed Dec 15, 2021
1 parent 86a7d4a commit 5d1690e
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/scripts/processReleases.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,16 +242,15 @@ function remapLinks (content, item) {
const docInternalLinkRx = /\(\/docs\/([\w\d.-]+)\/[\w\d-]+(.md)\)/gi
const ecosystemLink = /\(Ecosystem\.md\)/gi
const pluginsLink = /\(Plugins.md\)/gi
const relativeLinks = /\((..?\/)((.*)\.[\w-]+(#[\w-]+)?)\)/gi
/* e.g. [foo](./foo/bar.md#baz) */
const relativeLinks = /\(([..?/]+)(([\w-]+).md(#[\w-]+)?)\)/gi
const relativeLinksWithLabel = /\('?(\.\/)([\w\d.-]+)(.md)'?\s+"([\w\d.-]+)"\)/gi
const hrefAbsoluteLinks = /href="https:\/\/github\.com\/fastify\/fastify\/blob\/master\/docs\/([\w\d.-]+)\.md/gi
const absoluteLinks = /https:\/\/github.com\/fastify\/fastify\/blob\/master\/docs/gi
const docResourcesLink = /\(.\/?resources\/([a-zA-Z0-9\-_]+\..+)\)/gi

/* e.g. [foo](#bar) */
const localAnchorLink = /\((#[a-z0-9\-_]+)\)/gi
/* e.g. [foo](./foo/bar.md#baz) */
const relativeDocLink = /(\[[\w\s()]+\]:?)\s?\(([\w-./]+)\.md(#[\w]+)?\)/gi
/* e.g. [foo]: ./foo/bar.md#baz */
const localReferenceLink = /(\[[\w\s()]+\]:?)\s?([\w-./]+).md(#[\w]+)?/gi

Expand All @@ -268,7 +267,7 @@ function remapLinks (content, item) {
.replace(ecosystemLink, (match) => '(/ecosystem)')
.replace(pluginsLink, (match) => `(/docs/${item.version}${item.section !== '' ? '/' + item.section : ''}/Plugins)`)
.replace(relativeLinks, (match, ...parts) => {
return `(../${parts[0]}${parts[2]}${parts[3] || ''})`
return `(${(item.name.toLowerCase() === 'index') ? '' : '../'}${parts[0]}${parts[2]}${parts[3] || ''})`
// handle nested indexes to default to root
.replace(/index/ig, '')
})
Expand All @@ -283,10 +282,6 @@ function remapLinks (content, item) {
const section = item.section !== '' ? item.section : ''
return `(/docs/${item.version}/${section}/${item.name}${p1})`
})
.replace(relativeDocLink, function (match, p1, p2, p3) {
const section = item.section !== '' ? item.section : ''
return `${p1}(/docs/${item.version}${section}/${p2}${p3 ?? ''})`
})
.replace(localReferenceLink, function (match, p1, p2, p3) {
const section = item.section !== '' ? item.section : ''
return `${p1}(/docs/${item.version}${section}/${p2}${p3 ?? ''})`
Expand Down

0 comments on commit 5d1690e

Please sign in to comment.