Skip to content

Commit

Permalink
fix: 优化 Hexo 文章链接转换规则
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Aug 8, 2023
1 parent f7dc02b commit 0021c29
Show file tree
Hide file tree
Showing 22 changed files with 105 additions and 82 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@
"vue-router": "^4.2.4",
"xmlbuilder2": "^3.1.1",
"zhi-blog-api": "^1.20.13",
"zhi-common": "^1.14.0",
"zhi-common": "^1.14.1",
"zhi-device": "^2.3.0",
"zhi-fetch-middleware": "^0.2.18",
"zhi-github-middleware": "^0.2.0",
"zhi-fetch-middleware": "^0.2.19",
"zhi-github-middleware": "^0.2.1",
"zhi-lib-base": "^0.4.4",
"zhi-notion-markdown": "^0.1.2",
"zhi-siyuan-api": "^2.0.14",
"zhi-xmlrpc-middleware": "^0.4.13"
"zhi-siyuan-api": "^2.0.15",
"zhi-xmlrpc-middleware": "^0.4.14"
}
}
97 changes: 44 additions & 53 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/adaptors/api/base/CommonblogConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ export class CommonblogConfig extends BlogConfig {
*/
public usernameEnabled = false

/**
* 是否启用用户名
*/
public allowPreviewUrlChange = true

/**
* 是否展示Token设置地址
*/
Expand All @@ -145,5 +150,6 @@ export class CommonblogConfig extends BlogConfig {
this.placeholder = new MetaweblogPlaceholder()
this.middlewareUrl = middlewareUrl
this.usernameEnabled = false
this.allowPreviewUrlChange = true
}
}
3 changes: 2 additions & 1 deletion src/adaptors/api/base/metaweblog/MetaweblogConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ export class MetaweblogConfig extends CommonblogConfig {
this.posidKey = ""
this.previewUrl = ""
this.pageType = PageTypeEnum.Html
this.middlewareUrl = middlewareUrl
this.placeholder = new MetaweblogPlaceholder()
this.usernameEnabled = true
this.showTokenTip = false
this.middlewareUrl = middlewareUrl
this.allowPreviewUrlChange = true
}
}
1 change: 1 addition & 0 deletions src/adaptors/api/cnblogs/cnblogsConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class CnblogsConfig extends MetaweblogConfig {
this.usernameEnabled = true
this.passwordType = PasswordType.PasswordType_Token
this.showTokenTip = true
this.allowPreviewUrlChange = true
}
}

Expand Down
1 change: 1 addition & 0 deletions src/adaptors/api/hexo/hexoConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class HexoConfig extends CommonGithubConfig {
// this.mdFilenameRule = "[slug].md"
this.pageType = PageTypeEnum.Markdown
this.passwordType = PasswordType.PasswordType_Token
this.allowPreviewUrlChange = false
}
}

Expand Down
34 changes: 17 additions & 17 deletions src/adaptors/api/hexo/hexoYamlConverterAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,23 @@ export class HexoYamlConverterAdaptor extends YamlConvertAdaptor {
const githubCfg = cfg as CommonGithubConfig
if (!StrUtil.isEmptyString(cfg.previewPostUrl)) {
link = githubCfg.previewPostUrl.replace("[postid]", post.wp_slug)
// const created = post.dateCreated
// const datearr = created.split(" ")[0]
// const numarr = datearr.split("-")
// this.logger.debug("created numarr=>", numarr)
// const y = numarr[0]
// const m = numarr[1]
// const d = numarr[2]
// link = link.replace(/\[yyyy]/g, y)
// link = link.replace(/\[MM]/g, m)
// link = link.replace(/\[mm]/g, m)
// link = link.replace(/\[dd]/g, d)
//
// if (yamlFormatObj.yamlObj.categories.length > 0) {
// link = link.replace(/\[cats]/, yamlFormatObj.yamlObj.categories.join("/"))
// } else {
// link = link.replace(/\/\[cats]/, "")
// }
const created = DateUtil.formatIsoToZh(post.dateCreated.toISOString(), true)
const datearr = created.split(" ")[0]
const numarr = datearr.split("-")
this.logger.debug("created numarr=>", numarr)
const y = numarr[0]
const m = numarr[1]
const d = numarr[2]
link = link.replace(/\[yyyy]/g, y)
link = link.replace(/\[MM]/g, m)
link = link.replace(/\[mm]/g, m)
link = link.replace(/\[dd]/g, d)

if (yamlFormatObj.yamlObj.categories.length > 0) {
link = link.replace(/\[cats]/, yamlFormatObj.yamlObj.categories.join("/"))
} else {
link = link.replace(/\/\[cats]/, "")
}
}
}
yamlFormatObj.yamlObj.permalink = link
Expand Down
1 change: 1 addition & 0 deletions src/adaptors/api/notion/notionConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class NotionConfig extends CommonblogConfig {
this.passwordType = PasswordType.PasswordType_Token
this.knowledgeSpaceTitle = "根页面"
this.enableKnowledgeSpace = true
this.allowPreviewUrlChange = false
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/adaptors/api/typecho/typechoConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
* questions.
*/

import { MetaweblogConfig } from "~/src/adaptors/api/base/metaweblog/MetaweblogConfig.ts"
import { PageTypeEnum } from "zhi-blog-api"
import TypechoUtils from "~/src/adaptors/api/typecho/typechoUtils.ts"
import { MetaweblogConfig } from "~/src/adaptors/api/base/metaweblog/MetaweblogConfig.ts"

/**
* Typecho 配置
Expand All @@ -51,6 +51,7 @@ class TypechoConfig extends MetaweblogConfig {
this.previewUrl = "/index.php/archives/[postid]"
this.pageType = PageTypeEnum.Html
this.showTokenTip = false
this.allowPreviewUrlChange = true
}
}

Expand Down
1 change: 1 addition & 0 deletions src/adaptors/api/wordpress/wordpressConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class WordpressConfig extends MetaweblogConfig {
this.pageType = PageTypeEnum.Html
this.usernameEnabled = true
this.showTokenTip = false
this.allowPreviewUrlChange = true
}
}

Expand Down
1 change: 1 addition & 0 deletions src/adaptors/api/yuque/yuqueConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class YuqueConfig extends CommonblogConfig {
this.passwordType = PasswordType.PasswordType_Token
this.knowledgeSpaceTitle = "知识库"
this.enableKnowledgeSpace = true
this.allowPreviewUrlChange = false
}
}

Expand Down
Loading

0 comments on commit 0021c29

Please sign in to comment.