Skip to content

Commit

Permalink
WIP fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharyblasczyk committed Oct 12, 2024
1 parent 7e6faed commit 9e6b0d0
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 63 deletions.
77 changes: 76 additions & 1 deletion apps/docs/.remarkrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,78 @@
import fs from "fs";
import path from "path";
import remarkMdx from "remark-mdx";
import remarkParse from "remark-parse";
import { unified } from "unified";
import { visit } from "unist-util-visit";

const validateInternalLinks = () => {
return async function transformer(tree, file) {
const fileDir = path.dirname(file.path);

const resolveFilePath = (basePath) =>
basePath.startsWith("/")
? path.resolve(process.cwd(), "pages", `${basePath.slice(1)}.mdx`)
: path.resolve(fileDir, `${basePath}.mdx`);

const hasValidFragment = (ast, fragment) => {
const isHeadingNode = (node) => node.type === "heading";
const isTextNode = (child) => child.type === "text";
const normalizeText = (text) =>
text.trim().replace(/\s+/g, "-").toLowerCase();

return ast.children?.some((node) => {
if (isHeadingNode(node))
return node.children?.some(
(child) =>
isTextNode(child) && normalizeText(child.value) === fragment,
);
return false;
});
};

const validateLink = async (url) => {
if (url.startsWith("http://") || url.startsWith("https://")) return;

const [basePath, fragment] = url.split("#");
const resolvedPath = resolveFilePath(basePath);

if (!fs.existsSync(resolvedPath))
throw new Error(`File not found for ${basePath}. URL: ${url}`);

if (!fragment) return;

const fileContent = fs.readFileSync(resolvedPath, "utf-8");
const ast = await unified()
.use(remarkParse)
.use(remarkMdx)
.parse(fileContent);

if (!hasValidFragment(ast, fragment))
throw new Error(`Fragment "${fragment}" not found in ${url}`);
};

visit(tree, "link", (node) => validateLink(node.url));

visit(tree, "mdxJsxFlowElement", (node) => {
const hrefAttr = node.attributes?.find((attr) => attr.name === "href");
if (hrefAttr?.value) validateLink(hrefAttr.value);
});
};
};

export default {
plugins: ["remark-lint", "remark-lint-mdx"],
plugins: [
"remark-preset-lint-recommended",
"remark-frontmatter",
"remark-lint",
"remark-mdx",
"remark-lint-are-links-valid",
"remark-lint-no-dead-urls",
"remark-lint-no-undefined-references",
validateInternalLinks,
],
settings: {
atxHeadingWithMarker: false,
headingStyle: "atx",
},
};
50 changes: 0 additions & 50 deletions apps/docs/.remarkrc.mjs

This file was deleted.

2 changes: 1 addition & 1 deletion apps/docs/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import reactConfig from "@ctrlplane/eslint-config/react";
/** @type {import('typescript-eslint').Config} */
export default [
{
ignores: [".next/**", "out/**", ".remarkrc.mjs"],
ignores: [".next/**", "out/**", ".remarkrc.js"],
},
...baseConfig,
...reactConfig,
Expand Down
6 changes: 3 additions & 3 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
"dev": "next dev -p 3001",
"build": "next build",
"start": "next start -p 3001",
"lint": "eslint && pnpm check-links",
"lint": "eslint",
"lint:mdx": "remark \"pages/**/*.mdx\" --frail",
"build:docker": "docker build -f apps/docs/Dockerfile -t docs .",
"format": "prettier --check . --ignore-path ../../.gitignore",
"typecheck": "tsc --noEmit --emitDeclarationOnly false",
"lint:mdx": "npx tsc .remarkrc.ts && remark . --frail"
"typecheck": "tsc --noEmit --emitDeclarationOnly false"
},
"dependencies": {
"@ctrlplane/ui": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/pages/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ setup more efficient, secure, and easy to manage
<Cards.Card
icon={<TbServer className="h-8 w-8 stroke-yellow-400" />}
title="Core Concepts"
href="/core-concepts/notathing/systems/fail"
href="/core-concepts/systems"
/>
<Cards.Card
icon={<TbPlug className="h-8 w-8 stroke-purple-400" />}
Expand Down
4 changes: 2 additions & 2 deletions apps/docs/pages/integrations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import { SiGithub, SiGooglecloud, SiKubernetes } from "react-icons/si";
<Cards.Card
icon={<SiGooglecloud className="h-8 w-8" />}
title="Google Cloud"
href="/integrations/google"
href="/integrations/google-cloud/compute-scanner"
/>
<Cards.Card
icon={<SiKubernetes className="h-8 w-8" />}
title="Kubernetes"
href="/integrations/kubernetes"
href="/integrations/kubernetes/jobs-agent"
/>
</Cards>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ the official Terraform/Opentofu module. You can customize it to accommodate your
needs.

If you cannot use the Terraform module, you can install Ctrlplane manually to a
GKE cluster and use the [Helm Chart](../methods/kubernetes.mdx) based install.
GKE cluster and use the [Helm Chart](../methods/kubernetes) based install.

### Using Terraform

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json",
"module": "esnext"
},
"include": [".", ".next/types/**/*.ts", ".remarkrc.mjs"],
"include": [".", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
IconReload,
} from "@tabler/icons-react";

import { Deployment } from "@ctrlplane/db/schema";
import type { Deployment } from "@ctrlplane/db/schema";
import {
AlertDialog,
AlertDialogAction,
Expand Down
2 changes: 1 addition & 1 deletion apps/webshell-router/src/routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const onConnect = async (ws: WebSocket, request: IncomingMessage) => {
};

export const addSocket = (expressApp: Express) => {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
const server = createServer(expressApp);
const wss = new WebSocketServer({ noServer: true });

Expand Down
6 changes: 5 additions & 1 deletion turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@
"outputLogs": "new-only"
},
"lint": {
"dependsOn": ["^topo", "^build"],
"dependsOn": ["^topo", "^build", "lint:mdx"],
"outputs": ["node_modules/.cache/.eslintcache"]
},
"lint:mdx": {
"dependsOn": ["^topo", "^build"],
"cache": true
},
"typecheck": {
"dependsOn": ["^topo", "^build"],
"outputs": ["node_modules/.cache/tsbuildinfo.json"]
Expand Down

0 comments on commit 9e6b0d0

Please sign in to comment.