Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit ab57080

Browse files
committed
feat: some enhancements (debug / api name)
1 parent f0d818f commit ab57080

File tree

7 files changed

+66
-15
lines changed

7 files changed

+66
-15
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## [0.0.2](https://github.com/ulivz/vuepress-plugin-blog/compare/v0.0.1...v0.0.2) (2019-06-03)
2+
3+
4+

src/Config.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export enum DefaultLayoutEnum {
2-
FrontmatterClassifier = 'FrontmatterClassifier',
2+
FrontmatterPagination = 'FrontmatterPagination',
3+
DirectoryPagination = 'DirectoryPagination',
34
}

src/client/classification.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Classifiable {
66
this._metaMap = Object.assign({}, metaMap)
77
Object.keys(this._metaMap).forEach(name => {
88
const { pageKeys } = this._metaMap[name]
9-
this._metaMap[name].posts = pageKeys.map(key => findPageByKey(pages, key))
9+
this._metaMap[name].pages = pageKeys.map(key => findPageByKey(pages, key))
1010
})
1111
}
1212

@@ -18,15 +18,19 @@ class Classifiable {
1818
return this._metaMap
1919
}
2020

21+
get pages() {
22+
return this.list
23+
}
24+
2125
get list() {
2226
return this.toArray()
2327
}
2428

2529
toArray() {
2630
const tags = []
2731
Object.keys(this._metaMap).forEach(name => {
28-
const { posts, path } = this._metaMap[name]
29-
tags.push({ name, posts, path })
32+
const { pages, path } = this._metaMap[name]
33+
tags.push({ name, pages, path })
3034
})
3135
return tags
3236
}
@@ -48,7 +52,7 @@ export default ({ Vue }) => {
4852
return classified
4953
},
5054
[`$current${classifiedType.charAt(0).toUpperCase() +
51-
classifiedType.slice(1)}`]() {
55+
classifiedType.slice(1)}`]() {
5256
const tagName = this.$route.meta.pid
5357
return this[helperName].getItemByName(tagName)
5458
},

src/handleOptions.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ export function handleOptions(options: BlogPluginOptions, ctx: AppContext) {
4444
id,
4545
dirname,
4646
path: indexPath,
47-
layout: indexLayout,
47+
layout: indexLayout = 'IndexPost',
4848
frontmatter,
49-
itemLayout,
50-
itemPermalink,
49+
itemLayout = 'Post',
50+
itemPermalink = '/:year/:month/:day/:slug',
5151
pagination = {
5252
perPagePosts: 10,
5353
},
@@ -107,7 +107,7 @@ export function handleOptions(options: BlogPluginOptions, ctx: AppContext) {
107107
},
108108
options: {
109109
...pagination,
110-
layout: DefaultLayoutEnum.FrontmatterClassifier,
110+
layout: DefaultLayoutEnum.DirectoryPagination,
111111
},
112112
getUrl(index) {
113113
if (index === 0) {

src/index.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { registerPagination } from './pagination'
44
import { BlogPluginOptions } from './interface/Options'
55
import { AppContext, Page } from './interface/VuePress'
66
import { DefaultLayoutEnum } from './Config'
7+
import { logPages } from './util'
78

89
module.exports = (options: BlogPluginOptions, ctx: AppContext) => {
910
const {
@@ -92,7 +93,7 @@ module.exports = (options: BlogPluginOptions, ctx: AppContext) => {
9293
},
9394
options: {
9495
...pagination,
95-
layout: DefaultLayoutEnum.FrontmatterClassifier,
96+
layout: DefaultLayoutEnum.FrontmatterPagination,
9697
serverPageFilter(page) {
9798
return clientFrontmatterClassifierPageFilter(
9899
page,
@@ -122,16 +123,19 @@ module.exports = (options: BlogPluginOptions, ctx: AppContext) => {
122123
pid: scope,
123124
id: key,
124125
frontmatter: {
125-
layout: DefaultLayoutEnum.FrontmatterClassifier,
126+
layout: DefaultLayoutEnum.FrontmatterPagination,
126127
title: `${key} | ${scope}`,
127128
},
128129
}
129130
})
130131
})
131132
.reduce((arr, next) => arr.concat(next), []),
132133
]
133-
console.log('====== allExtraPages')
134-
console.log(allExtraPages)
134+
135+
logPages(
136+
`Automatically Added Index Pages`,
137+
allExtraPages
138+
)
135139

136140
await Promise.all(allExtraPages.map(async page => ctx.addPage(page)))
137141
await registerPagination(paginations, ctx)

src/pagination.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { AppContext } from './interface/VuePress'
22
import { InternalPagination } from './interface/Pagination'
3+
import { logPages } from './util'
34

45
export async function registerPagination(paginations: InternalPagination[], ctx: AppContext) {
56
ctx.paginations = []
@@ -71,8 +72,10 @@ export async function registerPagination(paginations: InternalPagination[], ctx:
7172
recordPageFilters(pid, clientPageFilter)
7273
recordPageSorters(pid, clientPageSorter)
7374

74-
console.log('==== pagination.paginationPages')
75-
console.log(pagination.paginationPages)
75+
logPages(
76+
`Automatically Added Pagination Pages`,
77+
pagination.paginationPages.slice(1)
78+
)
7679

7780
await Promise.all(
7881
pagination.paginationPages.map(async ({ path }, index) => {

src/util.ts

+35
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { env } from '@vuepress/shared-utils'
2+
13
export type FrontmatterHandler = (key: string, pageKey: string) => void
24
export interface FrontmatterTempMap {
35
scope: string;
@@ -22,3 +24,36 @@ export function curryFrontmatterHandler(scope, map) {
2224
}
2325
}
2426
}
27+
28+
export function logPages(title, pages) {
29+
if (env.isDebug) {
30+
const table = require('text-table')
31+
const chalk = require('chalk')
32+
console.log()
33+
console.log(chalk.cyan(`[@vuepress/plugin-blog] ====== ${title} ======`))
34+
const data: any[] = [
35+
['permalink', 'meta', 'pid', 'id', 'frontmatter'],
36+
]
37+
data.push(
38+
...pages.map(({
39+
// @ts-ignore
40+
path,
41+
permalink,
42+
meta,
43+
// @ts-ignore
44+
pid,
45+
// @ts-ignore
46+
id,
47+
frontmatter,
48+
}) => [
49+
permalink || path || '',
50+
JSON.stringify(meta) || '',
51+
pid || '',
52+
id || '',
53+
JSON.stringify(frontmatter) || '',
54+
]),
55+
)
56+
console.log(table(data))
57+
console.log()
58+
}
59+
}

0 commit comments

Comments
 (0)