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

Commit

Permalink
Merge pull request #313 from fastify/fix/broken-links
Browse files Browse the repository at this point in the history
Fix broken links
  • Loading branch information
jsumners committed Dec 15, 2021
2 parents 5be58a5 + dcb4bda commit 02a11ff
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
30 changes: 12 additions & 18 deletions src/scripts/processReleases.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,19 +239,17 @@ function remapLinks (content, item) {
[XXXX](./resources/YYYY.ZZZZ) -> [XXXX](/docs/[VERSION]/resources/YYYY.ZZZZ)
*/
const ecosystemLinkRx = /\(\/docs\/[\w\d.-]+\/Ecosystem\.md\)/gi
const docInternalLinkRx = /\(\/docs\/[\w\d.-]+\/[\w\d-]+(.md)/gi
const docInternalLinkRx = /\(\/docs\/([\w\d.-]+)\/[\w\d-]+(.md)\)/gi
const ecosystemLink = /\(Ecosystem\.md\)/gi
const pluginsLink = /\(Plugins.md\)/gi
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
const relativeLinks = /\(([..?/]+)(([\w/-]+\/?).md\/?(#[\w-]+)?)\)/gi
/* e.g. [foo](./foo/bar.md#baz "Example Label") */
const relativeLinksWithLabel = /\('?(\.\/)([\w\d.-]+)(.md)'?\s+"([\w\d.-]+)"\)/gi
/* e.g. (../resources/encapsulation_context.svg) */
const docResourcesLink = /\(..?\/?resources\/([a-zA-Z0-9\-_]+\..+)\)/gi
/* e.g. [foo]: ./foo/bar.md#baz */
const localReferenceLink = /(\[[\w\s()]+\]:?)\s?([\w-./]+).md(#[\w]+)?/gi

Expand All @@ -268,21 +266,17 @@ function remapLinks (content, item) {
.replace(ecosystemLink, (match) => '(/ecosystem)')
.replace(pluginsLink, (match) => `(/docs/${item.version}${item.section !== '' ? '/' + item.section : ''}/Plugins)`)
.replace(relativeLinks, (match, ...parts) => {
return `(/docs/${item.version}${item.section !== '' ? '/' + item.section : ''}/${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, '')
})
.replace(relativeLinksWithLabel, (match, ...parts) => `(/docs/${item.version}${item.section !== '' ? '/' + item.section : ''}/${parts[1]} "${parts[3]}")`)
.replace(docInternalLinkRx, (match, p1) => match.replace(p1, ''))
.replace(docResourcesLink, (match, p1) => `(/docs/${item.version}/resources/${p1})`)
.replace(localAnchorLink, function (match, p1) {
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(docInternalLinkRx, (match, p1, p2) => {
return match
.replace(p1, `${item.version}/${p1}`)
.replace(p2, '')
})
.replace(docResourcesLink, (match, p1) => `(/docs/${item.version}/resources/${p1})`)
.replace(localReferenceLink, function (match, p1, p2, p3) {
const section = item.section !== '' ? item.section : ''
return `${p1}(/docs/${item.version}${section}/${p2}${p3 ?? ''})`
Expand Down
2 changes: 1 addition & 1 deletion src/website/layouts/ecosystem.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h1 class="title">
<li>We guarantee that every community plugin respects Fastify best practices (tests, etc) at the time they have
been added to the list. We offer no guarantee on their maintenance.</li>
<li>
Can't you find the plugin you are looking for? No problem, <a href="/docs/master/Plugins">it's very easy to
Can't you find the plugin you are looking for? No problem, <a href="/docs/master/Reference/Plugins">it's very easy to
write one</a>!
</li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion src/website/layouts/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ <h1 class="title">Ecosystem</h1>
<p>
Fastify has an ever-growing ecosystem of plugins. Probably there is already a plugin for your favourite database or template language.
Have a look at the <a href="/ecosystem">Ecosystem page</a> to navigate through the currently available plugins.
Can't you find the plugin you are looking for? No problem, <a href="/docs/master/Plugins">it's very easy to write one</a>!
Can't you find the plugin you are looking for? No problem, <a href="/docs/master/Reference/Plugins">it's very easy to write one</a>!
</p>
<div class="block">
<!-- TAG: "Changed the statement to count plugins" -->
Expand Down

0 comments on commit 02a11ff

Please sign in to comment.