-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Support mapping links to full URLs from hint
Github repo
#934
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -524,16 +524,21 @@ const getFilesInfo = (files) => { | |
}; | ||
|
||
/** Updates the markdown links to other parts of the documentation, i.e.: start with "./" */ | ||
const updateMarkdownlinks = (content, filePath) => { | ||
const updateMarkdownlinks = (file) => { | ||
const content = file.content; | ||
const filePath = file.orig || file.dest; | ||
/** | ||
* This regex should match the following examples: | ||
* * [link label]: ./somewhere.md → \s | ||
* * [link label]:./somewhere.md → : | ||
* * [link](./somewhere.md) → \( | ||
* * [link](https://github.com/webhintio/hint/blob/HEAD/path-to-file/file.md) | ||
* * [link]: https://github.com/webhintio/hint/blob/HEAD/path-to-file/file.md | ||
* * [link]:https://github.com/webhintio/hint/blob/HEAD/path-to-file/file.md | ||
* | ||
* The \.? allow us to also match "../" | ||
*/ | ||
const mdLinkRegex = /(\s|:|\()\.?\.\/(\S*?)\.md/gi; | ||
const mdLinkRegex = /(]:\s*|]\()(\.?\.\/|https:\/\/github.com\/webhintio\/hint\/blob\/HEAD\/(packages\/)?)(\S*?)\.md/gi; | ||
const isIndex = filePath.toLowerCase().endsWith('index.md'); | ||
let transformed = content; | ||
let val; | ||
|
@@ -564,14 +569,25 @@ const updateMarkdownlinks = (content, filePath) => { | |
val[0].replace(/(index|readme)\.md/i, '') : | ||
val[0].replace('.md', '/'); | ||
|
||
/* | ||
* An github url is found for a md file. | ||
* In this case we need to replace it with the a valid | ||
* url in the website. | ||
*/ | ||
if (val[2].startsWith('https')) { | ||
replacement = | ||
`${val[1]}/docs/${file.frontMatter.section}${file.frontMatter.tocTitle ? `/${file.frontMatter.tocTitle.replace(' ', '-')}` : ''}/${val[4].replace('/docs/', '/')}/`; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we could document what the different |
||
transformed = transformed.replace(val[0], replacement); | ||
} | ||
/** | ||
* If val[0] contains './docs/ then, it is part of a multi-hint hint, so | ||
* we need to ignore it. | ||
* Later in the the `link-filter.js`, the link will be replaced for the final one. | ||
*/ | ||
if (!val[0].includes('./docs/')) { | ||
/** | ||
* `val[1] is the first capturing group. It could be "\s", ":", or "(" | ||
* `val[1] is the first capturing group. It could be "]:\s", "]:", or "](" | ||
* and it's part of the matched value so we need to add it at the beginning as well. E.g.: | ||
* | ||
* * `[events](./events.md)` will match `(./events.md` that needs to be transformed into `(../events/`. | ||
|
@@ -595,7 +611,7 @@ const updateLinks = (files) => { | |
return; | ||
} | ||
|
||
file.content = updateMarkdownlinks(file.content, file.orig || file.dest); | ||
file.content = updateMarkdownlinks(file); | ||
}); | ||
}; | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a bit weird to say the link is for github and then check just for https.