11import fs from 'node:fs' ;
22import path from 'node:path' ;
3+ import { fileURLToPath } from 'node:url' ;
34import container from 'markdown-it-container' ;
45import markdownItAttrs from 'markdown-it-attrs' ;
6+ import { defineConfig } from 'vitepress' ;
7+ import type { MarkdownItAsync } from 'markdown-it-async' ;
8+ import type { RenderRule } from 'markdown-it/lib/renderer.mjs' ;
9+ type ContainerArguments = [
10+ typeof container ,
11+ string ,
12+ {
13+ render : RenderRule ,
14+ marker ?: string ;
15+ }
16+ ] ;
517
6- const getChildrenRules = ( directoryName ) => {
7- const rules = fs . readdirSync ( path . resolve ( __dirname , `../rules/${ directoryName } ` ) ) ;
18+ const currentDirectory = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
19+ const getChildrenRules = ( directoryName : string ) => {
20+ const rules = fs . readdirSync ( path . resolve ( currentDirectory , `../rules/${ directoryName } ` ) ) ;
821 const items = [ ] ;
922 for ( const rule of rules ) {
1023 const ruleName = rule . replace ( '.md' , '' ) ;
@@ -17,12 +30,12 @@ const getChildrenRules = (directoryName) => {
1730} ;
1831
1932const getRules = ( ) => {
20- const rulesFolderContent = fs . readdirSync ( path . resolve ( __dirname , '../rules' ) ) ;
33+ const rulesFolderContent = fs . readdirSync ( path . resolve ( currentDirectory , '../rules' ) ) ;
2134
2235 const items = [ ] ;
2336 for ( const item of rulesFolderContent ) {
2437 // Process directories only
25- if ( ! fs . lstatSync ( path . resolve ( __dirname , `../rules/${ item } ` ) ) . isDirectory ( ) ) {
38+ if ( ! fs . lstatSync ( path . resolve ( currentDirectory , `../rules/${ item } ` ) ) . isDirectory ( ) ) {
2639 continue ;
2740 }
2841
@@ -35,20 +48,24 @@ const getRules = () => {
3548 return items ;
3649} ;
3750
38- const createRuleContainer = function ( klass , defaultTitle , md ) {
51+ const createRuleContainer = function (
52+ className : string ,
53+ defaultTitle : string ,
54+ md : MarkdownItAsync
55+ ) : ContainerArguments {
3956 return [
4057 container ,
41- klass ,
58+ className ,
4259 {
4360 render ( tokens , index ) {
4461 const token = tokens [ index ] ;
4562 const info = token . info
4663 . trim ( )
47- . slice ( klass . length )
64+ . slice ( className . length )
4865 . trim ( ) ;
4966 if ( token . nesting === 1 ) {
5067 const title = md . renderInline ( info || defaultTitle ) ;
51- return `<div class="${ klass } rule-container custom-block"><p class="rule-block-title">${ title } </p>\n` ;
68+ return `<div class="${ className } rule-container custom-block"><p class="rule-block-title">${ title } </p>\n` ;
5269 }
5370 return '</div>\n' ;
5471 } ,
@@ -57,20 +74,24 @@ const createRuleContainer = function (klass, defaultTitle, md) {
5774 ] ;
5875} ;
5976
60- const createExampleContainer = function ( klass , defaultTitle , md ) {
77+ const createExampleContainer = function (
78+ className : string ,
79+ defaultTitle : string ,
80+ md : MarkdownItAsync
81+ ) : ContainerArguments {
6182 return [
6283 container ,
63- klass ,
84+ className ,
6485 {
6586 render ( tokens , index ) {
6687 const token = tokens [ index ] ;
6788 const info = token . info
6889 . trim ( )
69- . slice ( klass . length )
90+ . slice ( className . length )
7091 . trim ( ) ;
7192 if ( token . nesting === 1 ) {
7293 const title = md . renderInline ( info || defaultTitle ) ;
73- return `<div class="${ klass } custom-block"><p class="custom-block-title">${ title } </p>\n` ;
94+ return `<div class="${ className } custom-block"><p class="custom-block-title">${ title } </p>\n` ;
7495 }
7596 return '</div>\n' ;
7697 } ,
@@ -134,17 +155,18 @@ const getSidebarData = () => {
134155 ] ;
135156} ;
136157
137- export default {
158+ const config = defineConfig ( {
138159 title : 'Documentation' ,
139160 description : 'Documentation for PHPTaqwim' ,
140161 base : '/docs/' ,
162+ cleanUrls : true ,
141163 themeConfig : {
142164 siteTitle : 'PHPTaqwim' ,
143165 logo : './logo.png' ,
144166 outline : [ 2 , 4 ] ,
145- lastUpdated : true ,
146- cleanUrls : 'without-subfolders ' ,
147-
167+ lastUpdated : {
168+ text : 'Last Updated ' ,
169+ } ,
148170 socialLinks : [
149171 {
150172 icon : 'github' ,
@@ -195,4 +217,6 @@ export default {
195217 . use ( markdownItAttrs ) ;
196218 } ,
197219 } ,
198- } ;
220+ } ) ;
221+
222+ export default config ;
0 commit comments