11import type { Config } from "@docusaurus/types" ;
22import type { Root } from "mdast" ;
3- import { relative , resolve } from "path" ;
3+ import { dirname , relative , resolve } from "path" ;
44import { themes } from "prism-react-renderer" ;
5- import * as unified from "unified" ;
5+ import type { Transformer } from "unified" ;
66import { visit } from "unist-util-visit" ;
7+ import { createRequire } from "node:module" ;
8+ import { fileURLToPath } from "node:url" ;
9+
10+ const require = createRequire ( import . meta. url ) ;
711
812/**
913 * Files within /docs reference repository directories
@@ -17,24 +21,27 @@ import { visit } from "unist-util-visit";
1721 * - Try resolving it relative to repo root.
1822 * - If anywhere but /docs - link to GitHub.
1923 */
20- function remarkPluginFixLinksToRepositoryArtifacts ( ) {
21- const transformer : unified . Transformer < Root > = async ( ast , file ) => {
24+ function remarkPluginFixLinksToRepositoryArtifacts ( ) : Transformer < Root > {
25+ return ( ast , file ) => {
2226 visit ( ast , "link" , ( node ) => {
23- const link = node . url ;
24- if ( link . startsWith ( "http://" ) || link . startsWith ( "https://" ) ) {
27+ const { url } = node ;
28+ if ( url . startsWith ( "http://" ) || url . startsWith ( "https://" ) ) {
2529 return ;
2630 }
2731
2832 // Docusaurus runs this plugin on its intermediate
2933 // markdown representaiton as well as on our original files.
3034 // These are relative links that docusaurus already figured out
3135 // based on realative links to .md files
32- if ( link . startsWith ( "/docs/" ) ) {
36+ if ( url . startsWith ( "/docs/" ) ) {
3337 return ;
3438 }
3539
36- const repoRoot = resolve ( __dirname , "../.." ) ;
37- const artifact = resolve ( file . dirname ! , link ) ;
40+ const repoRoot = resolve (
41+ dirname ( fileURLToPath ( import . meta. url ) ) ,
42+ "../.." ,
43+ ) ;
44+ const artifact = resolve ( file . dirname ! , url ) ;
3845 const artifactRelative = relative ( repoRoot , artifact ) ;
3946
4047 // We host all files under docs, will resolve as a relative link
@@ -49,7 +56,6 @@ function remarkPluginFixLinksToRepositoryArtifacts() {
4956 node . url = linkToRepositoryArtifact ;
5057 } ) ;
5158 } ;
52- return transformer ;
5359}
5460
5561const config : Config = {
0 commit comments