-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
link to examples in concepts pages (#7753)
- Loading branch information
jamiedemaria
committed
May 10, 2022
1 parent
b0e3ca2
commit 35a198b
Showing
15 changed files
with
209 additions
and
21 deletions.
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
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
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
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
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
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
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import fs, { link } from "fs"; | ||
import path from "path"; | ||
import fg from "fast-glob"; | ||
import { Node } from "hast"; | ||
import visit from "unist-util-visit"; | ||
import matter from "gray-matter"; | ||
|
||
// remark | ||
import mdx from "remark-mdx"; | ||
import remark from "remark"; | ||
|
||
const ROOT_DIR = path.resolve(__dirname, "../../"); | ||
const DOCS_DIR = path.resolve(ROOT_DIR, "content"); | ||
const DAGSTER_DIR = path.resolve(ROOT_DIR, "..") | ||
interface LinkElement extends Node { | ||
type: "link" | "image"; | ||
url: string; | ||
} | ||
|
||
|
||
test("No dead external MDX links", async () => { | ||
const allMdxFilePaths = await fg(["**/*.mdx"], { cwd: DOCS_DIR }); | ||
|
||
const astStore: { [filePath: string]: Node } = {}; | ||
const allExternalLinksStore: { [filePath: string]: Array<string> } = {}; | ||
|
||
// Parse mdx files to find all internal links and populate the store | ||
await Promise.all( | ||
allMdxFilePaths.map(async (relativeFilePath) => { | ||
const absolutePath = path.resolve(DOCS_DIR, relativeFilePath); | ||
const fileContent = await fs.promises.readFile(absolutePath, "utf-8"); | ||
// separate content and front matter data | ||
const { content, data } = matter(fileContent); | ||
astStore[relativeFilePath] = remark().use(mdx).parse(content); | ||
}) | ||
); | ||
|
||
for (const filePath in astStore) { | ||
const externalLinks = collectExternalLinks(astStore[filePath]); | ||
allExternalLinksStore[filePath] = externalLinks; | ||
} | ||
|
||
const deadLinks: Array<{ sourceFile: string; deadLink: string }> = []; | ||
|
||
let linkCount = 0; | ||
|
||
for (const source in allExternalLinksStore) { | ||
const linkList = allExternalLinksStore[source]; | ||
|
||
for (const link of linkList) { | ||
linkCount++; | ||
if (!isLinkLegit(link)) { | ||
deadLinks.push({ | ||
sourceFile: path.resolve(DOCS_DIR, source), | ||
deadLink: link, | ||
}); | ||
} | ||
} | ||
} | ||
|
||
// Sanity check to make sure the parser is working | ||
expect(linkCount).toBeGreaterThan(0); | ||
|
||
expect(deadLinks).toEqual([]); | ||
}); | ||
|
||
|
||
function isLinkLegit( | ||
rawTarget: string, | ||
): boolean { | ||
// TODO: Validate links to API Docs | ||
|
||
const splitter = new RegExp('\/master\/') | ||
|
||
const filePath = rawTarget.split(splitter)[1] | ||
|
||
return fileExists(path.resolve(DAGSTER_DIR, filePath)) | ||
} | ||
|
||
// traverse the mdx ast to find all links to our examples | ||
function collectExternalLinks( | ||
tree: Node, | ||
): Array<string> { | ||
const externalLinkRegex = /^(https?:\/\/github\.com\/dagster\-io\/dagster\/.*\/master)/; | ||
const result: Array<string> = []; | ||
|
||
visit(tree, ["link", "image"], (node: LinkElement, index) => { | ||
const { url } = node; | ||
if (url.match(externalLinkRegex)) { | ||
result.push(url); | ||
} else { | ||
return; | ||
} | ||
}); | ||
|
||
return result; | ||
} | ||
|
||
function fileExists(filePath: string): boolean { | ||
|
||
try { | ||
fs.statSync(filePath); | ||
return true; | ||
} catch (_) { | ||
return false; | ||
} | ||
} |
Empty file.
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
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
35a198b
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.
Successfully deployed to the following URLs:
dagster – ./docs/next
dagster.vercel.app
dagster-git-master-elementl.vercel.app
docs.dagster.io
dagster-elementl.vercel.app
new-docs.dagster.io