11import fs from 'node:fs'
22import path from 'node:path'
3- import { rehypeHeadingIds } from '@astrojs/markdown-remark'
43import mdx from '@astrojs/mdx'
54import sitemap from '@astrojs/sitemap'
65import type { AstroIntegration } from 'astro'
7- import autoImport from 'astro-auto-import'
8- import type { Element , Text } from 'hast'
9- import rehypeAutolinkHeadings from 'rehype-autolink-headings'
106import { getConfig } from './config'
11- import { rehypeBsTable } from './rehype'
12- import { remarkBsComp , remarkBsConfig , remarkBsDocsref } from './remark'
137import { configurePrism } from './prism'
148import {
15- docsDirectory ,
169 getDocsFsPath ,
1710 getDocsPublicFsPath ,
1811 getDocsStaticFsPath ,
1912 validateVersionedDocsPaths
2013} from './path'
2114
22- // A list of directories in `src/components` that contains components that will be auto imported in all pages for
23- // convenience.
24- // Note: adding a new component to one of the existing directories requires a restart of the dev server.
25- const autoImportedComponentDirectories = [ 'shortcodes' ]
26-
2715// A list of static file paths that will be aliased to a different path.
2816const staticFileAliases = {
2917 '/orange/docs/[version]/assets/img/favicons/apple-touch-icon.png' : '/apple-touch-icon.png' ,
@@ -48,44 +36,18 @@ const sitemapExcludes = [
4836 `/${ getConfig ( ) . brand } /docs/${ getConfig ( ) . docs_version } /about`
4937]
5038
51- const headingsRangeRegex = new RegExp ( `^h[${ getConfig ( ) . anchors . min } -${ getConfig ( ) . anchors . max } ]$` )
52-
5339export function oudsWeb ( ) : AstroIntegration [ ] {
5440 const sitemapExcludedUrls = sitemapExcludes . map ( ( url ) => `${ getConfig ( ) . baseURL } ${ url } /` )
5541
5642 configurePrism ( )
5743
5844 return [
59- ouds_web_auto_import ( ) ,
6045 {
6146 name : 'ouds-web-integration' ,
6247 hooks : {
63- 'astro:config:setup' : ( { addWatchFile, updateConfig } ) => {
48+ 'astro:config:setup' : ( { addWatchFile } ) => {
6449 // Reload the config when the integration is modified.
6550 addWatchFile ( path . join ( getDocsFsPath ( ) , 'src/libs/astro.ts' ) )
66-
67- // Add the remark and rehype plugins.
68- updateConfig ( {
69- markdown : {
70- rehypePlugins : [
71- rehypeHeadingIds ,
72- [
73- rehypeAutolinkHeadings ,
74- {
75- behavior : 'append' ,
76- content : [ { type : 'text' , value : ' ' } ] ,
77- properties : ( element : Element ) => ( {
78- class : 'anchor-link' ,
79- ariaLabel : `Link to this section: ${ ( element . children [ 0 ] as Text ) . value } `
80- } ) ,
81- test : ( element : Element ) => element . tagName . match ( headingsRangeRegex )
82- }
83- ] ,
84- rehypeBsTable
85- ] ,
86- remarkPlugins : [ remarkBsConfig , remarkBsDocsref , remarkBsComp ]
87- }
88- } )
8951 } ,
9052 'astro:config:done' : ( ) => {
9153 cleanPublicDirectory ( )
@@ -107,51 +69,6 @@ export function oudsWeb(): AstroIntegration[] {
10769 ]
10870}
10971
110- function ouds_web_auto_import ( ) {
111- const autoImportedComponents : string [ ] = [ ]
112- const autoImportedComponentDefinitions : string [ ] = [ ]
113-
114- for ( const autoImportedComponentDirectory of autoImportedComponentDirectories ) {
115- const components = fs . readdirSync ( path . join ( getDocsFsPath ( ) , 'src/components' , autoImportedComponentDirectory ) , {
116- withFileTypes : true
117- } )
118-
119- for ( const component of components ) {
120- if ( component . isFile ( ) ) {
121- autoImportedComponents . push (
122- `./${ path . posix . join ( docsDirectory , 'src/components' , autoImportedComponentDirectory , component . name ) } `
123- )
124-
125- if ( component . name . endsWith ( '.astro' ) ) {
126- autoImportedComponentDefinitions . push (
127- `export const ${ component . name . replace ( '.astro' , '' ) } : typeof import('@shortcodes/${
128- component . name
129- } ').default`
130- )
131- }
132- }
133- }
134- }
135-
136- const autoImportedComponentDefinition = `/**
137- * DO NOT EDIT THIS FILE MANUALLY.
138- *
139- * This file is automatically generated by the Bootstrap Astro Integration.
140- * It contains the type definitions for the components that are auto imported in all pages.
141- * @see site/src/libs/astro.ts
142- */
143- export declare global {
144- ${ autoImportedComponentDefinitions . join ( '\n ' ) }
145- }
146- `
147-
148- fs . writeFileSync ( path . join ( getDocsFsPath ( ) , 'src/types/auto-import.d.ts' ) , autoImportedComponentDefinition )
149-
150- return autoImport ( {
151- imports : autoImportedComponents
152- } )
153- }
154-
15572function cleanPublicDirectory ( ) {
15673 fs . rmSync ( getDocsPublicFsPath ( ) , { force : true , recursive : true } )
15774}
0 commit comments