Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Component Integration With Content
This commit ensures that Storybook, Jest and a preact project render the components/contents correctly. Previously a variety of mistakes were made that now are rectified: * Jest does not honour .babelrc, so we gave up on JSX and pragma niceties * Previous tests were not actually rendering the component from the bundle * package.json specified an incorrect bundle entry * dist/ folder was made part of version control * Hidayah implementation was leveraging react-markdown to render the contents. While this works for storybook, bundling this code implied that react-markdown tries to mutate the content that Rollup marks as immutable: rollup/rollup#1771 In addition to the above: * Abstract out the implementation of markdown_plugin so Rollup and Vite can reuse.
- Loading branch information
Khalil Johnson
committed
Jan 7, 2024
1 parent
f805144
commit f01ef6a
Showing
25 changed files
with
264 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
node_modules/ | ||
npm-debug.log | ||
storybook-static/ | ||
.DS_Store | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import { h } from 'preact'; | ||
// import renderToString from 'preact-render-to-string'; | ||
import { marked } from 'marked'; | ||
|
||
const markdownPlugin = () => ({ | ||
name: 'our-custom-markdown-plugin', | ||
load(id) { | ||
if (id.endsWith('.md')) { | ||
const filePath = path.resolve(id); | ||
const markdown = fs.readFileSync(filePath, 'utf-8'); | ||
|
||
// Convert Markdown to HTML | ||
const renderedMarkdown = marked(markdown); | ||
|
||
// Export the transformed content | ||
return `export default ${JSON.stringify(renderedMarkdown)};`; | ||
} | ||
return null; | ||
} | ||
}); | ||
|
||
export default markdownPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.