feat: support sitemap and seo
新增 sitemap和seo支持
This commit is contained in:
parent
397c8e4364
commit
a57af599e6
@ -10,6 +10,7 @@ export default defineUserConfig<PlumeThemeOptions>({
|
||||
theme: '@vuepress-plume/vuepress-theme-plume',
|
||||
themeConfig: {
|
||||
logo: 'https://pengzhanbo.cn/g.gif',
|
||||
hostname: 'https://pengzhanbo.cn',
|
||||
avatar: {
|
||||
url: '/images/blogger.jpg',
|
||||
name: 'Plume Theme',
|
||||
|
||||
@ -19,9 +19,10 @@
|
||||
"docs:webpack-build": "vuepress-webpack build docs",
|
||||
"docs:webpack-serve": "vuepress-webpack dev docs",
|
||||
"lerna": "lerna clean && lerna bootstrap",
|
||||
"lerna:publish": "node scripts/release/index.mjs",
|
||||
"lerna:publish": "node scripts/release/index.mjs --input-type module",
|
||||
"lint": "eslint --ext .js,.ts,.vue .",
|
||||
"package:clean": "lerna run clean",
|
||||
"package:update": "node scripts/dependencies.js",
|
||||
"prepare": "husky install",
|
||||
"release": "yarn lint && yarn build && lerna publish --registry https://registry.npmjs.org/"
|
||||
},
|
||||
|
||||
@ -55,12 +55,12 @@
|
||||
"sass-loader": "^12.6.0",
|
||||
"vue": "^3.2.33",
|
||||
"vue-router": "^4.0.14",
|
||||
"vuepress-plugin-comment2": "^2.0.0-beta.45",
|
||||
"vuepress-plugin-copy-code2": "^2.0.0-beta.45",
|
||||
"vuepress-plugin-md-enhance": "^2.0.0-beta.45",
|
||||
"vuepress-plugin-reading-time2": "^2.0.0-beta.45",
|
||||
"vuepress-plugin-seo2": "^2.0.0-beta.36",
|
||||
"vuepress-plugin-sitemap2": "^2.0.0-beta.36"
|
||||
"vuepress-plugin-comment2": "^2.0.0-beta.47",
|
||||
"vuepress-plugin-copy-code2": "^2.0.0-beta.47",
|
||||
"vuepress-plugin-md-enhance": "^2.0.0-beta.47",
|
||||
"vuepress-plugin-reading-time2": "^2.0.0-beta.47",
|
||||
"vuepress-plugin-seo2": "^2.0.0-beta.47",
|
||||
"vuepress-plugin-sitemap2": "^2.0.0-beta.47"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
|
||||
@ -14,6 +14,8 @@ import { resolveNprogress } from './nprogress'
|
||||
import { resolvePalette } from './palette'
|
||||
import { resolvePrismjs } from './prismjs'
|
||||
import { resolveSearch } from './search'
|
||||
import { resolveSeo } from './seo'
|
||||
import { resolveSitemap } from './sitemap'
|
||||
import { resolveThemeData } from './themeData'
|
||||
|
||||
export const getPlugins = (
|
||||
@ -33,6 +35,8 @@ export const getPlugins = (
|
||||
resolveCopyCode(plugins),
|
||||
resolveMarkdownEnhance(plugins),
|
||||
resolveComment(plugins),
|
||||
resolveSitemap(plugins, localeOptions),
|
||||
resolveSeo(plugins, localeOptions),
|
||||
resolveThemeData(localeOptions),
|
||||
].filter((item) => item[1] !== false)
|
||||
}
|
||||
|
||||
17
packages/theme/src/node/plugins/seo.ts
Normal file
17
packages/theme/src/node/plugins/seo.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import type { PluginConfig } from '@vuepress/core'
|
||||
import { seo } from 'vuepress-plugin-seo2'
|
||||
import type {
|
||||
PlumeThemeLocaleOptions,
|
||||
PlumeThemePluginOptions,
|
||||
} from '../../shared'
|
||||
|
||||
export const resolveSeo = (
|
||||
plugins: PlumeThemePluginOptions,
|
||||
localeOptions: PlumeThemeLocaleOptions
|
||||
): PluginConfig => {
|
||||
if (plugins.sitemap === false || !localeOptions.hostname) return ['', false]
|
||||
return seo({
|
||||
hostname: localeOptions.hostname,
|
||||
author: localeOptions.avatar?.name,
|
||||
})
|
||||
}
|
||||
16
packages/theme/src/node/plugins/sitemap.ts
Normal file
16
packages/theme/src/node/plugins/sitemap.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import type { PluginConfig } from '@vuepress/core'
|
||||
import { sitemap } from 'vuepress-plugin-sitemap2'
|
||||
import type {
|
||||
PlumeThemeLocaleOptions,
|
||||
PlumeThemePluginOptions,
|
||||
} from '../../shared'
|
||||
|
||||
export const resolveSitemap = (
|
||||
plugins: PlumeThemePluginOptions,
|
||||
localeOptions: PlumeThemeLocaleOptions
|
||||
): PluginConfig => {
|
||||
if (plugins.sitemap === false || !localeOptions.hostname) return ['', false]
|
||||
return sitemap({
|
||||
hostname: localeOptions.hostname,
|
||||
})
|
||||
}
|
||||
@ -70,6 +70,13 @@ export interface PlumeThemeLocaleData extends LocaleData {
|
||||
*/
|
||||
darkMode?: boolean
|
||||
|
||||
/**
|
||||
* 部署站点域名。
|
||||
* 用于生成 sitemap、 seo等。
|
||||
*
|
||||
*/
|
||||
hostname?: string
|
||||
|
||||
/**
|
||||
* 配置博主拥有者信息
|
||||
*
|
||||
|
||||
@ -36,4 +36,6 @@ export interface PlumeThemePluginOptions {
|
||||
markdownEnhance?: false | MarkdownEnhanceOptions
|
||||
|
||||
comment?: false | CommentOptions
|
||||
|
||||
sitemap?: false
|
||||
}
|
||||
|
||||
60
scripts/dependencies.js
Normal file
60
scripts/dependencies.js
Normal file
@ -0,0 +1,60 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import { execa } from 'execa'
|
||||
import ora from 'ora'
|
||||
import chalk from 'chalk'
|
||||
|
||||
const packages = fs.readdirSync(new URL('../packages', import.meta.url))
|
||||
|
||||
const dependencies = packages.map(dir => {
|
||||
const dirname = new URL(path.join('../packages', dir), import.meta.url)
|
||||
const pkg = fs.readFileSync(path.join(dirname.pathname, 'package.json'))
|
||||
const { dependencies, devDependencies } = JSON.parse(pkg)
|
||||
return {
|
||||
dirname: dirname.pathname,
|
||||
dependencies: filterVuePress(Object.keys(dependencies || {})),
|
||||
devDependencies: filterVuePress(Object.keys(devDependencies || {}))
|
||||
}
|
||||
})
|
||||
|
||||
function filterVuePress(dependencies) {
|
||||
const vuepress = dependencies.filter(
|
||||
dependence => dependence.startsWith('@vuepress/') || dependence.startsWith('vuepress-')
|
||||
).map(dependence => dependence + '@next')
|
||||
const includes = ['vue', 'vue-router']
|
||||
const vue = dependencies.filter(
|
||||
dependence => includes.includes(dependence)
|
||||
)
|
||||
return [...vue, ...vuepress]
|
||||
}
|
||||
|
||||
const options = []
|
||||
dependencies.forEach(({ dirname, dependencies, devDependencies }) => {
|
||||
if (dependencies.length) {
|
||||
options.push(['yarn', ['add', ...dependencies], { cwd: dirname }])
|
||||
}
|
||||
if (devDependencies.length) {
|
||||
options.push(['yarn', ['add', '-D', ...devDependencies], { cwd: dirname }])
|
||||
}
|
||||
})
|
||||
|
||||
async function install(index = 0) {
|
||||
if (index >= options.length) return
|
||||
const opt = options[index]
|
||||
console.log(chalk.cyan(opt[2].cwd.split('/').slice(-2).join('/')));
|
||||
console.log(chalk.gray(opt[0], opt[1].join(' ')));
|
||||
console.log('\n');
|
||||
const spinner = ora('installing').start()
|
||||
const current = execa(opt[0], opt[1], opt[2])
|
||||
current.stdout.pipe(process.stdout)
|
||||
try {
|
||||
await current;
|
||||
spinner.succeed()
|
||||
await install(index + 1)
|
||||
} catch(e) {
|
||||
spinner.fail()
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
|
||||
install()
|
||||
Loading…
x
Reference in New Issue
Block a user