single-page-markdown-website
Version:
Create a nice single-page documentation website from one or more Markdown files
30 lines • 1.57 kB
JavaScript
import isUrl from 'is-url';
import { buildHtmlAsync } from './utilities/build-html-async/build-html-async.js';
import { copyImageFilesAsync } from './utilities/copy-image-files-async.js';
import { readMarkdownFilesAsync } from './utilities/read-markdown-files-async.js';
import { resolveNewImageFilePath } from './utilities/resolve-new-image-file-path.js';
export async function buildAsync(globs, options) {
const { files, images } = await readMarkdownFilesAsync(globs);
if (options.shareImage !== null && isUrl(options.shareImage) === false) {
const shareImageFilePath = resolveNewImageFilePath(options.shareImage, Object.values(images));
images[options.shareImage] = shareImageFilePath;
options.shareImage = createImageUrl(shareImageFilePath, options.baseUrl);
}
if (options.faviconImage !== null && isUrl(options.faviconImage) === false) {
const faviconImageFilePath = resolveNewImageFilePath(options.faviconImage, Object.values(images));
images[options.faviconImage] = faviconImageFilePath;
options.faviconImage = createImageUrl(faviconImageFilePath, options.baseUrl);
}
await copyImageFilesAsync(images, {
outputDirectory: options.outputDirectory
});
const htmlFilePath = await buildHtmlAsync(files.join('\n\n'), options);
return htmlFilePath;
}
function createImageUrl(imageFilePath, baseUrl) {
if (baseUrl === null) {
return imageFilePath;
}
return [baseUrl, imageFilePath].join('/').replace(/(?<!:)\/+/g, '/');
}
//# sourceMappingURL=build-async.js.map