Skip to content

Commit

Permalink
feat: Github 和 Gitlab 系列平台支持自定义设置作者主页
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Oct 10, 2023
1 parent 8f0b429 commit 720c3b4
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 10 deletions.
7 changes: 7 additions & 0 deletions src/adaptors/api/base/github/commonGithubConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import { PasswordType } from "zhi-blog-api"
import { CommonBlogConfig } from "~/src/adaptors/api/base/commonBlogConfig.ts"
import { StrUtil } from "zhi-common"

/**
* CommonGithubConfig 类用于存储 GitHub 相关配置信息
Expand Down Expand Up @@ -60,6 +61,11 @@ class CommonGithubConfig extends CommonBlogConfig {
*/
public email: string

/**
* 作者主页
*/
public site: string

/**
* Markdown文件名规则(占位符:[yyyy] [MM] [dd] [slug] [filename] )
*/
Expand Down Expand Up @@ -111,6 +117,7 @@ class CommonGithubConfig extends CommonBlogConfig {
this.defaultMsg = "auto published by siyuan-plugin-publisher"
this.author = "terwer"
this.email = "youweics@163.com"
this.site = StrUtil.pathJoin(this.home, "/" + this.username)
this.mdFilenameRule = "[filename].md"
this.useMdFilename = false
this.usePathCategory = false
Expand Down
4 changes: 2 additions & 2 deletions src/adaptors/api/vuepress/vuepressYamlConverterAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ class VuepressYamlConverterAdaptor extends YamlConvertAdaptor {
}

// author
let githubUrl = "https://github.com/terwer"
const githubCfg = cfg as CommonGithubConfig
if (githubCfg.home) {
let githubUrl = githubCfg.site
if (StrUtil.isEmptyString(githubCfg.site)) {
githubUrl = StrUtil.pathJoin(githubCfg.home, "/" + githubCfg.username)
}
yamlFormatObj.yamlObj.author = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,17 @@ const props = defineProps({
})
// emits
const emit = defineEmits(["onHomeChange"])
const emit = defineEmits(["onHomeChange", "onApiUrlChange", "onUsernameChange"])
const handleHomeChange = (value: string | number): void => {
if (emit) {
emit("onHomeChange", value, formData.cfg)
}
}
const handleUsernameChange = (value: string | number): void => {
if (emit) {
emit("onUsernameChange", value, formData.cfg)
}
}
// datas
const isLoading = ref(false)
Expand Down Expand Up @@ -293,7 +298,11 @@ onMounted(async () => {
</el-form-item>
<!-- 登录名 -->
<el-form-item :label="t('setting.common.username')" v-if="props.cfg.usernameEnabled">
<el-input v-model="formData.cfg.username" :placeholder="props.cfg?.placeholder.usernamePlaceholder" />
<el-input
v-model="formData.cfg.username"
:placeholder="props.cfg?.placeholder.usernamePlaceholder"
@input="handleUsernameChange"
/>
</el-form-item>
<!-- 密码 -->
<el-form-item
Expand Down Expand Up @@ -424,4 +433,4 @@ onMounted(async () => {
.inline-tip
margin 0
padding-left 0
</style>
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ const syncDefaultPath = (cfg: any) => {
<el-form-item :label="t('setting.blog.yamlLinkEnabled')">
<el-switch v-model="(main.cfg as any).yamlLinkEnabled" />
</el-form-item>
<el-form-item>
<a href="javascript:;" @click="toggleAdvance">{{ formData.advanceBtnText }}</a>
</el-form-item>
<!-- Github分支名 -->
<el-form-item :label="t('setting.blog.type.github.default.branch')">
<el-input
Expand All @@ -98,6 +95,9 @@ const syncDefaultPath = (cfg: any) => {
:placeholder="t('setting.blog.type.github.default.path.tip')"
/>
</el-form-item>
<el-form-item>
<a href="javascript:;" @click="toggleAdvance">{{ formData.advanceBtnText }}</a>
</el-form-item>
<div v-if="formData.showAdvancedConfig">
<!-- 提交信息 -->
<el-form-item :label="t('setting.blog.type.github.msg')">
Expand All @@ -111,6 +111,10 @@ const syncDefaultPath = (cfg: any) => {
<el-form-item :label="t('setting.blog.type.github.email')">
<el-input v-model="(main.cfg as any).email" :placeholder="t('setting.blog.type.github.email.tip')" />
</el-form-item>
<!-- 作者主页 -->
<el-form-item :label="t('setting.blog.type.github.site')">
<el-input v-model="(main.cfg as any).site" :placeholder="t('setting.blog.type.github.site.tip')" />
</el-form-item>
<!-- 文件规则 -->
<el-form-item :label="t('setting.blog.mdFilenameRule')">
<el-input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { useVueI18n } from "~/src/composables/useVueI18n.ts"
import { useVuepressApi } from "~/src/adaptors/api/vuepress/useVuepressApi.ts"
import { VuepressConfig } from "~/src/adaptors/api/vuepress/vuepressConfig.ts"
import { VuepressPlaceholder } from "~/src/adaptors/api/vuepress/vuepressPlaceholder.ts"
import { StrUtil } from "zhi-common"
const props = defineProps({
apiType: {
Expand All @@ -46,10 +47,32 @@ vuepressPlaceholder.passwordPlaceholder = t("setting.blog.type.github.token.tip"
vuepressPlaceholder.apiUrlPlaceholder = t("setting.blog.github.apiurl.tip")
vuepressPlaceholder.previewUrlPlaceholder = t("setting.blog.previewUrl.tip")
vuepressCfg.placeholder = vuepressPlaceholder
// 处理事件的方法
const onHomeChange = (value: string, cfg: VuepressConfig) => {
if (StrUtil.isEmptyString(cfg.home) || StrUtil.isEmptyString(cfg.username)) {
cfg.site = ""
} else {
cfg.site = StrUtil.pathJoin(cfg.home, "/" + cfg.username)
}
}
const onUsernameChange = (value: string, cfg: VuepressConfig) => {
// sync site
if (StrUtil.isEmptyString(cfg.home) || StrUtil.isEmptyString(cfg.username)) {
cfg.site = ""
} else {
cfg.site = StrUtil.pathJoin(cfg.home, "/" + cfg.username)
}
}
</script>

<template>
<common-github-setting :api-type="props.apiType" :cfg="vuepressCfg">
<common-github-setting
:api-type="props.apiType"
:cfg="vuepressCfg"
@onHomeChange="onHomeChange"
@onUsernameChange="onUsernameChange"
>
<template #header="header"> </template>
<template #main="main"> </template>
<template #footer="footer"> </template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,38 @@ vuepressCfg.placeholder = vuepressPlaceholder
// 处理事件的方法
const onHomeChange = (value: string, cfg: GitlabvuepressConfig) => {
// sync api
if (StrUtil.isEmptyString(cfg.home)) {
cfg.apiUrl = ""
} else {
cfg.apiUrl = cfg.home
cfg.tokenSettingUrl = `${cfg.home}/-/profile/personal_access_tokens`
}
// sync site
if (StrUtil.isEmptyString(cfg.home) || StrUtil.isEmptyString(cfg.username)) {
cfg.site = ""
} else {
cfg.site = StrUtil.pathJoin(cfg.home, "/" + cfg.username)
}
}
const onUsernameChange = (value: string, cfg: GitlabvuepressConfig) => {
// sync site
if (StrUtil.isEmptyString(cfg.home) || StrUtil.isEmptyString(cfg.username)) {
cfg.site = ""
} else {
cfg.site = StrUtil.pathJoin(cfg.home, "/" + cfg.username)
}
}
</script>

<template>
<common-github-setting :api-type="props.apiType" :cfg="vuepressCfg" @onHomeChange="onHomeChange">
<common-github-setting
:api-type="props.apiType"
:cfg="vuepressCfg"
@onHomeChange="onHomeChange"
@onUsernameChange="onUsernameChange"
>
<template #header="header"> </template>
<template #main="main"> </template>
<template #footer="footer"> </template>
Expand Down
2 changes: 2 additions & 0 deletions src/locales/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ export default {
"setting.blog.type.github.author.tip": "Author, eg:terwer",
"setting.blog.type.github.email": "Email",
"setting.blog.type.github.email.tip": "Email",
"setting.blog.type.github.site": "Author's Page",
"setting.blog.type.github.site.tip": "Author's page, defaults to: [GitHub URL]/[Username] if left empty. Please do not change the key, translate the value to English.",
"setting.blog.url": "Blog addr",
"setting.blog.github.url.tip": "Github homepage address",
"setting.blog.github.apiurl.tip": "Github's REST API address, typically: https://api.github.com",
Expand Down
2 changes: 2 additions & 0 deletions src/locales/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ export default {
"setting.blog.type.github.author.tip": "作者,例如:terwer",
"setting.blog.type.github.email": "邮箱",
"setting.blog.type.github.email.tip": "邮箱",
"setting.blog.type.github.site": "作者主页",
"setting.blog.type.github.site.tip": "作者主页,如果为空默认为:[GitHub地址]/[用户名]",
"setting.blog.url": "博客网址",
"setting.blog.github.url.tip": "Github首页地址",
"setting.blog.username": "账号",
Expand Down

0 comments on commit 720c3b4

Please sign in to comment.