Skip to content

Commit 4e259e7

Browse files
committed
clean up the code
1 parent f771fdc commit 4e259e7

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ export const plugin: Plugin<AstPathStackEntry> = {
4545
parse(text, options) {
4646
logger.debug('[parsers:pug:parse]:', { text });
4747

48-
const parts = parse(text);
49-
const frontmatter = parts.frontMatter;
48+
const parts: FrontMatter = parse(text);
49+
const frontmatter: string = parts.frontMatter
50+
? parts.frontMatter.value
51+
: undefined;
5052
text = parts.content;
5153

5254
let trimmedAndAlignedContent: string = text.replace(/^\s*\n/, '');

src/printer.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,13 @@ export class PugPrinter {
236236
* @param content The pug content string.
237237
* @param tokens The pug token array.
238238
* @param options Options for the printer.
239+
* @param frontmatter The extracted frontmatter part.
239240
*/
240241
public constructor(
241242
private readonly content: string,
242243
private tokens: Token[],
243244
private readonly options: PugPrinterOptions,
244-
private readonly frontmatter: Frontmatter<string>,
245+
private readonly frontmatter: string,
245246
) {
246247
this.frontmatter = frontmatter;
247248
this.indentString = options.pugUseTabs
@@ -392,10 +393,15 @@ export class PugPrinter {
392393
}
393394

394395
if (this.frontmatter) {
395-
const frontmatter: string = await this.frontmatterFormat(
396-
this.frontmatter.value,
397-
);
398-
results.unshift('---\n', frontmatter, '---\n');
396+
try {
397+
results.unshift(
398+
'---\n',
399+
await this.frontmatterFormat(this.frontmatter),
400+
'---\n',
401+
);
402+
} catch (error: any) {
403+
logger.warn(error);
404+
}
399405
}
400406

401407
return results.join('');

0 commit comments

Comments
 (0)