feat(v2): various markdown string parsing improvements/fixes (#4590)

* extract createExcerpt code in separate file + add bad test

* almost working markdown parsing refactor

* complete parseMarkdownString refactor

* fix tests

* fix blog test issue

* fix docusaurus utils imports
This commit is contained in:
Sébastien Lorber 2021-04-09 17:09:33 +02:00 committed by GitHub
parent b743edf5fb
commit 4efe6824b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 895 additions and 563 deletions

View file

@ -30,6 +30,7 @@ import getSlug from './slug';
import {CURRENT_VERSION_NAME} from './constants';
import globby from 'globby';
import {getDocsDirPaths} from './versions';
import {assertDocFrontMatter} from './docFrontMatter';
type LastUpdateOptions = Pick<
PluginOptions,
@ -115,11 +116,15 @@ export function processDocMetadata({
const {homePageId} = options;
const {siteDir, i18n} = context;
const {frontMatter, contentTitle, excerpt} = parseMarkdownString(content, {
source,
});
assertDocFrontMatter(frontMatter);
// ex: api/myDoc -> api
// ex: myDoc -> .
const docsFileDirName = path.dirname(source);
const {frontMatter = {}, excerpt} = parseMarkdownString(content, source);
const {
sidebar_label: sidebarLabel,
custom_edit_url: customEditURL,
@ -165,9 +170,9 @@ export function processDocMetadata({
});
// Default title is the id.
const title: string = frontMatter.title || baseID;
const title: string = frontMatter.title ?? contentTitle ?? baseID;
const description: string = frontMatter.description || excerpt;
const description: string = frontMatter.description ?? excerpt ?? '';
const permalink = normalizeUrl([versionMetadata.versionPath, docSlug]);