This repository was archived by the owner on Apr 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
[HOUSEKEEPING] Finding broken links in md files and fix them #432
Merged
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
98bc86a
[HOUSEKEEPING] Finding broken links in md files and fix them
dennisseah 5a5ac78
Merge branch 'master' into brokenLinks
dennisseah 2abd364
Merge branch 'master' into brokenLinks
dennisseah 2b34be7
Merge branch 'master' into brokenLinks
dennisseah 6621cd9
using markdown-link-check
dennisseah 942bd60
Merge branch 'brokenLinks' of https://github.com/CatalystCode/spk int…
dennisseah 521d895
update md-lint
dennisseah 717004b
Update azure-pipelines.yml
dennisseah 036d15d
Merge branch 'master' into brokenLinks
dennisseah dd82f23
Merge branch 'master' into brokenLinks
yradsmikham 8fc4dc3
script is not needed because we do not support windows runtime
dennisseah 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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| // DISCLAIMER: Only test this tool on mac | ||
| // There may be some false negative results | ||
|
|
||
| import fs from "fs"; | ||
| import path from "path"; | ||
| import axios from "axios"; | ||
|
|
||
| const urlExists = async (url: string): Promise<boolean> => { | ||
| try { | ||
| const res = await axios.head(url); | ||
| return res.status === 200; | ||
| } catch (_) { | ||
| return false; | ||
| } | ||
| }; | ||
|
|
||
| const regex = /\[[^[]+?\]\(([^(]+?)\)/g; | ||
|
|
||
| // get sub folders under commands folder. | ||
| const getMarkdownFiles = (curDir: string, mds: string[]): void => { | ||
| fs.readdirSync(curDir).forEach(f => { | ||
| const p = path.join(curDir, f); | ||
| if (fs.lstatSync(p).isDirectory()) { | ||
| getMarkdownFiles(p, mds); | ||
| } else if (p.endsWith(".md")) { | ||
| mds.push(p); | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
| const testFile = (folder: string, link: string): boolean => { | ||
| const arr = link.split(" "); | ||
| const target = arr[0].replace(/#.+/, ""); | ||
| return fs.existsSync(folder + "/" + target); | ||
| }; | ||
|
|
||
| const testLink = async ( | ||
| file: string, | ||
| folder: string, | ||
| link: string | ||
| ): Promise<void> => { | ||
| if (link.startsWith("#")) { | ||
| return; | ||
| } | ||
| let ok = false; | ||
| if (link.startsWith("./")) { | ||
| ok = testFile(folder, link.substring(2)); | ||
| } | ||
| if (!link.startsWith("https://") && !link.startsWith("http://")) { | ||
| ok = testFile(folder, link); | ||
| } | ||
| if (link.startsWith("https://") || link.startsWith("http://")) { | ||
| ok = await urlExists(link); | ||
| } | ||
| if (!ok) { | ||
| console.log(`${file}: ${link}`); | ||
| } | ||
| }; | ||
|
|
||
| (async (): Promise<void> => { | ||
| const dir = path.join(process.cwd(), "guides"); | ||
| const mdFiles: string[] = []; | ||
| getMarkdownFiles(dir, mdFiles); | ||
| const promises: Promise<void>[] = []; | ||
|
|
||
| mdFiles.forEach(f => { | ||
| const folder = f.substring(0, f.lastIndexOf("/")); | ||
| let content = fs.readFileSync(f, "utf-8"); | ||
| content = content.replace(/\n/g, " "); | ||
|
|
||
| let m = regex.exec(content); | ||
| while (m) { | ||
| const target = m[1]; | ||
| promises.push(testLink(f, folder, target)); | ||
| m = regex.exec(content); | ||
| } | ||
| }); | ||
|
|
||
| Promise.all(promises); | ||
| })(); | ||
This file contains hidden or 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
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.