Skip to content

Commit

Permalink
fix: 修复标签为空时部分平台报错的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Sep 20, 2023
1 parent 582c5ee commit 3031c2a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
27 changes: 13 additions & 14 deletions src/adaptors/api/vitepress/vitepressYamlConverterAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,19 @@ class VitepressYamlConverterAdaptor extends YamlConvertAdaptor {
yamlFormatObj.yamlObj.date = DateUtil.formatIsoToZh(post.dateCreated.toISOString(), true)

// head
yamlFormatObj.yamlObj.head = [
[
"meta",
{
name: "description",
content: post?.shortDesc ?? "",
},
"meta",
{
name: "keywords",
content: post?.mt_keywords?.split(",").join(" "),
},
],
]
yamlFormatObj.yamlObj.head = []
if (!StrUtil.isEmptyString(post.mt_keywords)) {
yamlFormatObj.yamlObj.head.push({
name: "keywords",
content: post.mt_keywords.split(",").join(" "),
})
}
if (!StrUtil.isEmptyString(post.shortDesc)) {
yamlFormatObj.yamlObj.head.push({
name: "description",
content: post.shortDesc,
})
}

// categories
if (post.categories?.length > 0) {
Expand Down
19 changes: 11 additions & 8 deletions src/adaptors/api/vuepress/vuepressYamlConverterAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,19 @@ class VuepressYamlConverterAdaptor extends YamlConvertAdaptor {
yamlFormatObj.yamlObj.date = DateUtil.formatIsoToZh(post.dateCreated.toISOString(), true)

// meta
yamlFormatObj.yamlObj.meta = [
{
yamlFormatObj.yamlObj.meta = []
if (!StrUtil.isEmptyString(post.mt_keywords)) {
yamlFormatObj.yamlObj.meta.push({
name: "keywords",
content: post.mt_keywords.split(",").join(" "),
},
{
content: post.mt_keywords.split(",").join(" ") || "",
})
}
if (!StrUtil.isEmptyString(post.shortDesc)) {
yamlFormatObj.yamlObj.meta.push({
name: "description",
content: post.shortDesc ?? "",
},
]
content: post.shortDesc,
})
}

// tags
if (!StrUtil.isEmptyString(post.mt_keywords)) {
Expand Down

0 comments on commit 3031c2a

Please sign in to comment.