@@ -3,22 +3,26 @@ import path from 'node:path';
3
3
import { fileURLToPath } from 'node:url' ;
4
4
import { rehypeHeadingIds } from '@astrojs/markdown-remark' ;
5
5
import remarkWikiLink from "@braindb/remark-wiki-link" ;
6
- import expressiveCode from 'astro-expressive-code' ;
6
+ // import expressiveCode from 'astro-expressive-code';
7
7
import icon from 'astro-icon' ;
8
8
import { defineConfig } from 'astro/config' ;
9
9
import fontCarrier from 'font-carrier' ;
10
10
// Others
11
11
// import { visualizer } from 'rollup-plugin-visualizer'
12
- import rehypeKatex from 'rehype-katex'
13
- import remarkBreaks from 'remark-breaks'
12
+ import rehypeKatex from 'rehype-katex' ;
13
+ import remarkBreaks from 'remark-breaks' ;
14
14
import remarkMath from 'remark-math' ;
15
15
16
+
17
+
16
18
import AstroPureIntegration from './packages/pure/index.ts' ;
17
19
// Local integrations
18
20
// Local rehype & remark plugins
19
21
import rehypeAutolinkHeadings from './src/plugins/rehype-auto-link-headings.ts' ;
20
22
import { remarkAiNotice } from './src/plugins/remark-ai-notice.mjs' ;
21
23
import { remarkMermaid } from './src/plugins/remark-mermaid' ;
24
+ // Shiki
25
+ import { addCopyButton , addLanguage , addTitle , transformerNotationDiff , transformerNotationHighlight , updateStyle } from './src/plugins/shiki-transformers.ts' ;
22
26
import config from './src/site.config.ts' ;
23
27
24
28
@@ -27,70 +31,71 @@ const createFontSubsetIntegration = () => {
27
31
name : 'font-subset-integration' ,
28
32
hooks : {
29
33
'astro:server:start' : ( ) => {
30
- const projectRoot = process . cwd ( ) ;
31
- const fontPath = path . join ( projectRoot , 'src' , 'assets' , 'fonts' , 'crjk03w03.ttf' ) ;
32
- const outputDir = path . join ( projectRoot , 'public' , 'fonts' ) ;
33
- const outputPath = path . join ( outputDir , 'crjk-subset.ttf' ) ;
34
+ const projectRoot = process . cwd ( )
35
+ const fontPath = path . join ( projectRoot , 'src' , 'assets' , 'fonts' , 'crjk03w03.ttf' )
36
+ const outputDir = path . join ( projectRoot , 'public' , 'fonts' )
37
+ const outputPath = path . join ( outputDir , 'crjk-subset.ttf' )
34
38
35
39
// To avoid slow startup, only copy the .ttf file in dev mode if it doesn't exist.
36
40
// The browser will show 404s for woff/woff2 but will fall back to the ttf.
37
41
if ( fs . existsSync ( outputPath ) ) {
38
- return ;
42
+ return
39
43
}
40
44
41
45
if ( ! fs . existsSync ( outputDir ) ) {
42
- fs . mkdirSync ( outputDir , { recursive : true } ) ;
46
+ fs . mkdirSync ( outputDir , { recursive : true } )
43
47
}
44
48
45
- fs . copyFileSync ( fontPath , outputPath ) ;
46
- console . log ( 'Development font .ttf copied to public/fonts!' ) ;
49
+ fs . copyFileSync ( fontPath , outputPath )
50
+ console . log ( 'Development font .ttf copied to public/fonts!' )
47
51
} ,
48
52
'astro:build:done' : async ( { dir } ) => {
49
- const projectRoot = process . cwd ( ) ;
50
- const contentDir = path . join ( projectRoot , 'src' , 'content' ) ;
51
- const pagesDir = path . join ( projectRoot , 'src' , 'pages' ) ;
52
- const fontPath = path . join ( projectRoot , 'src' , 'assets' , 'fonts' , 'crjk03w03.ttf' ) ;
53
- const outputDir = fileURLToPath ( new URL ( './fonts' , dir ) ) ;
54
- const outputPath = path . join ( outputDir , 'crjk-subset' ) ;
53
+ const projectRoot = process . cwd ( )
54
+ const contentDir = path . join ( projectRoot , 'src' , 'content' )
55
+ const pagesDir = path . join ( projectRoot , 'src' , 'pages' )
56
+ const fontPath = path . join ( projectRoot , 'src' , 'assets' , 'fonts' , 'crjk03w03.ttf' )
57
+ const outputDir = fileURLToPath ( new URL ( './fonts' , dir ) )
58
+ const outputPath = path . join ( outputDir , 'crjk-subset' )
55
59
56
60
if ( ! fs . existsSync ( outputDir ) ) {
57
- fs . mkdirSync ( outputDir , { recursive : true } ) ;
61
+ fs . mkdirSync ( outputDir , { recursive : true } )
58
62
}
59
63
60
64
function getAllFiles ( dirPath , arrayOfFiles ) {
61
- const files = fs . readdirSync ( dirPath ) ;
62
- arrayOfFiles = arrayOfFiles || [ ] ;
65
+ const files = fs . readdirSync ( dirPath )
66
+ arrayOfFiles = arrayOfFiles || [ ]
63
67
files . forEach ( function ( file ) {
64
68
if ( fs . statSync ( path . join ( dirPath , file ) ) . isDirectory ( ) ) {
65
- arrayOfFiles = getAllFiles ( path . join ( dirPath , file ) , arrayOfFiles ) ;
69
+ arrayOfFiles = getAllFiles ( path . join ( dirPath , file ) , arrayOfFiles )
66
70
} else {
67
71
if ( file . endsWith ( '.md' ) || file . endsWith ( '.mdx' ) || file . endsWith ( '.astro' ) ) {
68
- arrayOfFiles . push ( path . join ( dirPath , file ) ) ;
72
+ arrayOfFiles . push ( path . join ( dirPath , file ) )
69
73
}
70
74
}
71
- } ) ;
72
- return arrayOfFiles ;
75
+ } )
76
+ return arrayOfFiles
73
77
}
74
78
75
- const contentFiles = getAllFiles ( contentDir ) ;
76
- const pagesFiles = getAllFiles ( pagesDir ) ;
77
- const allFiles = [ ...contentFiles , ...pagesFiles ] ;
79
+ const contentFiles = getAllFiles ( contentDir )
80
+ const pagesFiles = getAllFiles ( pagesDir )
81
+ const allFiles = [ ...contentFiles , ...pagesFiles ]
78
82
79
- const noticeTextForSubsetting = 'AI-Assisted Content This article is AI-assisted, and the author has strived for accuracy. Please use with discretion. Posted today Posted 1 day ago Posted {days} days ago 本文由AI辅助生成,作者已尽力确保内容准确,请谨慎参考 发布于今天 发布于 1 天前 发布于 {days} 天前' ;
80
- let allText = noticeTextForSubsetting ;
83
+ const noticeTextForSubsetting =
84
+ 'AI-Assisted Content This article is AI-assisted, and the author has strived for accuracy. Please use with discretion. Posted today Posted 1 day ago Posted {days} days ago 本文由AI辅助生成,作者已尽力确保内容准确,请谨慎参考 发布于今天 发布于 1 天前 发布于 {days} 天前'
85
+ let allText = noticeTextForSubsetting
81
86
allFiles . forEach ( ( file ) => {
82
- allText += fs . readFileSync ( file , 'utf-8' ) ;
83
- } ) ;
87
+ allText += fs . readFileSync ( file , 'utf-8' )
88
+ } )
84
89
85
- const font = fontCarrier . transfer ( fontPath ) ;
86
- font . min ( allText ) ;
87
- font . output ( { path : outputPath } ) ;
90
+ const font = fontCarrier . transfer ( fontPath )
91
+ font . min ( allText )
92
+ font . output ( { path : outputPath } )
88
93
89
- console . log ( 'Font subset created successfully in dist/fonts!' ) ;
90
- } ,
91
- } ,
92
- } ;
93
- } ;
94
+ console . log ( 'Font subset created successfully in dist/fonts!' )
95
+ }
96
+ }
97
+ }
98
+ }
94
99
95
100
// https://astro.build/config
96
101
export default defineConfig ( {
@@ -137,14 +142,14 @@ export default defineConfig({
137
142
// return slug
138
143
// }
139
144
// }),
140
- expressiveCode ( ) ,
145
+ // expressiveCode(),
141
146
icon ( {
142
147
include : {
143
148
devicon : [ '*' ]
144
149
}
145
150
} ) ,
146
151
AstroPureIntegration ( config ) ,
147
- createFontSubsetIntegration ( ) ,
152
+ createFontSubsetIntegration ( )
148
153
] ,
149
154
// root: './my-project-directory',
150
155
@@ -204,8 +209,23 @@ export default defineConfig({
204
209
properties : { className : [ 'anchor' ] } ,
205
210
content : { type : 'text' , value : '#' }
206
211
}
207
- ] ,
208
- ]
212
+ ]
213
+ ] ,
214
+ // https://docs.astro.build/en/guides/syntax-highlighting/
215
+ shikiConfig : {
216
+ themes : {
217
+ light : 'github-light' ,
218
+ dark : 'github-dark'
219
+ } ,
220
+ transformers : [
221
+ transformerNotationDiff ( ) ,
222
+ transformerNotationHighlight ( ) ,
223
+ updateStyle ( ) ,
224
+ addTitle ( ) ,
225
+ addLanguage ( ) ,
226
+ addCopyButton ( 2000 )
227
+ ]
228
+ }
209
229
} ,
210
230
experimental : {
211
231
svg : true ,
@@ -219,7 +239,7 @@ export default defineConfig({
219
239
// })
220
240
] ,
221
241
server : {
222
- host : true ,
242
+ host : true
223
243
// https: {
224
244
// key: fs.readFileSync('./localhost+2-key.pem'),
225
245
// cert: fs.readFileSync('./localhost+2.pem')
0 commit comments