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:
Alexey Pyltsyn 2020-04-24 07:18:54 +03:00 committed by GitHub
parent 3c27e23f38
commit 9e1f816fcd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 75 additions and 37 deletions

View file

@ -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;