From 1fcf95d313e506cdfc20787122230808de29036e Mon Sep 17 00:00:00 2001 From: Willin Wang Date: Wed, 20 Jul 2022 12:05:22 +0800 Subject: [PATCH 01/11] feat: sidebar search --- .../theme/components/SearchInput.vue | 35 +++++++++++-------- .../theme/components/SidebarSearch.vue | 31 ++++++++-------- 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/docs/.vuepress/theme/components/SearchInput.vue b/docs/.vuepress/theme/components/SearchInput.vue index 5310c0183..86aab6972 100755 --- a/docs/.vuepress/theme/components/SearchInput.vue +++ b/docs/.vuepress/theme/components/SearchInput.vue @@ -32,7 +32,9 @@ > {{ s.title || s.path }} - > {{ s.header.title }} + > {{ s.header.title }} @@ -49,14 +51,14 @@ export default { name: "SearchBox", props: { - placeholder: String + placeholder: String, }, data() { return { query: "", focused: false, - focusIndex: 0 + focusIndex: 0, }; }, @@ -74,17 +76,17 @@ export default { let { pages } = this.$site; pages = pages // TODO: 暂时隐藏开发集成 新版页面 reference-new - .filter(item => !item.path.includes("reference-new/")) - .map(item => { + .filter((item) => !item.path.includes("reference-new/")) + .map((item) => { return { ...item, title: transformInterpolation(item.title, this), headers: item.headers && - item.headers.map(header => ({ + item.headers.map((header) => ({ ...header, - title: transformInterpolation(header.title, this) - })) + title: transformInterpolation(header.title, this), + })), }; }); const max = @@ -115,7 +117,7 @@ export default { res.push( Object.assign({}, p, { path: p.path + "#" + h.slug, - header: h + header: h, }) ); } @@ -130,7 +132,7 @@ export default { const navCount = (this.$site.themeConfig.nav || []).length; const repo = this.$site.repo ? 1 : 0; return navCount + repo <= 2; - } + }, }, mounted() { @@ -164,7 +166,7 @@ export default { : new Array(searchPaths); return ( - searchPaths.filter(path => { + searchPaths.filter((path) => { return page.path.match(path); }).length > 0 ); @@ -215,8 +217,8 @@ export default { unfocus() { this.focusIndex = -1; - } - } + }, + }, }; @@ -297,9 +299,14 @@ export default { color lighten($textColor, 35%) .page-title font-weight 600 + display block .header + display block font-size 0.9em - margin-left 0.25em + margin-top 0.25em + height 1em + line-height 1em + overflow hidden &.focused background-color #f3f4f5 a diff --git a/docs/.vuepress/theme/components/SidebarSearch.vue b/docs/.vuepress/theme/components/SidebarSearch.vue index 34708f683..98a02e650 100755 --- a/docs/.vuepress/theme/components/SidebarSearch.vue +++ b/docs/.vuepress/theme/components/SidebarSearch.vue @@ -27,9 +27,7 @@ > {{ s.title || s.path }} - > {{ s.header.title }} + {{ s.nav.join(" / ") }} @@ -47,7 +45,7 @@ export default { props: { placeholder: String, - items: Array + items: Array, }, data() { @@ -55,7 +53,7 @@ export default { query: "", focused: false, focusIndex: 0, - platLinks: [] + platLinks: [], }; }, watch: { @@ -65,8 +63,8 @@ export default { this.calcLinks(); }, immediate: true, - deep: true - } + deep: true, + }, }, computed: { @@ -75,14 +73,14 @@ export default { }, suggestions() { - const query = this.query.trim().toLowerCase(); + const query = this.query.toString().trim().toLowerCase(); if (!query) { return; } if (this.platLinks.length === 0) { this.calcLinks(); } - const result = this.platLinks.filter(item => + const result = this.platLinks.filter((item) => item.keywords.includes(query) ); return result; @@ -93,7 +91,7 @@ export default { const navCount = (this.$site.themeConfig.nav || []).length; const repo = this.$site.repo ? 1 : 0; return navCount + repo <= 2; - } + }, }, mounted() { @@ -107,8 +105,8 @@ export default { methods: { calcLinks() { const result = []; - function calcLinksWithChildren(items) { - items.forEach(item => { + function calcLinksWithChildren(items, nav = []) { + items.forEach((item) => { if (item.path) { result.push({ path: item.path, @@ -117,11 +115,12 @@ export default { .split("/") .pop() .toLowerCase()}${item.title.toLowerCase()}`, - dataIndex: item.dataIndex + dataIndex: item.dataIndex, + nav, }); } if (item.children && item.children.length > 0) { - calcLinksWithChildren(item.children); + calcLinksWithChildren(item.children, [...nav, item.title]); } }); } @@ -175,7 +174,7 @@ export default { unfocus() { this.focusIndex = -1; - } - } + }, + }, }; From 59e09e33f1b2189da3ae1c36f1c8492761140767 Mon Sep 17 00:00:00 2001 From: Willin Wang Date: Wed, 20 Jul 2022 19:57:08 +0800 Subject: [PATCH 02/11] feat: share link --- docs/.vuepress/config.js | 213 +++++++++--------- docs/.vuepress/enhanceApp.js | 2 + docs/.vuepress/theme/components/Share.vue | 110 +++++++++ .../theme/global-components/LastUpdated.vue | 16 +- docs/.vuepress/theme/util/index.js | 211 ++++++++--------- package.json | 1 + 6 files changed, 343 insertions(+), 210 deletions(-) create mode 100644 docs/.vuepress/theme/components/Share.vue diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index affd31a03..dc2589d49 100755 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -14,19 +14,19 @@ const head = [ rel: "icon", type: "image/png", sizes: "32x32", - href: "https://authing.cn/favicon.ico" - } + href: "https://authing.cn/favicon.ico", + }, ], [ "script", {}, - `!function(){var e=window.Cohere=window.Cohere||[];if(e.invoked)console.error("Tried to load Cohere twice");else{e.invoked=!0,e.snippet="0.2",e.methods=["init","identify","stop","showCode","getSessionUrl","makeCall","addCallStatusListener","removeCallStatusListener","widget","addSessionUrlListener","removeSessionUrlListener",],e.methods.forEach(function(o){e[o]=function(){var t=Array.prototype.slice.call(arguments);t.unshift(o),e.push(t)}});var o=document.createElement("script");o.type="text/javascript",o.async=!0,o.src="https://static.cohere.so/main.js",o.crossOrigin="anonymous";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(o,t)}}();` + `!function(){var e=window.Cohere=window.Cohere||[];if(e.invoked)console.error("Tried to load Cohere twice");else{e.invoked=!0,e.snippet="0.2",e.methods=["init","identify","stop","showCode","getSessionUrl","makeCall","addCallStatusListener","removeCallStatusListener","widget","addSessionUrlListener","removeSessionUrlListener",],e.methods.forEach(function(o){e[o]=function(){var t=Array.prototype.slice.call(arguments);t.unshift(o),e.push(t)}});var o=document.createElement("script");o.type="text/javascript",o.async=!0,o.src="https://static.cohere.so/main.js",o.crossOrigin="anonymous";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(o,t)}}();`, ], [ "script", {}, - `if(window.location.hostname === "docs.authing.cn"){window.Cohere.init("PUkf845sOZgDd59V6aTJCsuJ");}` - ] + `if(window.location.hostname === "docs.authing.cn"){window.Cohere.init("PUkf845sOZgDd59V6aTJCsuJ");}`, + ], ]; if (gaEnabled) { @@ -34,8 +34,8 @@ if (gaEnabled) { "script", { async: true, - src: `https://www.googletagmanager.com/gtag/js?id=${gTrackingId}` - } + src: `https://www.googletagmanager.com/gtag/js?id=${gTrackingId}`, + }, ]); head.push([ "script", @@ -44,7 +44,7 @@ if (gaEnabled) { function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); - gtag('config', '${gTrackingId}');` + gtag('config', '${gTrackingId}');`, ]); } @@ -59,16 +59,16 @@ module.exports = { markdown: { // lineNumbers: true, anchor: { - permalinkSymbol: "¶" + permalinkSymbol: "¶", }, toc: { - includeLevel: [2, 3, 4, 5] + includeLevel: [2, 3, 4, 5], }, extractHeaders: ["h2", "h3", "h4", "h5"], - extendMarkdown: md => { + extendMarkdown: (md) => { // 使用更多的 markdown-it 插件! md.use(require("markdown-it-include"), "docs"); - } + }, }, locales: { // The key is the path for the locale to be nested under. @@ -88,7 +88,7 @@ module.exports = { back: "回到列表", next: "下一步", previous: "上一步", - lastStep: "我知道了,返回列表" + lastStep: "我知道了,返回列表", }, "/en/": { lang: "en-US", @@ -105,13 +105,12 @@ module.exports = { back: "Back to list", next: "Next", previous: "Previous", - lastStep: "I know, return to the list" - } + lastStep: "I know, return to the list", + }, }, head, themeConfig: { - logo: - "https://files.authing.co/authing-console/authing-logo-new-20210924.svg", + logo: "https://files.authing.co/authing-console/authing-logo-new-20210924.svg", officeSiteDomain: "authing.cn", officeSiteUrl: "https://authing.cn", consoleDomain: "https://console.authing.cn", @@ -137,6 +136,11 @@ module.exports = { search: "搜索标题", searchInDoc: "在文档中搜索", oldVersion: "旧版", + share: { + share: "分享", + copyLink: "复制链接", + copied: "链接已复制", + }, nav: [ { text: "快速开始", link: "/quickstarts/" }, { text: "概念", link: "/concepts/" }, @@ -144,22 +148,22 @@ module.exports = { { text: "开发集成", link: "/reference/" }, { text: "应用集成", - link: "/integration/" + link: "/integration/", }, { text: "加入 APN", - link: "/apn/" + link: "/apn/", }, { link: "/reference-new/", text: "开发集成", - hidden: true + hidden: true, }, { link: "/tenant/", text: "多租户(内测版)", - hidden: true - } + hidden: true, + }, ], sidebar: sidebar.zhCnNavBar, feedback: { @@ -175,32 +179,32 @@ module.exports = { reasons: [ { value: "内容错误", - label: "内容错误" + label: "内容错误", }, { value: "缺少代码/图片示例", - label: "缺少代码/图片示例" + label: "缺少代码/图片示例", }, { value: "更新不及时", - label: "更新不及时" + label: "更新不及时", }, { value: "太简单/步骤待完善", - label: "太简单/步骤待完善" + label: "太简单/步骤待完善", }, { value: "链接错误", - label: "链接错误" + label: "链接错误", }, { value: "其他", - label: "其他" - } + label: "其他", + }, ], customReasonPlaceholder: - "请详细描述在文档使用中遇到的问题或改进建议(选填)" - } + "请详细描述在文档使用中遇到的问题或改进建议(选填)", + }, }, footer: { sections: [ @@ -209,81 +213,81 @@ module.exports = { links: [ { text: "集成第三方登录", - link: "/guides/connections/" + link: "/guides/connections/", }, { text: "手机号闪验", - link: "https://authing.cn/verify" + link: "https://authing.cn/verify", }, { text: "通用登录表单组件", - link: "/reference/ui-components/" + link: "/reference/ui-components/", }, { text: "自定义认证流程", - link: "/guides/pipeline/" - } - ] + link: "/guides/pipeline/", + }, + ], }, { title: "企业内部管理", links: [ { text: "单点登录", - link: "/guides/authentication/sso/" + link: "/guides/authentication/sso/", }, { text: "多因素认证", - link: "/guides/authentication/mfa/" + link: "/guides/authentication/mfa/", }, { text: "权限管理", - link: "/guides/access-control/" - } - ] + link: "/guides/access-control/", + }, + ], }, { title: "开发者", links: [ { text: "开发文档", - link: "/reference/" + link: "/reference/", }, { text: "框架集成", - link: "/reference/frameworks" + link: "/reference/frameworks", }, { text: "博客", - link: "https://authing.cn/blog" + link: "https://authing.cn/blog", }, { text: "GitHub", - link: "https://github.com/authing" + link: "https://github.com/authing", }, { text: "社区用户中心", - link: "https://forum.authing.cn/" - } - ] - } + link: "https://forum.authing.cn/", + }, + ], + }, ], socials: [ { icon: "authing-github", link: "https://github.com/Authing", - title: "GitHub" + title: "GitHub", }, { icon: "authing-gitter", link: "https://forum.authing.cn/", - title: "Forum" + title: "Forum", }, { icon: "authing-zhihu", link: "https://www.zhihu.com/org/authing", - title: "知乎" - } + title: "知乎", + }, ], // serviceStatus: "服务状态", contactPhone: "400 888 2106", @@ -293,8 +297,8 @@ module.exports = { "成都市高新区天府五街 200 号 1 号楼 B 区 4 楼 406 室(分)", icp: "京ICP备19051205号", beian: "京公网安备 11010802035968号", - companyName: "© 北京蒸汽记忆科技有限公司" - } + companyName: "© 北京蒸汽记忆科技有限公司", + }, }, "/en/": { // text for the language dropdown @@ -315,14 +319,19 @@ module.exports = { search: "Search", searchInDoc: "Search in Docs", oldVersion: "Old Version", + share: { + share: "Share", + copyLink: "Copy Link", + copied: "Link Copied", + }, nav: [ { text: "Concept", link: "/en/concepts/" }, { text: "Guides", link: "/en/guides/" }, { text: "Development Integration", link: "/en/reference/" }, { text: "Application integration", - link: "/en/integration/" - } + link: "/en/integration/", + }, ], sidebar: sidebar.enUsNavBar, feedback: { @@ -338,32 +347,32 @@ module.exports = { reasons: [ { value: "内容错误", - label: "Content error" + label: "Content error", }, { value: "缺少代码/图片示例", - label: "Missing code/image example" + label: "Missing code/image example", }, { value: "更新不及时", - label: "Update is not timely" + label: "Update is not timely", }, { value: "太简单/步骤待完善", - label: "Too simple/steps to be perfected" + label: "Too simple/steps to be perfected", }, { value: "链接错误", - label: "Link error" + label: "Link error", }, { value: "其他", - label: "Other" - } + label: "Other", + }, ], customReasonPlaceholder: - "Please describe in detail the problems encountered in the use of the document or suggestions for improvement (optional)" - } + "Please describe in detail the problems encountered in the use of the document or suggestions for improvement (optional)", + }, }, footer: { sections: [ @@ -372,81 +381,81 @@ module.exports = { links: [ { text: "Integrated third-party login", - link: "/en/guides/connections/" + link: "/en/guides/connections/", }, { text: "Mobile phone number flash check", - link: "https://authing.cn/verify" + link: "https://authing.cn/verify", }, { text: "Universal login form component", - link: "/en/reference/ui-components/" + link: "/en/reference/ui-components/", }, { text: "Custom authentication process", - link: "/en/guides/pipeline/" - } - ] + link: "/en/guides/pipeline/", + }, + ], }, { title: "Enterprise internal management", links: [ { text: "Single Sign On", - link: "/en/guides/authentication/sso/" + link: "/en/guides/authentication/sso/", }, { text: "Multi-factor Authentication", - link: "/en/guides/authentication/mfa/" + link: "/en/guides/authentication/mfa/", }, { text: "Authority Management", - link: "/en/guides/access-control/" - } - ] + link: "/en/guides/access-control/", + }, + ], }, { title: "Developers", links: [ { text: "Development Document", - link: "/en/reference/" + link: "/en/reference/", }, { text: "Framework Integration", - link: "/en/reference/frameworks" + link: "/en/reference/frameworks", }, { text: "Blog", - link: "https://authing.cn/blog" + link: "https://authing.cn/blog", }, { text: "GitHub", - link: "https://github.com/authing" + link: "https://github.com/authing", }, { text: "Community User Center", - link: "https://forum.authing.cn/" - } - ] - } + link: "https://forum.authing.cn/", + }, + ], + }, ], socials: [ { icon: "authing-github", link: "https://github.com/Authing", - title: "GitHub" + title: "GitHub", }, { icon: "authing-gitter", link: "https://forum.authing.cn/", - title: "Forum" + title: "Forum", }, { icon: "authing-zhihu", link: "https://www.zhihu.com/org/authing", - title: "ZhiHu" - } + title: "ZhiHu", + }, ], // serviceStatus: "Service Status", contactPhone: "400 888 2106", @@ -456,10 +465,10 @@ module.exports = { contactChenduAddress: "room 406, 4th floor, zone B, building 1, No. 200, Tianfu Fifth Street, Chengdu(branch)", icp: "Beijing ICP No.19051205-1", - companyName: "© Beijing Steamory Technology Co." - } - } - } + companyName: "© Beijing Steamory Technology Co.", + }, + }, + }, }, configureWebpack: (config, isServer) => { return { @@ -473,29 +482,29 @@ module.exports = { // }, // }, output: { - publicPath: process.env.PUBLIC_URL || basePath + publicPath: process.env.PUBLIC_URL || basePath, }, resolve: { alias: { "@imagesZhCn": path.resolve(__dirname, "../images"), - "@imagesEnUs": path.resolve(__dirname, "../en/images") - } + "@imagesEnUs": path.resolve(__dirname, "../en/images"), + }, }, plugins: [ process.env.npm_lifecycle_event !== "docs:dev" && new webpack.optimize.LimitChunkCountPlugin({ - maxChunks: 50 - }) + maxChunks: 50, + }), // new webpack.optimize.MinChunkSizePlugin({ // minChunkSize: 500000, // Minimum number of characters // }), - ].filter(Boolean) + ].filter(Boolean), }; }, extraWatchFiles: [ ".vuepress/enhanceApp.js", ".vuepress/env.js", ".vuepress/sidebar.js", - "README.md" - ] + "README.md", + ], }; diff --git a/docs/.vuepress/enhanceApp.js b/docs/.vuepress/enhanceApp.js index f1cddecc4..6a1b18318 100755 --- a/docs/.vuepress/enhanceApp.js +++ b/docs/.vuepress/enhanceApp.js @@ -3,10 +3,12 @@ import VueSelect from "vue-select"; import "vue-select/src/scss/vue-select.scss"; import Pagination from "vue-pagination-2"; import VTooltip from "v-tooltip"; +import VueClipboard from "vue-clipboard2"; export default ({ Vue, options, router, siteData }) => { Vue.use(VueNotification); Vue.use(VTooltip); + Vue.use(VueClipboard); Vue.component("v-select", VueSelect); Vue.component("v-pagination", Pagination); Vue.prototype.$eventBus = new Vue(); diff --git a/docs/.vuepress/theme/components/Share.vue b/docs/.vuepress/theme/components/Share.vue new file mode 100644 index 000000000..4f25cc82c --- /dev/null +++ b/docs/.vuepress/theme/components/Share.vue @@ -0,0 +1,110 @@ + + + + + diff --git a/docs/.vuepress/theme/global-components/LastUpdated.vue b/docs/.vuepress/theme/global-components/LastUpdated.vue index d6512ff06..4621e33fe 100755 --- a/docs/.vuepress/theme/global-components/LastUpdated.vue +++ b/docs/.vuepress/theme/global-components/LastUpdated.vue @@ -10,6 +10,10 @@
+ + + + {{ $localeConfig.githubEdit }} @@ -35,10 +37,11 @@ @@ -74,6 +77,7 @@ export default { align-items center justify-content space-between .github-edit + display flex margin-left 20px a line-height: 20px; diff --git a/docs/.vuepress/theme/util/index.js b/docs/.vuepress/theme/util/index.js index a15715d66..1c0d8bfc9 100755 --- a/docs/.vuepress/theme/util/index.js +++ b/docs/.vuepress/theme/util/index.js @@ -1,123 +1,121 @@ -import get from 'lodash/get' +import get from "lodash/get"; -export const hashRE = /#.*$/ -export const extRE = /\.(md|html)$/ -export const endingSlashRE = /\/$/ -export const outboundRE = /^[a-z]+:/i +export const hashRE = /#.*$/; +export const extRE = /\.(md|html)$/; +export const endingSlashRE = /\/$/; +export const outboundRE = /^[a-z]+:/i; export function normalize(path) { - return decodeURI(path) - .replace(hashRE, '') - .replace(extRE, '') + return decodeURI(path).replace(hashRE, "").replace(extRE, ""); } -export function getHash(path) { - const match = path.match(hashRE) +export function getHash(path = "") { + const match = path.match(hashRE); if (match) { - return match[0] + return match[0]; } } export function isExternal(path) { - return outboundRE.test(path) + return outboundRE.test(path); } export function isMailto(path) { - return /^mailto:/.test(path) + return /^mailto:/.test(path); } export function isTel(path) { - return /^tel:/.test(path) + return /^tel:/.test(path); } export function ensureExt(path) { if (isExternal(path)) { - return path + return path; } - const hashMatch = path.match(hashRE) - const hash = hashMatch ? hashMatch[0] : '' - const normalized = normalize(path) + const hashMatch = path.match(hashRE); + const hash = hashMatch ? hashMatch[0] : ""; + const normalized = normalize(path); if (endingSlashRE.test(normalized)) { - return path + return path; } - return normalized + '.html' + hash + return normalized + ".html" + hash; } export function isActive(route, path) { - const routeHash = decodeURIComponent(route.hash) - const linkHash = getHash(path) + const routeHash = decodeURIComponent(route.hash); + const linkHash = getHash(path); if (linkHash && routeHash !== linkHash) { - return false + return false; } - const routePath = normalize(route.path) - const pagePath = normalize(path) - return routePath === pagePath + const routePath = normalize(route.path); + const pagePath = normalize(path); + return routePath === pagePath; } export function resolvePage(pages, rawPath, base, dataIndex) { if (isExternal(rawPath)) { return { - type: 'external', + type: "external", path: rawPath, - } + }; } if (base) { - rawPath = resolvePath(rawPath, base) + rawPath = resolvePath(rawPath, base); } - const path = normalize(rawPath) + const path = normalize(rawPath); for (let i = 0; i < pages.length; i++) { if (normalize(pages[i].regularPath) === path) { - pages[i].dataIndex = dataIndex + pages[i].dataIndex = dataIndex; return Object.assign({}, pages[i], { - type: 'page', + type: "page", path: ensureExt(pages[i].path), - dataIndex: dataIndex - }) + dataIndex: dataIndex, + }); } } console.error( `[vuepress] No matching page found for sidebar item "${rawPath}"` - ) - return {} + ); + return {}; } function resolvePath(relative, base, append) { - const firstChar = relative.charAt(0) - if (firstChar === '/') { - return relative + const firstChar = relative.charAt(0); + if (firstChar === "/") { + return relative; } - if (firstChar === '?' || firstChar === '#') { - return base + relative + if (firstChar === "?" || firstChar === "#") { + return base + relative; } - const stack = base.split('/') + const stack = base.split("/"); // remove trailing segment if: // - not appending // - appending to trailing slash (last segment is empty) if (!append || !stack[stack.length - 1]) { - stack.pop() + stack.pop(); } // resolve relative path - const segments = relative.replace(/^\//, '').split('/') + const segments = relative.replace(/^\//, "").split("/"); for (let i = 0; i < segments.length; i++) { - const segment = segments[i] - if (segment === '..') { - stack.pop() - } else if (segment !== '.') { - stack.push(segment) + const segment = segments[i]; + if (segment === "..") { + stack.pop(); + } else if (segment !== ".") { + stack.push(segment); } } // ensure leading slash - if (stack[0] !== '') { - stack.unshift('') + if (stack[0] !== "") { + stack.unshift(""); } - return stack.join('/') + return stack.join("/"); } /** @@ -128,28 +126,32 @@ function resolvePath(relative, base, append) { * @returns { SidebarGroup } */ export function resolveSidebarItems(page, regularPath, site, localePath) { - const { pages, themeConfig } = site + const { pages, themeConfig } = site; const localeConfig = localePath && themeConfig.locales ? themeConfig.locales[localePath] || themeConfig - : themeConfig + : themeConfig; const pageSidebarConfig = - page.frontmatter.sidebar || localeConfig.sidebar || themeConfig.sidebar - if (pageSidebarConfig === 'auto') { - return resolveHeaders(page) + page.frontmatter.sidebar || localeConfig.sidebar || themeConfig.sidebar; + if (pageSidebarConfig === "auto") { + return resolveHeaders(page); } - const sidebarConfig = localeConfig.sidebar || themeConfig.sidebar + const sidebarConfig = localeConfig.sidebar || themeConfig.sidebar; if (!sidebarConfig) { - return [] + return []; } else { - const { base, config } = resolveMatchingConfig(regularPath, sidebarConfig) - if (config === 'auto') { - return resolveHeaders(page) + const { base, config } = resolveMatchingConfig(regularPath, sidebarConfig); + if (config === "auto") { + return resolveHeaders(page); } - return config ? config.map((item, index) => resolveItem(item, pages, base, 1, `${index}`)) : [] + return config + ? config.map((item, index) => + resolveItem(item, pages, base, 1, `${index}`) + ) + : []; } } @@ -158,42 +160,42 @@ export function resolveSidebarItems(page, regularPath, site, localePath) { * @returns { SidebarGroup } */ function resolveHeaders(page) { - const headers = groupHeaders(page.headers || []) + const headers = groupHeaders(page.headers || []); return [ { - type: 'group', + type: "group", collapsable: false, title: page.title, path: null, children: headers.map((h) => ({ - type: 'auto', + type: "auto", title: h.title, basePath: page.path, - path: page.path + '#' + h.slug, + path: page.path + "#" + h.slug, children: h.children || [], })), }, - ] + ]; } export function groupHeaders(headers) { // group h3s under h2 - headers = headers.map((h) => Object.assign({}, h)) - let lastH2 + headers = headers.map((h) => Object.assign({}, h)); + let lastH2; headers.forEach((h) => { if (h.level === 2) { - lastH2 = h + lastH2 = h; } else if (lastH2) { - ;(lastH2.children || (lastH2.children = [])).push(h) + (lastH2.children || (lastH2.children = [])).push(h); } - }) - return headers.filter((h) => h.level === 2) + }); + return headers.filter((h) => h.level === 2); } export function resolveNavLinkItem(linkItem) { return Object.assign(linkItem, { - type: linkItem.items && linkItem.items.length ? 'links' : 'link', - }) + type: linkItem.items && linkItem.items.length ? "links" : "link", + }); } /** @@ -204,41 +206,41 @@ export function resolveNavLinkItem(linkItem) { export function resolveMatchingConfig(regularPath, config) { if (Array.isArray(config)) { return { - base: '/', + base: "/", config: config, - } + }; } for (const base in config) { if (ensureEndingSlash(regularPath).indexOf(encodeURI(base)) === 0) { return { base, config: config[base], - } + }; } } - return {} + return {}; } function ensureEndingSlash(path) { - return /(\.html|\/)$/.test(path) ? path : path + '/' + return /(\.html|\/)$/.test(path) ? path : path + "/"; } -function resolveItem(item, pages, base, groupDepth = 1, dataIndex = '') { - if (typeof item === 'string') { - return resolvePage(pages, item, base, dataIndex) +function resolveItem(item, pages, base, groupDepth = 1, dataIndex = "") { + if (typeof item === "string") { + return resolvePage(pages, item, base, dataIndex); } else if (Array.isArray(item)) { return Object.assign(resolvePage(pages, item[0], base, dataIndex), { title: item[1], - }) + }); } else { - const children = item.children || [] + const children = item.children || []; if (children.length === 0 && item.path) { return Object.assign(resolvePage(pages, item.path, base, dataIndex), { title: item.title, - }) + }); } return { - type: 'group', + type: "group", path: item.path, title: item.title, sidebarDepth: item.sidebarDepth, @@ -249,18 +251,18 @@ function resolveItem(item, pages, base, groupDepth = 1, dataIndex = '') { resolveItem(child, pages, base, groupDepth + 1, `${dataIndex}-${index}`) ), collapsable: item.collapsable !== false, - } + }; } } export const transformInterpolation = (str, data) => { if (!str) { - return str + return str; } return str.replace(/\{\{([\$\w\.]+?)\}\}/, (matched, $1) => { - return get(data, $1, matched) - }) -} + return get(data, $1, matched); + }); +}; // export const getPlatform = () => { // /* @@ -303,13 +305,19 @@ export const transformInterpolation = (str, data) => { // export { platform } // } //写cookies -export function setCookie(name,value) -{ - var Days = 10; - var exp = new Date(); - exp.setTime(exp.getTime() + Days*24*60*60*1000); - // document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString()+ ";path=/" + ";domain=localhost"; - document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString()+ ";path=/" + ";domain=.authing.cn"; +export function setCookie(name, value) { + var Days = 10; + var exp = new Date(); + exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000); + // document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString()+ ";path=/" + ";domain=localhost"; + document.cookie = + name + + "=" + + escape(value) + + ";expires=" + + exp.toGMTString() + + ";path=/" + + ";domain=.authing.cn"; } //读取cookies @@ -332,7 +340,6 @@ export function getCookie(name) { } //删除cookies -export function delCookie(name) -{ +export function delCookie(name) { setCookie(name, ""); } diff --git a/package.json b/package.json index ded7701d3..5ddb404ca 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "markdown-it-include": "^2.0.0", "node-sass": "npm:dart-sass@^1.25.0", "v-tooltip": "^2.1.3", + "vue-clipboard2": "^0.3.3", "vue-notification": "^1.3.20", "vue-pagination-2": "^3.0.8", "vue-select": "^3.11.2" From f87b28d4469f5c07ffbf2d61a2a6fff42cae741c Mon Sep 17 00:00:00 2001 From: Willin Wang Date: Thu, 21 Jul 2022 09:57:13 +0800 Subject: [PATCH 03/11] feat: share --- docs/.vuepress/config.js | 4 ++ docs/.vuepress/theme/components/Share.vue | 70 +++++++++++++++++++++-- package.json | 1 + 3 files changed, 69 insertions(+), 6 deletions(-) diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index dc2589d49..74220a5fc 100755 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -139,6 +139,8 @@ module.exports = { share: { share: "分享", copyLink: "复制链接", + weibo: "新浪微博", + wechat: "微信扫一扫", copied: "链接已复制", }, nav: [ @@ -322,6 +324,8 @@ module.exports = { share: { share: "Share", copyLink: "Copy Link", + weibo: "Weibo", + wechat: "Wechat QRCode", copied: "Link Copied", }, nav: [ diff --git a/docs/.vuepress/theme/components/Share.vue b/docs/.vuepress/theme/components/Share.vue index 4f25cc82c..45a985526 100644 --- a/docs/.vuepress/theme/components/Share.vue +++ b/docs/.vuepress/theme/components/Share.vue @@ -1,7 +1,7 @@ @@ -41,9 +75,9 @@