diff --git a/action.yml b/action.yml index 49b3cdb..edf119f 100644 --- a/action.yml +++ b/action.yml @@ -13,8 +13,8 @@ inputs: - 那么 `database_id=0f3d856498ca4db3b457c5b4eeaxxxxx` status_name: required: false - description: notion database 状态字段的字段名, 支持自定义 - default: "status" + description: notion database 状态字段的字段名, 默认为pstatus, 可修改 + default: "pstatus" status_published: required: false description: notion database 文章已发布状态的字段值 @@ -36,7 +36,7 @@ inputs: description: | 转换后markdown文件中需要保留的字段, 字段值会同步到Notion中。 例如abbrlink等字段, 在notion->markdown过程不存在, 但需要hexo等博客自动生成, 且不能变化。 - 多个key请用逗号分隔, 如abbrlink, id. + 多个key请用逗号分隔, 如abbrlink, id default: "abbrlink" last_sync_datetime: required: false @@ -85,8 +85,13 @@ inputs: default: "{}" pic_compress: description: | - 是否开启图片压缩?true为开启, 默认不开启 + 是否开启图片压缩? true为开启, 默认不开启 default: "false" + excluded_metas: + default: "ptype, pstatus" + description: | + Notion转Markdown, 生成页面YAML是需要删除的属性名称, 多个用逗号分隔 + 需要删除的页面属性名称 timezone: description: 设置的时区 default: "Asia/Shanghai" diff --git a/dist/index.js b/dist/index.js index a4265bd..df48129 100644 --- a/dist/index.js +++ b/dist/index.js @@ -282381,8 +282381,8 @@ let notion = new Client({ auth: config.notion_secret }); let picgo = new PicGo(); let n2m = new NotionToMarkdown({ notionClient: notion }); -function init(conf) { - config = conf; +function init(cfg) { + config = cfg; notion = new Client({ auth: config.notion_secret, config: { @@ -282436,18 +282436,18 @@ async function sync() { // query the filename list from the output directory let notionPagePropList = await Promise.all(pages.map(async (page) => { var properties = await getPropertiesDict(page); - switch (properties.type) { + switch (properties?.ptype?.toLocaleLowerCase() || "") { case "page": - if (!properties.filename) { + if (!properties?.filename && !properties?.slug) { console.error(`Page ${properties.title} has no filename, the page id will be used as the filename.`); properties.filename = properties.id; } - properties.filePath = path.join(config.output_dir.page, properties.filename, 'index.md'); + properties.filePath = path.join(config.output_dir.page, (properties?.filename || properties?.slug).trim(), 'index.md'); properties.filename = "index.md"; break; case "post": default: - properties.filename = properties.filename != undefined && properties.filename ? properties.filename + ".md" : properties.title + ".md"; + properties.filename = (properties?.filename || properties?.slug || properties?.title || properties.id).trim() + '.md' // get the filename and directory of the post, if the filename includes /, then it will be treated as a subdirectory properties.filePath = path.join(config.output_dir.post, properties.filename); if (properties.filename.includes("/")) { @@ -282620,6 +282620,14 @@ async function page2Markdown(page, filePath, properties) { } } // remove created_time and last_edited_time from properties + if (config?.excluded_metas && config.excluded_metas.length){ + // delete the key within excluded_metas for properties + for(const key of config.excluded_metas){ + if(key && key in properties) { + delete properties[key]; + } + } + } delete properties.created_time; delete properties.last_edited_time; let fm = YAML.stringify(properties, { doubleQuotedAsJSON: true }); @@ -282786,7 +282794,7 @@ function getPropVal(data) { case "date": var mt = moment(val.start); if (!mt.isValid()) return val.start; - return mt.tz(config.timezone).format('YYYY-MM-DD HH:mm:ss'); + return config?.timezone ? mt.tz(config.timezone).format('YYYY-MM-DD') : mt.format(); case "rich_text": case "title": return val.map((a) => a.plain_text).join(""); @@ -282799,7 +282807,7 @@ function getPropVal(data) { case "last_edited_time": var mt = moment(val); if (!mt.isValid()) return val; - return mt.tz(config.timezone).format('YYYY-MM-DD HH:mm:ss'); + return config?.timezone ? mt.tz(config.timezone).format('YYYY-MM-DD HH:mm:ss') : mt.format(); default: return ""; } @@ -305415,6 +305423,14 @@ if (keys_to_keep && keys_to_keep.trim().length > 0) { keys_to_keep = keys_to_keep.split(",").map((key) => key.trim()); } +var excluded_metas = core.getInput("excluded_metas") || []; +if(excluded_metas){ + excluded_metas = excluded_metas.split(','); + // use trim to remove space for excluded_metas; + excluded_metas = excluded_metas.forEach((v)=>v.trim()); + excluded_metas = excluded_metas.filter((v)=>v); +} + let config = { notion_secret: core.getInput("notion_secret"), database_id: core.getInput("database_id"), @@ -305432,6 +305448,7 @@ let config = { }, keys_to_keep: keys_to_keep, last_sync_datetime: core.getInput("last_sync_datetime") || null, + excluded_metas: excluded_metas || [], timezone: core.getInput("timezone") || "Asia/Shanghai", }; diff --git a/dist/vendor1/pngquant b/dist/vendor1/pngquant deleted file mode 100644 index 5e420e2..0000000 Binary files a/dist/vendor1/pngquant and /dev/null differ diff --git a/dist/vendor1/source/pngquant.tar.gz b/dist/vendor1/source/pngquant.tar.gz deleted file mode 100644 index 44d8c07..0000000 Binary files a/dist/vendor1/source/pngquant.tar.gz and /dev/null differ diff --git a/dist/vendor2/cjpeg b/dist/vendor2/cjpeg deleted file mode 100644 index fc7de12..0000000 Binary files a/dist/vendor2/cjpeg and /dev/null differ diff --git a/dist/vendor2/source/mozjpeg.tar.gz b/dist/vendor2/source/mozjpeg.tar.gz deleted file mode 100644 index 96ba696..0000000 Binary files a/dist/vendor2/source/mozjpeg.tar.gz and /dev/null differ diff --git a/src/index.js b/src/index.js index 796b893..6b464ca 100644 --- a/src/index.js +++ b/src/index.js @@ -40,6 +40,14 @@ if (keys_to_keep && keys_to_keep.trim().length > 0) { keys_to_keep = keys_to_keep.split(",").map((key) => key.trim()); } +var excluded_metas = core.getInput("excluded_metas") || []; +if(excluded_metas){ + excluded_metas = excluded_metas.split(','); + // use trim to remove space for excluded_metas; + excluded_metas = excluded_metas.forEach((v)=>v.trim()); + excluded_metas = excluded_metas.filter((v)=>v); +} + let config = { notion_secret: core.getInput("notion_secret"), database_id: core.getInput("database_id"), @@ -57,6 +65,7 @@ let config = { }, keys_to_keep: keys_to_keep, last_sync_datetime: core.getInput("last_sync_datetime") || null, + excluded_metas: excluded_metas || [], timezone: core.getInput("timezone") || "Asia/Shanghai", }; diff --git a/src/notion.js b/src/notion.js index 93813ab..3867418 100644 --- a/src/notion.js +++ b/src/notion.js @@ -47,8 +47,8 @@ let notion = new Client({ auth: config.notion_secret }); let picgo = new PicGo(); let n2m = new NotionToMarkdown({ notionClient: notion }); -function init(conf) { - config = conf; +function init(cfg) { + config = cfg; notion = new Client({ auth: config.notion_secret, config: { @@ -102,18 +102,18 @@ async function sync() { // query the filename list from the output directory let notionPagePropList = await Promise.all(pages.map(async (page) => { var properties = await getPropertiesDict(page); - switch (properties.type) { + switch (properties?.ptype?.toLocaleLowerCase() || "") { case "page": - if (!properties.filename) { + if (!properties?.filename && !properties?.slug) { console.error(`Page ${properties.title} has no filename, the page id will be used as the filename.`); properties.filename = properties.id; } - properties.filePath = path.join(config.output_dir.page, properties.filename, 'index.md'); + properties.filePath = path.join(config.output_dir.page, (properties?.filename || properties?.slug).trim(), 'index.md'); properties.filename = "index.md"; break; case "post": default: - properties.filename = properties.filename != undefined && properties.filename ? properties.filename + ".md" : properties.title + ".md"; + properties.filename = (properties?.filename || properties?.slug || properties?.title || properties.id).trim() + '.md' // get the filename and directory of the post, if the filename includes /, then it will be treated as a subdirectory properties.filePath = path.join(config.output_dir.post, properties.filename); if (properties.filename.includes("/")) { @@ -286,6 +286,14 @@ async function page2Markdown(page, filePath, properties) { } } // remove created_time and last_edited_time from properties + if (config?.excluded_metas && config.excluded_metas.length){ + // delete the key within excluded_metas for properties + for(const key of config.excluded_metas){ + if(key && key in properties) { + delete properties[key]; + } + } + } delete properties.created_time; delete properties.last_edited_time; let fm = YAML.stringify(properties, { doubleQuotedAsJSON: true }); @@ -452,7 +460,7 @@ function getPropVal(data) { case "date": var mt = moment(val.start); if (!mt.isValid()) return val.start; - return mt.tz(config.timezone).format('YYYY-MM-DD HH:mm:ss'); + return config?.timezone ? mt.tz(config.timezone).format('YYYY-MM-DD') : mt.format(); case "rich_text": case "title": return val.map((a) => a.plain_text).join(""); @@ -465,7 +473,7 @@ function getPropVal(data) { case "last_edited_time": var mt = moment(val); if (!mt.isValid()) return val; - return mt.tz(config.timezone).format('YYYY-MM-DD HH:mm:ss'); + return config?.timezone ? mt.tz(config.timezone).format('YYYY-MM-DD HH:mm:ss') : mt.format(); default: return ""; }