Skip to content

Commit

Permalink
fix: notice tag links
Browse files Browse the repository at this point in the history
  • Loading branch information
Ballonek committed Oct 1, 2024
1 parent ef89b39 commit 6ea9df6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
13 changes: 4 additions & 9 deletions .github/actions/validate-docs-links/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87612,7 +87612,7 @@ async function getAllMdxFilePaths(basePath) {
return allRoutes;
}
// Returns the slugs of all headings in a tree
function getHeadingsFromMarkdownTree(tree) {
function getHeadingsFromMarkdownTree(tree, test) {
const headings = [];
slugger.reset();
lib_visit(tree, "heading", (node) => {
Expand All @@ -87624,7 +87624,7 @@ function getHeadingsFromMarkdownTree(tree) {
headingText += node.value;
}
});
headings.push(slugger.slug(headingText));
headings.push(slugger.slug(headingText.trim()));
});
return headings;
}
Expand Down Expand Up @@ -87654,7 +87654,7 @@ async function prepareDocumentMapEntry(route, setFailed) {
const mdxContent = await promises_default().readFile(route.source, "utf8");
const { content, data } = gray_matter_default()(mdxContent);
const tree = markdownProcessor.parse(content);
const headings = getHeadingsFromMarkdownTree(tree);
const headings = getHeadingsFromMarkdownTree(tree, route.source.includes("/learn/filtering_and_sorting/filter_expression_reference"));
return [
route.slug,
{
Expand Down Expand Up @@ -87689,9 +87689,7 @@ function validateInternalLink(errors, href) {
errors.link.push(href);
}
else if (hash && !EXCLUDED_HASHES.includes(hash)) {
// remove all "-" from end of the hash
const transformedHash = hash.replace(/-+$/, "");
const hashFound = foundPage.headings.includes(transformedHash);
const hashFound = foundPage.headings.includes(hash);
if (!hashFound) {
errors.hash.push(href);
}
Expand Down Expand Up @@ -87738,9 +87736,6 @@ function traverseTreeAndValidateLinks(tree, doc, setFailed) {
// Check if the link is an internal link and not ending with a file extension
if (href.startsWith(RELATIVE_PATH)) {
if (!/^.*\.[^\\]+$/.test(href)) {
if (href.includes("contains")) {
console.dir({ node }, { depth: 10 });
}
validateInternalLink(errors, href);
}
}
Expand Down
16 changes: 5 additions & 11 deletions .github/actions/validate-docs-links/src/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ async function getAllMdxFilePaths(basePath: string): Promise<RouteFragment[]> {
}

// Returns the slugs of all headings in a tree
function getHeadingsFromMarkdownTree(tree: Node): string[] {
function getHeadingsFromMarkdownTree(tree: Node, test:boolean): string[] {
const headings: string[] = [];
slugger.reset();

Expand All @@ -144,7 +144,7 @@ function getHeadingsFromMarkdownTree(tree: Node): string[] {
headingText += node.value;
}
});
headings.push(slugger.slug(headingText));
headings.push(slugger.slug(headingText.trim()));
});

return headings;
Expand Down Expand Up @@ -181,7 +181,7 @@ async function prepareDocumentMapEntry(
const mdxContent = await fs.readFile(route.source, "utf8");
const { content, data } = matter(mdxContent);
const tree = markdownProcessor.parse(content);
const headings = getHeadingsFromMarkdownTree(tree);
const headings = getHeadingsFromMarkdownTree(tree, route.source.includes("/learn/filtering_and_sorting/filter_expression_reference"));

return [
route.slug,
Expand Down Expand Up @@ -218,10 +218,8 @@ function validateInternalLink(errors: Errors, href: string): void {
if (!foundPage) {
errors.link.push(href);
} else if (hash && !EXCLUDED_HASHES.includes(hash)) {
// remove all "-" from end of the hash
const transformedHash = hash.replace(/-+$/, "");
const hashFound = foundPage.headings.includes(transformedHash);

const hashFound = foundPage.headings.includes(hash);

if (!hashFound) {
errors.hash.push(href);
}
Expand Down Expand Up @@ -282,10 +280,6 @@ function traverseTreeAndValidateLinks(
// Check if the link is an internal link and not ending with a file extension
if (href.startsWith(RELATIVE_PATH)) {
if (!/^.*\.[^\\]+$/.test(href)) {
if(href.includes("contains")) {
console.dir({node}, {depth: 10})
}


validateInternalLink(errors, href);
}
Expand Down

0 comments on commit 6ea9df6

Please sign in to comment.