Skip to content

Commit 16e6811

Browse files
authored
Merge pull request #183 from jaredwray/moving-to-function-calls-with-js-yaml
moving to function calls with js-yaml
2 parents 9ea9aa6 + af7e8ac commit 16e6811

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/helpers.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fs from 'node:fs';
2-
import yaml from 'js-yaml';
2+
import {load, dump} from 'js-yaml';
33

44
export class DoculaHelpers {
55
createDoc(path: string, destination: string, frontMatter?: Record<string, string>, contentFunction?: (content: string) => string): void {
@@ -24,7 +24,7 @@ export class DoculaHelpers {
2424
const match = /^---\r?\n([\s\S]+?)\r?\n---/.exec(content);
2525
if (match) {
2626
// Parse the YAML string to an object
27-
const frontMatter = yaml.load(match[1]);
27+
const frontMatter = load(match[1]);
2828
return frontMatter as Record<string, string>;
2929
}
3030

@@ -47,7 +47,7 @@ export class DoculaHelpers {
4747

4848
if (match) {
4949
// Parse the existing FrontMatter
50-
let oldFrontMatter = yaml.load(match[1]);
50+
let oldFrontMatter = load(match[1]);
5151

5252
// Set or replace values
5353
oldFrontMatter = {
@@ -56,7 +56,7 @@ export class DoculaHelpers {
5656
};
5757

5858
// Serialize the FrontMatter back to a YAML string
59-
const newYaml = yaml.dump(oldFrontMatter);
59+
const newYaml = dump(oldFrontMatter);
6060

6161
// Replace the old FrontMatter with the new string
6262
const newContent = `---\n${newYaml}---\n${match[2]}`;
@@ -66,7 +66,7 @@ export class DoculaHelpers {
6666
}
6767

6868
// No FrontMatter found, add it
69-
const newYaml = yaml.dump(frontMatter);
69+
const newYaml = dump(frontMatter);
7070
const newContent = `---\n${newYaml}---\n${content}`;
7171
return newContent;
7272
}

0 commit comments

Comments
 (0)