From 7b2505dfc3f95498eaeff3e6353d08bcc01aa11e Mon Sep 17 00:00:00 2001 From: ULIVZ <472590061@qq.com> Date: Tue, 5 Feb 2019 02:22:26 +0800 Subject: [PATCH] feat: "home" option and default title and description --- example/.vuepress/config.js | 10 +++++++--- example/README.md | 3 --- lib/index.js | 37 ++++++++++++++++++++++++++++++++++--- 3 files changed, 41 insertions(+), 9 deletions(-) delete mode 100644 example/README.md diff --git a/example/.vuepress/config.js b/example/.vuepress/config.js index 7e7939f..f10c4e6 100644 --- a/example/.vuepress/config.js +++ b/example/.vuepress/config.js @@ -1,11 +1,15 @@ module.exports = { - title: 'Ant Design 实战教程', - description: 'build your yuque\'s docs via vuepress', plugins: [ [ require('../../lib/index.js'), { - repoId: '146550' + repoId: '146550', + home: { + // actionText: 'Getting Started →', + // actionLink: '/intro/', + // heroImage: 'https://cdn.nlark.com/yuque/0/2018/png/84868/1535520500482-avatar/20c595c5-ab31-4543-9142-f36cc87c8868.png?x-oss-process=image/resize,m_fill,w_320,h_320', + // footer: `Copyright © 蚂蚁金服体验技术部` + } } ] ] diff --git a/example/README.md b/example/README.md deleted file mode 100644 index 461d87e..0000000 --- a/example/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# vuepress-plugin-yuque - - diff --git a/lib/index.js b/lib/index.js index a2a6468..5a89580 100644 --- a/lib/index.js +++ b/lib/index.js @@ -51,7 +51,7 @@ module.exports = (opts, ctx) => { } spinner.succeed(`Retrieved repo detail`) - const { name, description } = repoDetail.data + const { name, description, user } = repoDetail.data spinner.succeed( `Your Yuque website: ${chalk.green(name)} ` + `${chalk.gray(description)} ...` @@ -72,6 +72,14 @@ module.exports = (opts, ctx) => { const sidebar = getSidebarByToc(toc.data) ctx.siteConfig.themeConfig = ctx.siteConfig.themeConfig || {} ctx.siteConfig.themeConfig.sidebar = sidebar + if (!ctx.siteConfig.title) { + ctx.siteConfig.title = name + } + if (!ctx.siteConfig.description) { + ctx.siteConfig.description = description + } + + let defaultActionLink // Apply pages for (const page of toc.data) { @@ -96,15 +104,38 @@ module.exports = (opts, ctx) => { ? postContent : `# ${title} \n ${postContent}` + const permalink = `/${slug}/` await ctx.addPage({ content, frontmatter, - permalink: `/${slug}/` + permalink }) + if (!defaultActionLink) { + defaultActionLink = permalink + } + spinner.succeed(`Retrieved ${chalk.cyan(title)} ... `) } + + if (ctx.pages.every(page => page.path !== '/')) { + const { home = {} } = opts + const { actionText, actionLink, heroImage, features, footer } = home + + spinner.info(`Apply default homepage`) + await ctx.addPage({ + content: '', + permalink: '/', + frontmatter: { + home: true, + heroImage: heroImage || user.large_avatar_url, + actionText: actionText || 'Getting Started →', + actionLink: actionLink || defaultActionLink, + features: features || undefined, + footer: footer || `Copyright © ${user.name}`, + } + }) + } } } } -