fix(v2): linkify blog posts (#2326)

* fix(v2): linkify blog posts

* Fix tests
This commit is contained in:
Alexey Pyltsyn 2020-02-29 09:49:00 +03:00 committed by GitHub
parent 84eeb5120c
commit 36163773ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 161 additions and 12 deletions

View file

@ -5,21 +5,20 @@
* LICENSE file in the root directory of this source tree.
*/
const {parseQuery, getOptions} = require('loader-utils');
import {loader} from 'webpack';
import {truncate} from './blogUtils';
import {truncate, linkify} from './blogUtils';
const {parseQuery, getOptions} = require('loader-utils');
export = function(fileString: string) {
const callback = this.async();
const {truncateMarker}: {truncateMarker: RegExp} = getOptions(this);
let finalContent = fileString;
const {truncateMarker, siteDir, contentPath, blogPosts} = getOptions(this);
// Linkify posts
let finalContent = linkify(fileString, siteDir, contentPath, blogPosts);
// Truncate content if requested (e.g: file.md?truncated=true).
const {truncated} = this.resourceQuery && parseQuery(this.resourceQuery);
if (truncated) {
finalContent = truncate(fileString, truncateMarker);
finalContent = truncate(finalContent, truncateMarker);
}
return callback && callback(null, finalContent);