Skip to content

Commit

Permalink
fix: #311 Github系列平台支持单篇文章重新设置formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Jan 7, 2023
1 parent 49e224b commit 72569a7
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 5 deletions.
35 changes: 35 additions & 0 deletions components/publish/tab/main/GithubMain.vue
Expand Up @@ -343,6 +343,40 @@
</div>
</div>

<!-- 附加属性,用于适配 -->
<div
class="addition-attributes"
v-if="pageModeData.etype === PageEditMode.EditMode_complex"
>
<!-- 是否使用永久链接 -->
<el-form-item :label="$t('github.use.permalink')">
<el-switch
v-model="githubPagesData.usePermalink"
@change="githubPagesMethods.permalinkOnChange"
/>
<el-alert
v-if="!githubPagesData.usePermalink"
:closable="false"
:title="$t('github.use.permalink.no.warn')"
type="warning"
/>
</el-form-item>
<!-- 菜单标题 -->
<el-form-item :label="$t('github.menu.title')">
<el-input
v-model="githubPagesData.linkTitle"
:placeholder="$t('github.menu.title.placeholder')"
/>
</el-form-item>
<!-- 权重 -->
<el-form-item :label="$t('github.weight')">
<el-input
v-model="githubPagesData.weight"
:placeholder="$t('github.weight.placeholder')"
/>
</el-form-item>
</div>

<!-- 快捷操作 -->
<div
v-if="pageModeData.etype !== PageEditMode.EditMode_source"
Expand All @@ -366,6 +400,7 @@
</el-button>
</el-form-item>

<!-- 属性转换 -->
<el-form-item
v-if="pageModeData.etype !== PageEditMode.EditMode_simple"
>
Expand Down
15 changes: 15 additions & 0 deletions composables/publish/githubPagesCom.ts
Expand Up @@ -65,6 +65,18 @@ export const useGithubPages = (props, deps) => {
* 最终发布的路径
*/
publishPath: "",
/**
* 是否生成永久链接(HUGO平台专用)
*/
usePermalink: true,
/**
* 菜单栏标题(HUGO平台专用,为空则不显示在菜单)
*/
linkTitle: "",
/**
* 权重(决定显示顺序,越小显示越靠前)
*/
weight: 0,
})

// deps
Expand Down Expand Up @@ -140,6 +152,9 @@ export const useGithubPages = (props, deps) => {
githubPagesMethods.onSelectChange(val)
logger.info("触发文件名修改,同步发布路径.")
},
permalinkOnChange: (val: boolean) => {
githubPagesData.usePermalink = val
},

getGithubPagesData: () => {
return githubPagesData
Expand Down
8 changes: 8 additions & 0 deletions composables/publish/initPublishCom.ts
Expand Up @@ -179,6 +179,14 @@ export const useInitPublish = (props, deps, otherArgs?) => {
}
postForm.formData.mdContent = md
postForm.formData.htmlContent = html
// 是否生成永久链接
postForm.formData.usePermalink =
githubPagesMethods.getGithubPagesData().usePermalink
// 菜单标题
postForm.formData.linkTitle =
githubPagesMethods.getGithubPagesData().linkTitle
// 权重
postForm.formData.weight = githubPagesMethods.getGithubPagesData().weight

return postForm
},
Expand Down
9 changes: 9 additions & 0 deletions locales/en_US.ts
Expand Up @@ -326,4 +326,13 @@ export default {
"picgo.pic.setting": "Picture setting",
"picgo.pic.setting.no.tip":
"You are currently using the browser plug -in and cannot inherit PicGo. You can only call the local Picgo client on the local Picgo client through HTTP",
"github.use.permalink": "Use permalink",
"github.use.permalink.no.warn":
"You have closed the permanent link, and Formatter will not generate a mark, which may be useful in some scenarios",
"github.menu.title": "Menu title",
"github.menu.title.placeholder":
"The menu column title (HUGO platform is dedicated, but the empty is not displayed in the menu)",
"github.weight": "Weight",
"github.weight.placeholder":
"Weight (decide to display the order, the smaller the display, the more upward)",
}
8 changes: 8 additions & 0 deletions locales/zh_CN.ts
Expand Up @@ -338,4 +338,12 @@ export default {
"picgo.pic.setting": "图床设置",
"picgo.pic.setting.no.tip":
"您当前使用的是浏览器插件,无法直接集成PicGO,只能通过HTTP请求间接调用本地PicGO客户端上图片,请直接在本地PicGO客户端进行设置。如需体验更加完整的功能,请通过思源笔记挂件版挂载菜单打开新窗口的方式使用",
"github.use.permalink": "永久链接",
"github.use.permalink.no.warn":
"您已关闭永久链接,formatter将不会生成标记,这在某些特殊场景下可能有用,大部分情况下需要开启此选项,注意:目前仅仅在HUGO平台生效,主要是适配Docsy",
"github.menu.title": "菜单标题",
"github.menu.title.placeholder":
"菜单栏标题(HUGO平台专用,为空则不显示在菜单)",
"github.weight": "显示权重",
"github.weight.placeholder": "权重(决定显示顺序,越小显示越靠前)",
}
5 changes: 4 additions & 1 deletion utils/models/postForm.ts
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Terwer . All rights reserved.
* Copyright (c) 2022-2023, Terwer . All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -43,5 +43,8 @@ export class PostForm {
categories: ["默认分类"],
mdContent: "",
htmlContent: "",
usePermalink: true,
linkTitle: "",
weight: 0,
}
}
26 changes: 22 additions & 4 deletions utils/platform/github/hugo/HugoYamlConverterAdaptor.ts
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Terwer . All rights reserved.
* Copyright (c) 2022-2023, Terwer . All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -33,6 +33,7 @@ import { YamlFormatObj } from "~/utils/models/yamlFormatObj"
import { LogFactory } from "~/utils/logUtil"
import { obj2Yaml } from "~/utils/yamlUtil"
import { formatIsoToZhDate } from "~/utils/dateUtil"
import { isEmptyString } from "~/utils/util"

/**
* Hugo平台的YAMl解析器
Expand All @@ -56,9 +57,12 @@ export class HugoYamlConverterAdaptor
// slug
yamlFormatObj.yamlObj.slug = postForm.formData.customSlug

// url
yamlFormatObj.yamlObj.url =
"/post/" + postForm.formData.customSlug + ".html"
// 固定连接开关
if (postForm.formData.usePermalink) {
// url
yamlFormatObj.yamlObj.url =
"/post/" + postForm.formData.customSlug + ".html"
}

// date
yamlFormatObj.yamlObj.date = postForm.formData.created
Expand All @@ -85,6 +89,20 @@ export class HugoYamlConverterAdaptor
// isCJKLanguage
yamlFormatObj.yamlObj.isCJKLanguage = true

// linkTitle
// weight
if (!isEmptyString(postForm.formData.linkTitle)) {
yamlFormatObj.yamlObj.linkTitle = postForm.formData.linkTitle
yamlFormatObj.yamlObj.weight = parseInt(
postForm.formData.weight.toString()
)
yamlFormatObj.yamlObj.menu = {
main: {
weight: parseInt(postForm.formData.weight.toString()),
},
}
}

// formatter
let yaml = obj2Yaml(yamlFormatObj.yamlObj)
// 修复yaml的ISO日期格式(js-yaml转换的才需要)
Expand Down

0 comments on commit 72569a7

Please sign in to comment.