Skip to content

Commit

Permalink
fix: undefined updated property (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
songkg7 authored May 20, 2023
1 parent 55565eb commit 3fa08e8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/jekyll/FrontMatterConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function convertImagePath(postTitle: string, imagePath: string, resourcePath: st
}

function replaceDateFrontMatter(frontMatter: FrontMatter, isEnable: boolean): FrontMatter {
if (!isEnable) {
if (!isEnable || frontMatter.updated === undefined) {
return frontMatter;
}
if (frontMatter.updated.length > 0) {
Expand Down
23 changes: 21 additions & 2 deletions src/tests/FrontMatterConverter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,21 +210,40 @@ image: /assets/img/2023-01-01-test-title/test.png

describe('updated front matter', () => {
const updatedConverter = new FrontMatterConverter('2023-01-01-test-title', 'assets/img', true, true);
const contents = `---
it('should be converted', () => {
const contents = `---
title: "test"
date: 2021-01-01 12:00:00 +0900
updated: 2022-01-02 12:00:00 +0900
---
# test
`;
it('should be converted', () => {
const result = updatedConverter.convert(contents);
expect(result).toEqual(`---
title: "test"
date: 2022-01-02 12:00:00 +0900
---
# test
`,
);
});

it('should be not converted', () => {
const contents = `---
title: "test"
date: 2021-01-01 12:00:00 +0900
---
# test
`;
const result = updatedConverter.convert(contents);
expect(result).toEqual(`---
title: "test"
date: 2021-01-01 12:00:00 +0900
---
# test
`,
);
Expand Down

0 comments on commit 3fa08e8

Please sign in to comment.