Skip to content
This repository has been archived by the owner on Jan 20, 2023. It is now read-only.

Commit

Permalink
feat: "home" option and default title and description
Browse files Browse the repository at this point in the history
  • Loading branch information
ulivz committed Feb 4, 2019
1 parent 9b6c95a commit 7b2505d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 9 deletions.
10 changes: 7 additions & 3 deletions example/.vuepress/config.js
Original file line number Diff line number Diff line change
@@ -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 © 蚂蚁金服体验技术部`
}
}
]
]
Expand Down
3 changes: 0 additions & 3 deletions example/README.md

This file was deleted.

37 changes: 34 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)} ...`
Expand All @@ -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) {
Expand All @@ -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}`,
}
})
}
}
}
}

0 comments on commit 7b2505d

Please sign in to comment.