From 10dfb6695dec7d9bbd2265f63ad50e008663b82c Mon Sep 17 00:00:00 2001 From: ULIVZ <472590061@qq.com> Date: Tue, 4 Jun 2019 03:35:37 +0800 Subject: [PATCH] chore: remove plugin-blog --- packages/@vuepress/plugin-blog/.npmignore | 3 - packages/@vuepress/plugin-blog/README.md | 9 - .../@vuepress/plugin-blog/enhanceAppFile.js | 63 ------- packages/@vuepress/plugin-blog/index.js | 165 ------------------ packages/@vuepress/plugin-blog/package.json | 26 --- 5 files changed, 266 deletions(-) delete mode 100644 packages/@vuepress/plugin-blog/.npmignore delete mode 100644 packages/@vuepress/plugin-blog/README.md delete mode 100644 packages/@vuepress/plugin-blog/enhanceAppFile.js delete mode 100644 packages/@vuepress/plugin-blog/index.js delete mode 100644 packages/@vuepress/plugin-blog/package.json diff --git a/packages/@vuepress/plugin-blog/.npmignore b/packages/@vuepress/plugin-blog/.npmignore deleted file mode 100644 index 13c38ea313..0000000000 --- a/packages/@vuepress/plugin-blog/.npmignore +++ /dev/null @@ -1,3 +0,0 @@ -__tests__ -__mocks__ -.temp diff --git a/packages/@vuepress/plugin-blog/README.md b/packages/@vuepress/plugin-blog/README.md deleted file mode 100644 index 1864f5b47d..0000000000 --- a/packages/@vuepress/plugin-blog/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# @vuepress/plugin-blog - -> blog plugin for vuepress - -See [documentation](https://v1.vuepress.vuejs.org/plugin/official/plugin-blog.html). - - - - diff --git a/packages/@vuepress/plugin-blog/enhanceAppFile.js b/packages/@vuepress/plugin-blog/enhanceAppFile.js deleted file mode 100644 index 98b88de794..0000000000 --- a/packages/@vuepress/plugin-blog/enhanceAppFile.js +++ /dev/null @@ -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) - } - } - }) -} diff --git a/packages/@vuepress/plugin-blog/index.js b/packages/@vuepress/plugin-blog/index.js deleted file mode 100644 index c2c8b453fd..0000000000 --- a/packages/@vuepress/plugin-blog/index.js +++ /dev/null @@ -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') - } -} diff --git a/packages/@vuepress/plugin-blog/package.json b/packages/@vuepress/plugin-blog/package.json deleted file mode 100644 index dcc85a751e..0000000000 --- a/packages/@vuepress/plugin-blog/package.json +++ /dev/null @@ -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 ", - "license": "MIT", - "bugs": { - "url": "https://github.com/vuejs/vuepress/issues" - }, - "homepage": "https://github.com/vuejs/vuepress/packages/@vuepress/plugin-blog#readme" -}