Skip to content

Commit

Permalink
Use parseMarkdownFile instead of parseMarkdownString (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
andremartinssw authored Jan 8, 2024
1 parent 1f4e8ac commit 9693fb3
Show file tree
Hide file tree
Showing 2 changed files with 531 additions and 380 deletions.
22 changes: 14 additions & 8 deletions packages/docusaurus-plugin-openapi/src/docs/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import type { LoadContext } from "@docusaurus/types";
import {
aliasedSitePath,
normalizeUrl,
parseMarkdownString,
parseMarkdownFile,
DEFAULT_PARSE_FRONT_MATTER,
} from "@docusaurus/utils";

import { validateDocFrontMatter } from "./frontMatter";
Expand Down Expand Up @@ -78,11 +79,16 @@ async function doProcessDocMetadata({
const { siteDir } = context;

const {
frontMatter: unsafeFrontMatter,
contentTitle,
excerpt,
} = parseMarkdownString(content);
const frontMatter = validateDocFrontMatter(unsafeFrontMatter);
frontMatter: parsedFrontMatter,
contentTitle: parsedContentTitle,
excerpt: parsedExcerpt,
} = await parseMarkdownFile({
fileContent: content,
filePath,
parseFrontMatter: DEFAULT_PARSE_FRONT_MATTER,
});

const frontMatter = validateDocFrontMatter(parsedFrontMatter);

// E.g. api/plugins/myDoc -> myDoc; myDoc -> myDoc
const sourceFileNameWithoutExtension = path.basename(
Expand Down Expand Up @@ -129,9 +135,9 @@ async function doProcessDocMetadata({
// Note: the title is used by default for page title, sidebar label,
// pagination buttons... frontMatter.title should be used in priority over
// contentTitle (because it can contain markdown/JSX syntax)
const title: string = frontMatter.title ?? contentTitle ?? baseID;
const title: string = frontMatter.title ?? parsedContentTitle ?? baseID;

const description: string = frontMatter.description ?? excerpt ?? "";
const description: string = frontMatter.description ?? parsedExcerpt ?? "";

const permalink = normalizeUrl([
context.baseUrl,
Expand Down
Loading

0 comments on commit 9693fb3

Please sign in to comment.