zenn-metadata-updater
v1.0.0
Published
Update metadata in Zenn markdown file for npm.
Downloads
28
Readme
zenn-metadata-updater
Update metadata in Zenn markdown file for npm.
Install
npm install zenn-metadata-updater
Usage
hoge-zenn-article.md
---
title: "Productivity Weekly (20xx-xx-xx号)"
emoji: "😇"
type: "idea"
topics: ["ProductivityWeekly", "生産性向上"]
published: false
---
# Content start
Update metadata
Single param
const markdownPath = "hoge-zenn-article.md"
const markdown = readFileSync(markdownPath);
const updater = new Updater();
await updater.load(markdown);
updater.updateProperty("published", true);
console.log(updater.getUpdatedContent());
/*
---
title: "Productivity Weekly (20xx-xx-xx号)"
emoji: "😇"
type: "idea"
topics: ["ProductivityWeekly", "生産性向上"]
published: false
---
# Content start
*/
Multi param
const markdownPath = "hoge-zenn-article.md"
const markdown = readFileSync(markdownPath);
const updater = new Updater();
await updater.load(markdown);
const param: ZennMetadata = {
title: "hoge",
emoji: "㊙️",
type: "tech",
topics: ["fuga", "bar"],
published: false,
};
updater.updateProperty(param);
console.log(updater.getUpdatedContent());
/*
---
title: "hoge"
emoji: "㊙️"
type: "tech"
topics: ["fuga", "bar"]
published: false
---
# Content start
*/
Validate metadata
invalid-zenn-article.md
---
title: ""
emoji: ""
type: "hoge"
topics: ["ProductivityWeekly", "生産性向上"]
published: ""
---
# Content start
const markdownPath = "invalid-zenn-article.md"
const markdown = readFileSync(markdownPath);
const updater = new Updater();
updater.load(markdown);
updater.validateProperty();
// Invalid metadata: type, emoji, title, boolean