mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-20 12:37:01 +02:00
fix(v2): use remark-admonitions separately in each plugin instead of in preset only (#2642)
* fix(v2): use remark-admonitions separately in each plugin instead of in preset only * Update types.d.ts * Update types.d.ts * Address fixes from review Co-authored-by: Yangshun Tay <tay.yang.shun@gmail.com>
This commit is contained in:
parent
3c27e23f38
commit
9e1f816fcd
11 changed files with 75 additions and 37 deletions
|
@ -8,6 +8,7 @@
|
|||
import fs from 'fs-extra';
|
||||
import kebabCase from 'lodash.kebabcase';
|
||||
import path from 'path';
|
||||
import admonitions from 'remark-admonitions';
|
||||
import {normalizeUrl, docuHash, aliasedSitePath} from '@docusaurus/utils';
|
||||
|
||||
import {
|
||||
|
@ -45,6 +46,7 @@ const DEFAULT_OPTIONS: PluginOptions = {
|
|||
rehypePlugins: [],
|
||||
editUrl: undefined,
|
||||
truncateMarker: /<!--\s*(truncate)\s*-->/, // Regex.
|
||||
admonitions: {},
|
||||
};
|
||||
|
||||
function assertFeedTypes(val: any): asserts val is FeedType {
|
||||
|
@ -72,6 +74,13 @@ export default function pluginContentBlog(
|
|||
opts: Partial<PluginOptions>,
|
||||
): Plugin<BlogContent | null> {
|
||||
const options: PluginOptions = {...DEFAULT_OPTIONS, ...opts};
|
||||
|
||||
if (options.admonitions) {
|
||||
options.remarkPlugins = options.remarkPlugins.concat([
|
||||
[admonitions, opts.admonitions || {}],
|
||||
]);
|
||||
}
|
||||
|
||||
const {siteDir, generatedFilesDir} = context;
|
||||
const contentPath = path.resolve(siteDir, options.path);
|
||||
const dataDir = path.join(
|
||||
|
@ -89,6 +98,16 @@ export default function pluginContentBlog(
|
|||
return [...globPattern];
|
||||
},
|
||||
|
||||
getClientModules() {
|
||||
const modules = [];
|
||||
|
||||
if (options.admonitions) {
|
||||
modules.push('remark-admonitions/styles/infima.css');
|
||||
}
|
||||
|
||||
return modules;
|
||||
},
|
||||
|
||||
// Fetches blog contents and returns metadata for the necessary routes.
|
||||
async loadContent() {
|
||||
const {postsPerPage, routeBasePath} = options;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue