Skip to content

Commit

Permalink
feat: #133 支持Github系列-Jekyll适配
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Dec 1, 2022
1 parent 2d81fd3 commit 1f3ea54
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 286 deletions.
2 changes: 1 addition & 1 deletion src/assets/style.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@import "./webfont.css";

html{
filter: grayscale(1);
/*filter: grayscale(1);*/
--el-font-family: var(--g-font-family) !important;
--custom-app-bg-color: #ffffff;
height: 100%;
Expand Down
6 changes: 4 additions & 2 deletions src/components/publish/tab/DynamicPlantform.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,14 @@ import {checkKeyExists} from "~/utils/config";
const {t} = useI18n()
const showForm = ref(true)
// 默认支持jekyll
const defaultGithubSubtype = SubPlantformType.Github_Jekyll
const formRef = ref<FormInstance>()
const formData = reactive({
subtype: SubPlantformType.Github_pages,
subtype: defaultGithubSubtype,
ptype: PlantformType.Github,
dynCfg: new DynamicConfig(PlantformType.Github, getNewPlatformKey(PlantformType.Github, SubPlantformType.Github_pages), ""),
dynCfg: new DynamicConfig(PlantformType.Github, getNewPlatformKey(PlantformType.Github, defaultGithubSubtype), "Jekyll-1"),
subtypeOptions: <Array<SubPlantformType>>[],
dynamicConfigArray:<Array<DynamicConfig>>[]
})
Expand Down
2 changes: 1 addition & 1 deletion src/components/publish/tab/ServiceSwitch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</el-form-item>

<el-form-item :label="$t('service.switch.hexo')">
<el-switch v-model="hexoEnabled" @change="hexoEnabled"/>
<el-switch v-model="hexoEnabled" @change="hexoOnChange"/>
</el-form-item>

<el-form-item :label="$t('service.switch.jekyll')">
Expand Down
8 changes: 1 addition & 7 deletions src/components/publish/tab/setting/GithubSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ const saveConf = (hideTip?: boolean) => {
cfg.defaultMsg = formData.msg
cfg.author = formData.author
cfg.email = formData.email
cfg.previewUrl = formData.email
cfg.previewUrl = formData.previewUrl
setJSONConf(props.apiType, cfg)
Expand Down Expand Up @@ -313,12 +313,6 @@ onMounted(async () => {
})
</script>

<script lang="ts">
export default {
name: "GithubSetting"
}
</script>

<style scoped>
</style>
15 changes: 8 additions & 7 deletions src/components/publish/tab/setting/github/HexoSetting.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<template>
<div>HexoSetting</div>
<github-setting :api-type="apiType" :cfg="hexoCfg"/>
</template>

<script lang="ts" setup>
import GithubSetting from "~/components/publish/tab/setting/GithubSetting.vue";
import {API_TYPE_CONSTANTS} from "~/utils/constants/apiTypeConstants";
import {ref} from "vue";
import {HexoCfg} from "~/utils/platform/github/hexo/hexoCfg";
</script>

<script lang="ts">
export default {
name: "HexoSetting"
}
const apiType = ref(API_TYPE_CONSTANTS.API_TYPE_HEXO)
const hexoCfg = new HexoCfg()
const cfg = ref(hexoCfg)
</script>

<style scoped>
Expand Down
23 changes: 10 additions & 13 deletions src/components/publish/tab/setting/github/JekyllSetting.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
<template>
<div>JekyllSetting</div>
<GithubSetting :api-type="apiType" :cfg="cfg"/>
</template>

<script lang="ts" setup>
</script>

<script lang="ts">
export default {
name: "JekyllSetting"
}
</script>

<style scoped>
</style>
import GithubSetting from "~/components/publish/tab/setting/GithubSetting.vue";
import {API_TYPE_CONSTANTS} from "~/utils/constants/apiTypeConstants";
import {ref} from "vue";
import {JekyllCfg} from "~/utils/platform/github/jekyll/jekyllCfg";
const apiType = ref(API_TYPE_CONSTANTS.API_TYPE_JEKYLL)
const jekyllCfg = new JekyllCfg()
const cfg = ref(jekyllCfg)
</script>
247 changes: 8 additions & 239 deletions src/components/publish/tab/setting/github/VuepressSetting.vue
Original file line number Diff line number Diff line change
@@ -1,244 +1,13 @@
<template>
<el-form label-width="120px" ref="formRef" :model="formData" :rules="rules" status-icon>
<el-form-item :label="$t('setting.blog.type.vuepress.github.user')" prop="githubUser">
<el-input v-model="formData.githubUser" :placeholder="$t('setting.blog.type.vuepress.github.user.tip')"/>
</el-form-item>

<el-form-item :label="$t('setting.blog.type.vuepress.github.repo')" prop="githubRepo">
<el-input v-model="formData.githubRepo" :placeholder="$t('setting.blog.type.vuepress.github.repo.tip')"/>
</el-form-item>

<el-form-item :label="$t('setting.blog.type.vuepress.github.token')" prop="githubToken">
<el-input type="password" v-model="formData.githubToken"
:placeholder="$t('setting.blog.type.vuepress.github.token.tip')" show-password/>
<a href="https://github.com/settings/tokens/new"
target="_blank">{{ $t('setting.blog.type.vuepress.github.token.gen') }}</a>
</el-form-item>

<el-form-item :label="$t('setting.blog.type.vuepress.github.default.path')" prop="defaultPath">
<el-input v-model="formData.defaultPath" :placeholder="$t('setting.blog.type.vuepress.github.default.path.tip')"/>
</el-form-item>

<el-form-item :label="$t('setting.blog.type.vuepress.github.default.branch')" prop="defaultBranch">
<el-input v-model="formData.defaultBranch"
:placeholder="$t('setting.blog.type.vuepress.github.default.branch.tip')"/>
</el-form-item>

<el-form-item :label="$t('setting.blog.type.vuepress.github.msg')" prop="msg">
<el-input v-model="formData.msg" :placeholder="$t('setting.blog.type.vuepress.github.msg.tip')"/>
</el-form-item>

<el-form-item :label="$t('setting.blog.type.vuepress.github.author')" prop="author">
<el-input v-model="formData.author" :placeholder="$t('setting.blog.type.vuepress.github.author.tip')"/>
</el-form-item>

<el-form-item :label="$t('setting.blog.type.vuepress.github.email')" prop="email">
<el-input v-model="formData.email" :placeholder="$t('setting.blog.type.vuepress.github.email.tip')"/>
</el-form-item>

<el-form-item :label="$t('form.validate.vuepress.auto.delete')">
<el-switch v-model="autoDeleteTest" @change="testOnChange"/>
</el-form-item>

<el-form-item>
<el-button type="primary" @click="valiConf" :loading="isLoading">
{{ isLoading ? $t('setting.blog.vali.ing') : $t('setting.blog.vali') }}
</el-button>
<el-alert :title="$t('setting.blog.vali.tip')" type="warning" :closable="false" v-if="!apiStatus"/>
<el-alert :title="$t('setting.blog.vali.ok')" type="success" :closable="false" v-if="apiStatus"/>
</el-form-item>

<el-form-item>
<el-button type="primary" @click="submitForm(formRef)">{{ $t('setting.blog.save') }}</el-button>
<el-button @click="resetForm(formRef)">{{ $t('setting.blog.cancel') }}</el-button>
</el-form-item>
<el-form-item>
<a :href="formData.previewUrl" target="_blank">{{ formData.previewUrl }}</a>
</el-form-item>
</el-form>
<github-setting :api-type="apiType" :cfg="cfg"/>
</template>

<script lang="ts" setup>
import {onBeforeMount, reactive, ref} from "vue";
import {ElMessage, FormInstance, FormRules} from "element-plus";
import {useI18n} from "vue-i18n";
import logUtil from "~/utils/logUtil";
import {getBooleanConf, getJSONConf, setBooleanConf} from "~/utils/config";
import GithubSetting from "~/components/publish/tab/setting/GithubSetting.vue";
import {API_TYPE_CONSTANTS} from "~/utils/constants/apiTypeConstants";
import {formatIsoToZhDate} from "~/utils/util";
import {IGithubCfg} from "~/utils/platform/github/githubCfg";
const {t} = useI18n()
const isLoading = ref(false)
const apiStatus = ref(false)
const autoDeleteTest = ref(true)
const formRef = ref<FormInstance>()
const formData = reactive({
githubUser: "",
githubRepo: "",
githubToken: "",
defaultBranch: "main",
defaultPath: "docs/_posts/",
msg: "auto published by sy-post-publisher",
author: "terwer",
email: "youweics@163.com",
previewUrl: "#preview"
})
const rules = reactive<FormRules>({
githubUser: [
{
required: true,
message: () => t('form.validate.name.required')
}
],
githubRepo: [
{
required: true,
message: () => t('form.validate.name.required')
}
],
githubToken: [
{
required: true,
message: () => t('form.validate.name.required')
}
],
defaultBranch: [
{
required: true,
message: () => t('form.validate.name.required')
}
],
defaultPath: [
{
required: true,
message: () => t('form.validate.name.required')
}
],
msg: [
{
required: true,
message: () => t('form.validate.name.required')
}
],
author: [
{
required: true,
message: () => t('form.validate.name.required')
}
],
email: [
{
required: true,
message: () => t('form.validate.name.required')
}
]
})
const testOnChange = (val: any) => {
autoDeleteTest.value = val
}
const submitForm = async (formEl: FormInstance | undefined) => {
if (!formEl) return
const result = await formEl.validate((valid, fields) => {
if (valid) {
logUtil.logInfo("校验成功")
} else {
logUtil.logError(t('main.opt.failure'), fields)
// ElMessage.error(t('main.opt.failure'))
return
}
})
if (!result) {
return
}
// 保存配置
const vuepressCfg = undefined
// new VuepressCfg(formData.githubUser, formData.githubRepo, formData.githubToken,
// formData.defaultBranch, formData.defaultPath, formData.msg, formData.author, formData.email);
// setJSONConf<IGithubCfg>(API_TYPE_CONSTANTS.API_TYPE_VUEPRESS, vuepressCfg)
ElMessage.success(t('main.opt.success'))
}
const valiConf = async () => {
isLoading.value = true;
const vuepressCfg = undefined
// new VuepressCfg(formData.githubUser, formData.githubRepo, formData.githubToken,
// formData.defaultBranch, formData.defaultPath, formData.msg, formData.author, formData.email);
// const vuepressCfg = getJSONConf<IVuepressCfg>(API_TYPE_CONSTANTS.API_TYPE_VUEPRESS)
const testFile = "test.md"
const docPath = formData.defaultPath + testFile
const mdContent = "Hello World!" + formatIsoToZhDate(new Date().toISOString(), true)
const res = undefined //= await publishPage(vuepressCfg, docPath, mdContent)
isLoading.value = false
if (!res) {
// 验证不通过,更新验证状态
apiStatus.value = false
// setBooleanConf(API_STATUS_CONSTANTS.API_STATUS_VUEPRESS, apiStatus.value)
ElMessage.error(t('main.opt.failure'))
return
}
// 自动删除测试文章
if(autoDeleteTest.value){
// await deletePage(vuepressCfg,docPath)
}
// 验证通过,更新验证状态
apiStatus.value = true
// setBooleanConf(API_STATUS_CONSTANTS.API_STATUS_VUEPRESS, apiStatus.value)
// 预览
formData.previewUrl = "https://github.com/" + formData.githubUser + "/" + formData.githubRepo
+ "/blob/" + formData.defaultBranch + "/" + formData.defaultPath + testFile
ElMessage.success(t('main.opt.success'))
}
const resetForm = (formEl: FormInstance | undefined) => {
if (!formEl) return
formEl.resetFields()
}
const initConf = () => {
logUtil.logInfo("Vuepress配置初始化")
const conf = getJSONConf<IGithubCfg>(API_TYPE_CONSTANTS.API_TYPE_VUEPRESS)
if (conf) {
logUtil.logInfo("vuepress conf=>", conf)
formData.githubUser = conf.githubUser
formData.githubRepo = conf.githubRepo
formData.githubToken = conf.githubToken
formData.defaultBranch = conf.defaultBranch
formData.defaultPath = conf.defaultPath
formData.msg = conf.defaultMsg
formData.author = conf.author
formData.email = conf.email
}
// api状态
// apiStatus.value = getBooleanConf(API_STATUS_CONSTANTS.API_STATUS_VUEPRESS);
}
onBeforeMount(async () => {
initConf();
})
</script>

<script lang="ts">
export default {
name: "VuepressSetting"
}
</script>
import {ref} from "vue";
import {VuepressCfg} from "~/utils/platform/github/vuepress/VuepressCfg";
<style scoped>
.el-alert {
margin-top: 10px;
}
</style>
const apiType = ref(API_TYPE_CONSTANTS.API_TYPE_VUEPRESS)
const vuepressCfg = new VuepressCfg()
const cfg = ref(vuepressCfg)
</script>
9 changes: 4 additions & 5 deletions src/utils/dynamicConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,11 @@ export enum PlantformType {
* @author terwer
*/
export enum SubPlantformType {
Github_pages = "pages",
Github_giteePages = "giteePages",
Github_codingPages = "codingPages",
Github_Hugo = "Hugo",
Github_Hexo = "Hexo",
Github_Jekyll = "Jekyll",
Github_giteePages = "giteePages",
Github_codingPages = "codingPages",
Github_Vuepress = "Vuepress",
Github_Vitepress = "Vitepress",
Github_Nuxt = "Nuxt",
Expand All @@ -97,11 +96,11 @@ export function getSubtypeList(ptype: PlantformType): Array<SubPlantformType> {

switch (ptype) {
case PlantformType.Github:
subtypeList.push(SubPlantformType.Github_pages)
subtypeList.push(SubPlantformType.Github_giteePages)
subtypeList.push(SubPlantformType.Github_Hugo)
subtypeList.push(SubPlantformType.Github_Hexo)
subtypeList.push(SubPlantformType.Github_Jekyll)
subtypeList.push(SubPlantformType.Github_giteePages)
subtypeList.push(SubPlantformType.Github_codingPages)
subtypeList.push(SubPlantformType.Github_Vuepress)
subtypeList.push(SubPlantformType.Github_Vitepress)
subtypeList.push(SubPlantformType.Github_Nuxt)
Expand Down
Loading

0 comments on commit 1f3ea54

Please sign in to comment.