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

Commit 828e5bf

Browse files
committed
chore: improve debug logs
1 parent 4940903 commit 828e5bf

File tree

5 files changed

+71
-28
lines changed

5 files changed

+71
-28
lines changed

src/client/pagination.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Pagination {
1717
public _indexPage: string;
1818

1919
constructor(pagination, pages, route) {
20-
debug(pagination);
20+
debug('pagination', pagination);
2121
const { pages: paginationPages } = pagination;
2222
const { path } = route;
2323

@@ -97,7 +97,7 @@ class PaginationGateway {
9797

9898
getPagination(pid, id, route) {
9999
debug('id', id);
100-
debug('this.paginations', this.paginations);
100+
debug('pid', pid);
101101
const pagnination = this.paginations.filter(
102102
p => p.id === id && p.pid === pid
103103
)[0];

src/node/handleOptions.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
FrontmatterTempMap,
1111
resolvePaginationConfig,
1212
UpperFirstChar,
13+
logObject,
1314
} from './util';
1415
import { ClassifierTypeEnum } from './interface/Classifier';
1516

@@ -173,10 +174,14 @@ export function handleOptions(
173174
});
174175
}
175176

176-
return {
177+
const processedData = {
177178
pageEnhancers,
178179
frontmatterClassificationPages,
179180
extraPages,
180181
paginations,
181182
};
183+
184+
logObject('Handle options', processedData, true);
185+
186+
return processedData;
182187
}

src/node/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { path, logger, chalk } from '@vuepress/shared-utils';
22
import { handleOptions } from './handleOptions';
33
import { registerPaginations } from './pagination';
44
import { BlogPluginOptions } from './interface/Options';
5-
import { logPages, resolvePaginationConfig } from './util';
5+
import { logPages, logTable, logObject, resolvePaginationConfig } from './util';
66
import { ClassifierTypeEnum, DefaultLayoutEnum } from './interface/Classifier';
77
import { VuePressContext, VuePressPage } from './interface/VuePress';
88

@@ -131,6 +131,10 @@ module.exports = (options: BlogPluginOptions, ctx: VuePressContext) => {
131131
}
132132
}
133133

134+
for (const { map } of frontmatterClassificationPages) {
135+
logTable('frontmatterClassificationPages.map', map);
136+
}
137+
134138
/**
135139
* 2.2 Store frontmatterClassificationPages in current context.
136140
*/
@@ -197,6 +201,7 @@ module.exports = (options: BlogPluginOptions, ctx: VuePressContext) => {
197201
];
198202

199203
logPages(`Automatically Added Index Pages`, allExtraPages);
204+
logObject(`Pagination data sources`, paginations);
200205

201206
await Promise.all(allExtraPages.map(async page => ctx.addPage(page)));
202207
await registerPaginations(paginations, ctx);

src/node/pagination.ts

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
GetPaginationPageTitle,
77
SerializedPagination,
88
} from './interface/Pagination';
9-
import { logPages } from './util';
9+
import { logPages, logObject } from './util';
1010

1111
/**
1212
* Divided an interval of several lengths into several equal-length intervals.
@@ -62,6 +62,9 @@ export async function registerPaginations(
6262
);
6363

6464
const intervallers = getIntervallers(pages.length, lengthPerPage);
65+
66+
logObject(`${id}'s page intervaller`, intervallers);
67+
6568
const pagination: SerializedPagination = {
6669
pid,
6770
id,
@@ -76,29 +79,31 @@ export async function registerPaginations(
7679
recordPageFilters(pid, filter);
7780
recordPageSorters(pid, sorter);
7881

79-
const extraPages = pagination.pages
80-
.slice(1) // The index page has been generated.
81-
.map(({ path }, index) => {
82-
return {
83-
permalink: path,
84-
frontmatter: {
85-
layout,
86-
title: (getPaginationPageTitle as GetPaginationPageTitle)(
87-
index,
82+
if (pagination.pages.length > 1) {
83+
const extraPages = pagination.pages
84+
.slice(1) // The index page has been generated.
85+
.map(({ path }, index) => {
86+
return {
87+
permalink: path,
88+
frontmatter: {
89+
layout,
90+
title: (getPaginationPageTitle as GetPaginationPageTitle)(
91+
index,
92+
id,
93+
pid
94+
),
95+
},
96+
meta: {
97+
pid,
8898
id,
89-
pid
90-
),
91-
},
92-
meta: {
93-
pid,
94-
id,
95-
},
96-
};
97-
});
99+
},
100+
};
101+
});
98102

99-
logPages(`Automatically generated pagination pages`, extraPages);
103+
logPages(`Automatically generated pagination pages`, extraPages);
100104

101-
await Promise.all(extraPages.map(page => ctx.addPage(page)));
105+
await Promise.all(extraPages.map(page => ctx.addPage(page)));
106+
}
102107

103108
ctx.serializedPaginations.push(pagination);
104109
}

src/node/util.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,40 @@ export function curryFrontmatterHandler(scope, map, path) {
3131
};
3232
}
3333

34+
function PluginBlogLog(title) {
35+
const chalk = require('chalk'); // eslint-disable-line
36+
console.log();
37+
console.log(chalk.cyan(`[@vuepress/plugin-blog] ====== ${title} ======`));
38+
}
39+
40+
export function logObject(title, o, spread = false) {
41+
if (env.isDebug) {
42+
PluginBlogLog(title);
43+
if (spread) {
44+
for (const key in o) {
45+
console.log(key, o[key]);
46+
console.log();
47+
}
48+
} else {
49+
console.log(o);
50+
console.log();
51+
}
52+
}
53+
}
54+
55+
export function logTable(title, data) {
56+
if (env.isDebug) {
57+
PluginBlogLog(title);
58+
console.table(data);
59+
console.log();
60+
}
61+
}
62+
3463
export function logPages(title, pages) {
3564
if (env.isDebug) {
3665
const table = require('text-table'); // eslint-disable-line
37-
const chalk = require('chalk'); // eslint-disable-line
38-
console.log();
39-
console.log(chalk.cyan(`[@vuepress/plugin-blog] ====== ${title} ======`));
66+
67+
PluginBlogLog(title);
4068
const data: any[] = [['permalink', 'meta', 'pid', 'id', 'frontmatter']];
4169
data.push(
4270
...pages.map(({ path, permalink, meta, pid, id, frontmatter }) => [

0 commit comments

Comments
 (0)