mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-18 19:46:57 +02:00
feat(v2): add blog post estimated reading time (#2531)
* feat: add estimated reading time to blog posts * docs: add showReadingTime on plugin docs * test: update plugin-content-blog tests to cover readingTime * Update index.js * Update using-plugins.md * Update index.js Co-authored-by: Yangshun Tay <tay.yang.shun@gmail.com>
This commit is contained in:
parent
c576faac73
commit
95fdfe7e15
8 changed files with 25 additions and 4 deletions
|
@ -8,6 +8,7 @@
|
|||
import fs from 'fs-extra';
|
||||
import globby from 'globby';
|
||||
import path from 'path';
|
||||
import readingTime from 'reading-time';
|
||||
import {Feed} from 'feed';
|
||||
import {PluginOptions, BlogPost, DateLink} from './types';
|
||||
import {parse, normalizeUrl, aliasedSitePath} from '@docusaurus/utils';
|
||||
|
@ -85,7 +86,7 @@ export async function generateBlogPosts(
|
|||
{siteConfig, siteDir}: LoadContext,
|
||||
options: PluginOptions,
|
||||
) {
|
||||
const {include, routeBasePath, truncateMarker} = options;
|
||||
const {include, routeBasePath, truncateMarker, showReadingTime} = options;
|
||||
|
||||
if (!fs.existsSync(blogDir)) {
|
||||
return [];
|
||||
|
@ -144,6 +145,9 @@ export async function generateBlogPosts(
|
|||
date,
|
||||
tags: frontMatter.tags,
|
||||
title: frontMatter.title,
|
||||
readingTime: showReadingTime
|
||||
? readingTime(content).minutes
|
||||
: undefined,
|
||||
truncated: truncateMarker?.test(content) || false,
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue