UNPKG

@hewes/storybook-addon-docs-graymatter

Version:
31 lines (30 loc) 1.45 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const loader_utils_1 = require("loader-utils"); const gray_matter_1 = __importDefault(require("gray-matter")); const path_1 = __importDefault(require("path")); async function webpackLoader(content) { var _a; this.cacheable && this.cacheable(); const callback = this.async(); const options = Object.assign({}, loader_utils_1.getOptions(this), { filepath: this.resourcePath, }); const relPath = path_1.default.relative(this.context, this.resourcePath); const matter = gray_matter_1.default(content); // this.getLogger("@hewes/storybook-addons-docs-graymatter").log("matter", matter); // @ts-ignore if (matter.isEmpty || !matter.data.title) { if (!options.fileNameFallback) { return callback(null, matter.content); } matter.data.id = relPath; matter.data.title = relPath; } const mdxStoryContent = `<Meta title="${options.prefix ? `${options.prefix}/` : ""}${matter.data.title || matter.data.id}" id="${matter.data.id || matter.data.title}" />\n\n# ${(_a = matter.data.title) === null || _a === void 0 ? void 0 : _a.replace(/.*\//, "")}\n${matter.content}`; return callback(null, mdxStoryContent); } exports.default = webpackLoader;