mirror of
https://github.com/wahyd4/vuepress.git
synced 2026-08-09 05:16:23 +10:00
chore: remove plugin-blog
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
__tests__
|
||||
__mocks__
|
||||
.temp
|
||||
@@ -1,9 +0,0 @@
|
||||
# @vuepress/plugin-blog
|
||||
|
||||
> blog plugin for vuepress
|
||||
|
||||
See [documentation](https://v1.vuepress.vuejs.org/plugin/official/plugin-blog.html).
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
import { findPageByKey } from '@app/util'
|
||||
import tagMeta from '@dynamic/tag'
|
||||
import categoryMeta from '@dynamic/category'
|
||||
|
||||
class Classifiable {
|
||||
constructor (metaMap, pages) {
|
||||
this._metaMap = Object.assign({}, metaMap)
|
||||
Object.keys(this._metaMap).forEach(name => {
|
||||
const { pageKeys } = this._metaMap[name]
|
||||
this._metaMap[name].posts = pageKeys.map(key => findPageByKey(pages, key))
|
||||
})
|
||||
}
|
||||
|
||||
get length () {
|
||||
return Object.keys(this._metaMap).length
|
||||
}
|
||||
|
||||
get map () {
|
||||
return this._metaMap
|
||||
}
|
||||
|
||||
get list () {
|
||||
return this.toArray()
|
||||
}
|
||||
|
||||
toArray () {
|
||||
const tags = []
|
||||
Object.keys(this._metaMap).forEach(name => {
|
||||
const { posts, path } = this._metaMap[name]
|
||||
tags.push({ name, posts, path })
|
||||
})
|
||||
return tags
|
||||
}
|
||||
|
||||
getItemByName (name) {
|
||||
return this._metaMap[name]
|
||||
}
|
||||
}
|
||||
|
||||
export default ({ Vue }) => {
|
||||
Vue.mixin({
|
||||
computed: {
|
||||
$tags () {
|
||||
const { pages } = this.$site
|
||||
const tags = new Classifiable(tagMeta, pages)
|
||||
return tags
|
||||
},
|
||||
$tag () {
|
||||
const tagName = this.$route.meta.tagName
|
||||
return this.$tags.getItemByName(tagName)
|
||||
},
|
||||
$categories () {
|
||||
const { pages } = this.$site
|
||||
const categories = new Classifiable(categoryMeta, pages)
|
||||
return categories
|
||||
},
|
||||
$category () {
|
||||
const categoryName = this.$route.meta.categoryName
|
||||
return this.$categories.getItemByName(categoryName)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -1,165 +0,0 @@
|
||||
const { path, datatypes: { isString }} = require('@vuepress/shared-utils')
|
||||
|
||||
module.exports = (options, ctx) => {
|
||||
const { themeAPI: { layoutComponentMap }} = ctx
|
||||
const {
|
||||
pageEnhancers = [],
|
||||
postsDir = '_posts',
|
||||
categoryIndexPageUrl = '/category/',
|
||||
tagIndexPageUrl = '/tag/',
|
||||
permalink = '/:year/:month/:day/:slug'
|
||||
} = options
|
||||
|
||||
const isLayoutExists = name => layoutComponentMap[name] !== undefined
|
||||
const getLayout = (name, fallback) => isLayoutExists(name) ? name : fallback
|
||||
const isDirectChild = regularPath => path.parse(regularPath).dir === '/'
|
||||
|
||||
const enhancers = [
|
||||
{
|
||||
when: ({ regularPath }) => regularPath === categoryIndexPageUrl,
|
||||
frontmatter: { layout: getLayout('Categories', 'Page') }
|
||||
},
|
||||
{
|
||||
when: ({ regularPath }) => regularPath.startsWith(categoryIndexPageUrl),
|
||||
frontmatter: { layout: getLayout('Category', 'Page') }
|
||||
},
|
||||
{
|
||||
when: ({ regularPath }) => regularPath === tagIndexPageUrl,
|
||||
frontmatter: { layout: getLayout('Tags', 'Page') }
|
||||
},
|
||||
{
|
||||
when: ({ regularPath }) => regularPath.startsWith(tagIndexPageUrl),
|
||||
frontmatter: { layout: getLayout('Tag', 'Page') }
|
||||
},
|
||||
{
|
||||
when: ({ regularPath }) => regularPath === '/',
|
||||
frontmatter: { layout: getLayout('Layout') }
|
||||
},
|
||||
{
|
||||
when: ({ regularPath }) => regularPath.startsWith(`/${postsDir}/`),
|
||||
frontmatter: {
|
||||
layout: getLayout('Post', 'Page'),
|
||||
permalink: permalink
|
||||
},
|
||||
data: { type: 'post' }
|
||||
},
|
||||
...pageEnhancers,
|
||||
{
|
||||
when: ({ regularPath }) => isDirectChild(regularPath),
|
||||
frontmatter: { layout: getLayout('Page', 'Layout') },
|
||||
data: { type: 'page' }
|
||||
}
|
||||
]
|
||||
|
||||
return {
|
||||
/**
|
||||
* Modify page's metadata according to the habits of blog users.
|
||||
*/
|
||||
extendPageData (pageCtx) {
|
||||
const { frontmatter: rawFrontmatter } = pageCtx
|
||||
|
||||
enhancers.forEach(({
|
||||
when,
|
||||
data = {},
|
||||
frontmatter = {}
|
||||
}) => {
|
||||
if (when(pageCtx)) {
|
||||
Object.keys(frontmatter).forEach(key => {
|
||||
if (!rawFrontmatter[key]) {
|
||||
rawFrontmatter[key] = frontmatter[key]
|
||||
}
|
||||
})
|
||||
Object.assign(pageCtx, data)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* Create tag page and category page.
|
||||
*/
|
||||
async ready () {
|
||||
const { pages } = ctx
|
||||
const tagMap = {}
|
||||
const categoryMap = {}
|
||||
|
||||
const curryHandler = (scope, map) => (key, pageKey) => {
|
||||
if (key) {
|
||||
if (!map[key]) {
|
||||
map[key] = {}
|
||||
map[key].path = `${scope}${key}.html`
|
||||
map[key].pageKeys = []
|
||||
}
|
||||
map[key].pageKeys.push(pageKey)
|
||||
}
|
||||
}
|
||||
const handleTag = curryHandler(tagIndexPageUrl, tagMap)
|
||||
const handleCategory = curryHandler(categoryIndexPageUrl, categoryMap)
|
||||
|
||||
pages.forEach(({
|
||||
key,
|
||||
frontmatter: {
|
||||
tag,
|
||||
tags,
|
||||
category,
|
||||
categories
|
||||
}
|
||||
}) => {
|
||||
if (isString(tag)) {
|
||||
handleTag(tag, key)
|
||||
}
|
||||
if (Array.isArray(tags)) {
|
||||
tags.forEach(tag => handleTag(tag, key))
|
||||
}
|
||||
if (isString(category)) {
|
||||
handleCategory(category, key)
|
||||
}
|
||||
if (Array.isArray(categories)) {
|
||||
categories.forEach(category => handleCategory(category, key))
|
||||
}
|
||||
})
|
||||
|
||||
ctx.tagMap = tagMap
|
||||
ctx.categoryMap = categoryMap
|
||||
|
||||
const extraPages = [
|
||||
{
|
||||
permalink: tagIndexPageUrl,
|
||||
frontmatter: { title: `Tags` }
|
||||
},
|
||||
{
|
||||
permalink: categoryIndexPageUrl,
|
||||
frontmatter: { title: `Categories` }
|
||||
},
|
||||
...Object.keys(tagMap).map(tagName => ({
|
||||
permalink: tagMap[tagName].path,
|
||||
meta: { tagName },
|
||||
frontmatter: { title: `${tagName} | Tag` }
|
||||
})),
|
||||
...Object.keys(categoryMap).map(categoryName => ({
|
||||
permalink: categoryMap[categoryName].path,
|
||||
meta: { categoryName },
|
||||
frontmatter: { title: `${categoryName} | Category` }
|
||||
}))
|
||||
]
|
||||
await Promise.all(extraPages.map(page => ctx.addPage(page)))
|
||||
},
|
||||
|
||||
/**
|
||||
* Generate tag and category metadata.
|
||||
*/
|
||||
async clientDynamicModules () {
|
||||
return [
|
||||
{
|
||||
name: 'tag.js',
|
||||
content: `export default ${JSON.stringify(ctx.tagMap, null, 2)}`
|
||||
},
|
||||
{
|
||||
name: 'category.js',
|
||||
content: `export default ${JSON.stringify(ctx.categoryMap, null, 2)}`
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
enhanceAppFiles: path.resolve(__dirname, 'enhanceAppFile.js')
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
{
|
||||
"name": "@vuepress/plugin-blog",
|
||||
"version": "1.0.0-alpha.49",
|
||||
"description": "blog plugin for vuepress",
|
||||
"main": "index.js",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/vuejs/vuepress.git",
|
||||
"directory": "packages/@vuepress/plugin-blog"
|
||||
},
|
||||
"keywords": [
|
||||
"documentation",
|
||||
"vue",
|
||||
"vuepress",
|
||||
"generator"
|
||||
],
|
||||
"author": "ULIVZ <chl814@foxmail.com>",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/vuejs/vuepress/issues"
|
||||
},
|
||||
"homepage": "https://github.com/vuejs/vuepress/packages/@vuepress/plugin-blog#readme"
|
||||
}
|
||||
Reference in New Issue
Block a user