mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 15:47:23 +02:00
refactor(v2): legacy export = syntax (#2948)
This commit is contained in:
parent
955e656496
commit
025ac4e28c
2 changed files with 23 additions and 7 deletions
|
@ -7,19 +7,31 @@
|
||||||
|
|
||||||
import {loader} from 'webpack';
|
import {loader} from 'webpack';
|
||||||
import {truncate, linkify} from './blogUtils';
|
import {truncate, linkify} from './blogUtils';
|
||||||
const {parseQuery, getOptions} = require('loader-utils');
|
import {parseQuery, getOptions} from 'loader-utils';
|
||||||
|
|
||||||
export = function (fileString: string) {
|
const markdownLoader: loader.Loader = function (source) {
|
||||||
|
const fileString = source as string;
|
||||||
const callback = this.async();
|
const callback = this.async();
|
||||||
const {truncateMarker, siteDir, contentPath, blogPosts} = getOptions(this);
|
const {truncateMarker, siteDir, contentPath, blogPosts} = getOptions(this);
|
||||||
|
|
||||||
// Linkify posts
|
// Linkify posts
|
||||||
let finalContent = linkify(fileString, siteDir, contentPath, blogPosts);
|
let finalContent = linkify(
|
||||||
|
fileString as string,
|
||||||
|
siteDir,
|
||||||
|
contentPath,
|
||||||
|
blogPosts,
|
||||||
|
);
|
||||||
|
|
||||||
// Truncate content if requested (e.g: file.md?truncated=true).
|
// Truncate content if requested (e.g: file.md?truncated=true).
|
||||||
const {truncated} = this.resourceQuery && parseQuery(this.resourceQuery);
|
const truncated: string | undefined = this.resourceQuery
|
||||||
|
? parseQuery(this.resourceQuery).truncated
|
||||||
|
: undefined;
|
||||||
|
|
||||||
if (truncated) {
|
if (truncated) {
|
||||||
finalContent = truncate(finalContent, truncateMarker);
|
finalContent = truncate(finalContent, truncateMarker);
|
||||||
}
|
}
|
||||||
|
|
||||||
return callback && callback(null, finalContent);
|
return callback && callback(null, finalContent);
|
||||||
} as loader.Loader;
|
};
|
||||||
|
|
||||||
|
export default markdownLoader;
|
||||||
|
|
|
@ -9,9 +9,11 @@ import {getOptions} from 'loader-utils';
|
||||||
import {loader} from 'webpack';
|
import {loader} from 'webpack';
|
||||||
import linkify from './linkify';
|
import linkify from './linkify';
|
||||||
|
|
||||||
export = function (fileString: string) {
|
const markdownLoader: loader.Loader = function (source) {
|
||||||
|
const fileString = source as string;
|
||||||
const callback = this.async();
|
const callback = this.async();
|
||||||
const {docsDir, siteDir, versionedDir, sourceToPermalink} = getOptions(this);
|
const {docsDir, siteDir, versionedDir, sourceToPermalink} = getOptions(this);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
callback &&
|
callback &&
|
||||||
callback(
|
callback(
|
||||||
|
@ -26,4 +28,6 @@ export = function (fileString: string) {
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
} as loader.Loader;
|
};
|
||||||
|
|
||||||
|
export default markdownLoader;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue