markdown-story-loader.js (1340B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 /* eslint-env node */ 5 6 /** 7 * This file contains a Webpack loader that takes markdown as its source and 8 * outputs a docs only MDX Storybook story. This enables us to write docs only 9 * pages in plain markdown by specifying a `.stories.md` extension. 10 * 11 * For more context on docs only stories, see: 12 * https://storybook.js.org/docs/web-components/writing-docs/mdx#documentation-only-mdx 13 * 14 * The MDX generated by the loader will then get run through the same loaders 15 * Storybook usually uses to transform MDX files. 16 */ 17 18 const { getStoryTitle, getMDXSource } = require("./markdown-story-utils.js"); 19 20 /** 21 * The WebpackLoader export. Takes markdown as its source and returns a docs 22 * only MDX story. Falls back to filing stories under "Docs" for everything 23 * outside of `toolkit/content/widgets`. 24 * 25 * @param {string} source - The markdown source to rewrite to MDX. 26 */ 27 module.exports = function markdownStoryLoader(source) { 28 // `this.resourcePath` is the path of the file being processed. 29 let title = getStoryTitle(this.resourcePath); 30 let mdxSource = getMDXSource(source, title, this.resourcePath); 31 return mdxSource; 32 };