1
1
import fs from 'node:fs' ;
2
- import yaml from 'js-yaml' ;
2
+ import { load , dump } from 'js-yaml' ;
3
3
4
4
export class DoculaHelpers {
5
5
createDoc ( path : string , destination : string , frontMatter ?: Record < string , string > , contentFunction ?: ( content : string ) => string ) : void {
@@ -24,7 +24,7 @@ export class DoculaHelpers {
24
24
const match = / ^ - - - \r ? \n ( [ \s \S ] + ?) \r ? \n - - - / . exec ( content ) ;
25
25
if ( match ) {
26
26
// Parse the YAML string to an object
27
- const frontMatter = yaml . load ( match [ 1 ] ) ;
27
+ const frontMatter = load ( match [ 1 ] ) ;
28
28
return frontMatter as Record < string , string > ;
29
29
}
30
30
@@ -47,7 +47,7 @@ export class DoculaHelpers {
47
47
48
48
if ( match ) {
49
49
// Parse the existing FrontMatter
50
- let oldFrontMatter = yaml . load ( match [ 1 ] ) ;
50
+ let oldFrontMatter = load ( match [ 1 ] ) ;
51
51
52
52
// Set or replace values
53
53
oldFrontMatter = {
@@ -56,7 +56,7 @@ export class DoculaHelpers {
56
56
} ;
57
57
58
58
// Serialize the FrontMatter back to a YAML string
59
- const newYaml = yaml . dump ( oldFrontMatter ) ;
59
+ const newYaml = dump ( oldFrontMatter ) ;
60
60
61
61
// Replace the old FrontMatter with the new string
62
62
const newContent = `---\n${ newYaml } ---\n${ match [ 2 ] } ` ;
@@ -66,7 +66,7 @@ export class DoculaHelpers {
66
66
}
67
67
68
68
// No FrontMatter found, add it
69
- const newYaml = yaml . dump ( frontMatter ) ;
69
+ const newYaml = dump ( frontMatter ) ;
70
70
const newContent = `---\n${ newYaml } ---\n${ content } ` ;
71
71
return newContent ;
72
72
}
0 commit comments