Skip to content

Commit 619536c

Browse files
committed
inject format frontmatter when there is one
also remove deadcode
1 parent 8a629b2 commit 619536c

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

src/printer.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// import matter = require('gray-matter');
21
import type { BuiltInParserName, Options, RequiredOptions } from 'prettier';
32
import { format } from 'prettier';
43
import type PrettierAngularPlugin from 'prettier/plugins/angular';
@@ -391,10 +390,11 @@ export class PugPrinter {
391390

392391
token = this.getNextToken();
393392
}
394-
console.log(this.frontmatter);
395-
//return matter.stringify(results.join(''), this.frontmatter.raw);
396-
console.log(this.frontmatter);
397-
return this.frontmatter.raw + results.join('');
393+
394+
const fm = await this.frontmatterFormat(this.frontmatter.value);
395+
const formattedFrontmatter = this.frontmatter ? '---\n' + fm + '---\n' : '';
396+
397+
return formattedFrontmatter + results.join('');
398398
}
399399

400400
private getNextToken(): Token | null {
@@ -482,6 +482,15 @@ export class PugPrinter {
482482
}
483483
}
484484

485+
private async frontmatterFormat(frontmatter: string): Promise<string> {
486+
const options = {
487+
parser: 'yaml',
488+
collectionStyle: 'block',
489+
};
490+
491+
return format(frontmatter, options);
492+
}
493+
485494
private async frameworkFormat(code: string): Promise<string> {
486495
const options: Options = {
487496
...this.codeInterpolationOptions,

0 commit comments

Comments
 (0)