Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(v2): legacy export = syntax #2948

Merged
merged 1 commit into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions packages/docusaurus-plugin-content-blog/src/markdownLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,31 @@

import {loader} from 'webpack';
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 {truncateMarker, siteDir, contentPath, blogPosts} = getOptions(this);

// 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).
const {truncated} = this.resourceQuery && parseQuery(this.resourceQuery);
const truncated: string | undefined = this.resourceQuery
? parseQuery(this.resourceQuery).truncated
: undefined;

if (truncated) {
finalContent = truncate(finalContent, truncateMarker);
}

return callback && callback(null, finalContent);
} as loader.Loader;
};

export default markdownLoader;
8 changes: 6 additions & 2 deletions packages/docusaurus-plugin-content-docs/src/markdown/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import {getOptions} from 'loader-utils';
import {loader} from 'webpack';
import linkify from './linkify';

export = function (fileString: string) {
const markdownLoader: loader.Loader = function (source) {
const fileString = source as string;
const callback = this.async();
const {docsDir, siteDir, versionedDir, sourceToPermalink} = getOptions(this);

return (
callback &&
callback(
Expand All @@ -26,4 +28,6 @@ export = function (fileString: string) {
),
)
);
} as loader.Loader;
};

export default markdownLoader;