11import type { Config } from "@docusaurus/types" ;
22import type { Root } from "mdast" ;
3- import { dirname , relative , resolve } from "path" ;
3+ import { createRequire } from "node:module" ;
4+ import { fileURLToPath } from "node:url" ;
5+ import { dirname , extname , relative , resolve } from "path" ;
46import { themes } from "prism-react-renderer" ;
57import type { Transformer } from "unified" ;
68import { visit } from "unist-util-visit" ;
7- import { createRequire } from "node:module" ;
8- import { fileURLToPath } from "node:url" ;
99
1010const require = createRequire ( import . meta. url ) ;
1111
12- const userRelative = "packages/cursorless-org-docs/src/docs/user " ;
13- const contributingRelative =
14- "packages/cursorless-org-docs/src/docs/ contributing";
12+ const docsRelative = "packages/cursorless-org-docs/src/docs/" ;
13+ const userRelative = docsRelative + "user" ;
14+ const contributingRelative = docsRelative + " contributing";
1515const repoLink = "https://github.com/cursorless-dev/cursorless/tree/main/" ;
1616
1717/**
@@ -51,14 +51,16 @@ function remarkPluginFixLinksToRepositoryArtifacts(): Transformer<Root> {
5151 const fileRelative = relative ( repoRoot , file . path ) . replace ( / \\ / g, "/" ) ;
5252
5353 // We host all files under docs. Will resolve as a relative link, but
54- // relative links passing between user and contributing are not resolved
55- // correctly by docusaurus. So we need to rewrite them.
56- if (
57- ( artifactRelative . startsWith ( userRelative ) &&
58- fileRelative . startsWith ( userRelative ) ) ||
59- ( artifactRelative . startsWith ( contributingRelative ) &&
60- fileRelative . startsWith ( contributingRelative ) )
61- ) {
54+ // relative links pointing to a folder passing between user and
55+ // contributing are not resolved correctly by docusaurus so we need to
56+ // rewrite them.
57+ if ( artifactRelative . startsWith ( docsRelative ) ) {
58+ if (
59+ isFolder ( url ) &&
60+ passingBetweenUserAndContributing ( fileRelative , artifactRelative )
61+ ) {
62+ node . url = "/docs/" + artifactRelative . slice ( docsRelative . length ) ;
63+ }
6264 return ;
6365 }
6466
@@ -67,6 +69,19 @@ function remarkPluginFixLinksToRepositoryArtifacts(): Transformer<Root> {
6769 } ;
6870}
6971
72+ function isFolder ( url : string ) {
73+ return ! extname ( url ) ;
74+ }
75+
76+ function passingBetweenUserAndContributing (
77+ fileRelative : string ,
78+ artifactRelative : string ,
79+ ) : boolean {
80+ return fileRelative . startsWith ( userRelative )
81+ ? ! artifactRelative . startsWith ( userRelative )
82+ : ! artifactRelative . startsWith ( contributingRelative ) ;
83+ }
84+
7085const config : Config = {
7186 title : "Cursorless" ,
7287 tagline : "Structural voice coding at the speed of thought" ,
0 commit comments