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

Fix/broken links #72

Merged
merged 6 commits into from
Jul 10, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/scripts/processReleases.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ const extractTOCFromFile = (file, version, cb) => {
}
})

// fix for missing Factory.md in old versions of TOC
const factoryFileSource = join(dirname(file), 'docs', 'Factory.md')
const hasFactoryFile = existsSync(factoryFileSource)
if (!toc.find((item) => item.fileName === 'Factory.md') && hasFactoryFile) {
toc.push({
fileName: 'Factory.md',
name: 'Factory',
sourceFile: factoryFileSource,
destinationFile: join(destFolder, 'content', 'docs', version, 'Factory.md'),
slug: 'Factory',
link: '/docs/latest/Factory'
})
}

cb(null, toc)
})
}
Expand Down Expand Up @@ -128,16 +142,19 @@ const remapLinks = (content, item) => {
[XXXX](/docs/VVVV/YYYY.md) -> [XXXX](/docs/VVVV/YYYY)
[XXXX]('./YYYY' "ZZZZ") -> [XXXX]('/docs/[VERSION]/YYYY' "ZZZZ")
[XXXX](./YYYY "ZZZZ") -> [XXXX]('/docs/[VERSION]/YYYY' "ZZZZ")
href="https://github.com/fastify/fastify/blob/master/docs/YYYY.md -> href="/docs/[VERSION]/YYYY
*/
const ecosystemLinkRx = /\(\/docs\/[\w\d.-]+\/Ecosystem\.md\)/gi
const docInternalLinkRx = /\(\/docs\/[\w\d.-]+\/[\w\d-]+(.md)/gi
const pluginsLink = /\(Plugins.md\)/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
return content
.replace(hrefAbsoluteLinks, (match, p1) => `href="/docs/${item.version}/${p1}`)
.replace(/https:\/\/github.com\/fastify\/fastify\/blob\/master\/docs/g, `/docs/${item.version}`)
.replace(ecosystemLinkRx, (match) => '(/ecosystem)')
.replace(pluginsLink, (match) => `(/docs/${item.version}/Plugins)`)
.replace(relativeLinksWithLabel, (match, ...parts) => `('/docs/${item.version}/${parts[1]}' "${parts[3]}")`)
.replace(relativeLinksWithLabel, (match, ...parts) => `(/docs/${item.version}/${parts[1]} "${parts[3]}")`)
.replace(docInternalLinkRx, (match, p1) => match.replace(p1, ''))
}

Expand Down