@docusaurus/plugin-content-blog 3.7.0-canary-6292 → 3.7.0-canary-6296
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/blogUtils.js +2 -2
- package/lib/readingTime.d.ts +16 -0
- package/lib/readingTime.js +22 -0
- package/package.json +10 -10
- package/src/blogUtils.ts +2 -2
- package/src/readingTime.ts +29 -0
package/lib/blogUtils.js
CHANGED
|
@@ -19,12 +19,12 @@ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
|
19
19
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
20
20
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
21
21
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
22
|
-
const reading_time_1 = tslib_1.__importDefault(require("reading-time"));
|
|
23
22
|
const utils_1 = require("@docusaurus/utils");
|
|
24
23
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
25
24
|
const frontMatter_1 = require("./frontMatter");
|
|
26
25
|
const authors_1 = require("./authors");
|
|
27
26
|
const authorsProblems_1 = require("./authorsProblems");
|
|
27
|
+
const readingTime_1 = require("./readingTime");
|
|
28
28
|
function truncate(fileString, truncateMarker) {
|
|
29
29
|
return fileString.split(truncateMarker, 1).shift();
|
|
30
30
|
}
|
|
@@ -130,7 +130,7 @@ async function parseBlogPostMarkdownFile({ filePath, parseFrontMatter, }) {
|
|
|
130
130
|
throw err;
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
|
-
const defaultReadingTime = ({ content, options }) => (0,
|
|
133
|
+
const defaultReadingTime = ({ content, options }) => (0, readingTime_1.calculateReadingTime)(content, options);
|
|
134
134
|
async function processBlogSourceFile(blogSourceRelative, contentPaths, context, options, tagsFile, authorsMap) {
|
|
135
135
|
const { siteConfig: { baseUrl, markdown: { parseFrontMatter }, }, siteDir, i18n, } = context;
|
|
136
136
|
const { routeBasePath, tagsBasePath: tagsRouteBasePath, truncateMarker, showReadingTime, editUrl, } = options;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
interface ReadingTimeOptions {
|
|
8
|
+
wordsPerMinute?: number;
|
|
9
|
+
wordBound?: (char: string) => boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Calculates the reading time for a given content string.
|
|
13
|
+
* Uses the reading-time package under the hood.
|
|
14
|
+
*/
|
|
15
|
+
export declare function calculateReadingTime(content: string, options?: ReadingTimeOptions): number;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.calculateReadingTime = calculateReadingTime;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const reading_time_1 = tslib_1.__importDefault(require("reading-time"));
|
|
12
|
+
const DEFAULT_WORDS_PER_MINUTE = 200;
|
|
13
|
+
/**
|
|
14
|
+
* Calculates the reading time for a given content string.
|
|
15
|
+
* Uses the reading-time package under the hood.
|
|
16
|
+
*/
|
|
17
|
+
function calculateReadingTime(content, options = {}) {
|
|
18
|
+
const wordsPerMinute = options.wordsPerMinute ?? DEFAULT_WORDS_PER_MINUTE;
|
|
19
|
+
const { wordBound } = options;
|
|
20
|
+
return (0, reading_time_1.default)(content, { wordsPerMinute, ...(wordBound && { wordBound }) })
|
|
21
|
+
.minutes;
|
|
22
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-content-blog",
|
|
3
|
-
"version": "3.7.0-canary-
|
|
3
|
+
"version": "3.7.0-canary-6296",
|
|
4
4
|
"description": "Blog plugin for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/plugin-content-blog.d.ts",
|
|
@@ -31,14 +31,14 @@
|
|
|
31
31
|
},
|
|
32
32
|
"license": "MIT",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@docusaurus/core": "3.7.0-canary-
|
|
35
|
-
"@docusaurus/logger": "3.7.0-canary-
|
|
36
|
-
"@docusaurus/mdx-loader": "3.7.0-canary-
|
|
37
|
-
"@docusaurus/theme-common": "3.7.0-canary-
|
|
38
|
-
"@docusaurus/types": "3.7.0-canary-
|
|
39
|
-
"@docusaurus/utils": "3.7.0-canary-
|
|
40
|
-
"@docusaurus/utils-common": "3.7.0-canary-
|
|
41
|
-
"@docusaurus/utils-validation": "3.7.0-canary-
|
|
34
|
+
"@docusaurus/core": "3.7.0-canary-6296",
|
|
35
|
+
"@docusaurus/logger": "3.7.0-canary-6296",
|
|
36
|
+
"@docusaurus/mdx-loader": "3.7.0-canary-6296",
|
|
37
|
+
"@docusaurus/theme-common": "3.7.0-canary-6296",
|
|
38
|
+
"@docusaurus/types": "3.7.0-canary-6296",
|
|
39
|
+
"@docusaurus/utils": "3.7.0-canary-6296",
|
|
40
|
+
"@docusaurus/utils-common": "3.7.0-canary-6296",
|
|
41
|
+
"@docusaurus/utils-validation": "3.7.0-canary-6296",
|
|
42
42
|
"cheerio": "1.0.0-rc.12",
|
|
43
43
|
"feed": "^4.2.2",
|
|
44
44
|
"fs-extra": "^11.1.1",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"@total-typescript/shoehorn": "^0.1.2",
|
|
64
64
|
"tree-node-cli": "^1.6.0"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "f7529479014cdcbe2569fa315724be244d554531"
|
|
67
67
|
}
|
package/src/blogUtils.ts
CHANGED
|
@@ -9,7 +9,6 @@ import fs from 'fs-extra';
|
|
|
9
9
|
import path from 'path';
|
|
10
10
|
import _ from 'lodash';
|
|
11
11
|
import logger from '@docusaurus/logger';
|
|
12
|
-
import readingTime from 'reading-time';
|
|
13
12
|
import {
|
|
14
13
|
parseMarkdownFile,
|
|
15
14
|
normalizeUrl,
|
|
@@ -32,6 +31,7 @@ import {getTagsFile} from '@docusaurus/utils-validation';
|
|
|
32
31
|
import {validateBlogPostFrontMatter} from './frontMatter';
|
|
33
32
|
import {getBlogPostAuthors} from './authors';
|
|
34
33
|
import {reportAuthorsProblems} from './authorsProblems';
|
|
34
|
+
import {calculateReadingTime} from './readingTime';
|
|
35
35
|
import type {TagsFile} from '@docusaurus/utils';
|
|
36
36
|
import type {LoadContext, ParseFrontMatter} from '@docusaurus/types';
|
|
37
37
|
import type {
|
|
@@ -211,7 +211,7 @@ async function parseBlogPostMarkdownFile({
|
|
|
211
211
|
}
|
|
212
212
|
|
|
213
213
|
const defaultReadingTime: ReadingTimeFunction = ({content, options}) =>
|
|
214
|
-
|
|
214
|
+
calculateReadingTime(content, options);
|
|
215
215
|
|
|
216
216
|
async function processBlogSourceFile(
|
|
217
217
|
blogSourceRelative: string,
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import readingTime from 'reading-time';
|
|
9
|
+
|
|
10
|
+
const DEFAULT_WORDS_PER_MINUTE = 200;
|
|
11
|
+
|
|
12
|
+
interface ReadingTimeOptions {
|
|
13
|
+
wordsPerMinute?: number;
|
|
14
|
+
wordBound?: (char: string) => boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Calculates the reading time for a given content string.
|
|
19
|
+
* Uses the reading-time package under the hood.
|
|
20
|
+
*/
|
|
21
|
+
export function calculateReadingTime(
|
|
22
|
+
content: string,
|
|
23
|
+
options: ReadingTimeOptions = {},
|
|
24
|
+
): number {
|
|
25
|
+
const wordsPerMinute = options.wordsPerMinute ?? DEFAULT_WORDS_PER_MINUTE;
|
|
26
|
+
const {wordBound} = options;
|
|
27
|
+
return readingTime(content, {wordsPerMinute, ...(wordBound && {wordBound})})
|
|
28
|
+
.minutes;
|
|
29
|
+
}
|