Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: cover字段或值不存在时报错 #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion format-image.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

const { matterMarkdownAdapter } = require('@elog/cli')
const elogConfig = require('./elog.config')

/**
* 自定义文档处理器
Expand All @@ -8,6 +9,15 @@ const { matterMarkdownAdapter } = require('@elog/cli')
* @return {Promise<DocDetail>} 返回处理后的文档对象
*/
const format = async (doc, imageClient) => {
doc.body = matterMarkdownAdapter(doc);
// 配置中无cover
if (!elogConfig.deploy.local.frontMatter.include.includes('cover')) {
return doc
}
// cover字段实际为空
if (!doc.properties.cover) {
return doc;
}
const cover = doc.properties.cover
// 将 cover 字段中的 notion 图片下载到本地
if (imageClient) {
Expand All @@ -16,7 +26,6 @@ const format = async (doc, imageClient) => {
// cover链接替换为本地图片
doc.properties.cover = url
}
doc.body = matterMarkdownAdapter(doc);
return doc;
};

Expand Down