host-mdx 2.2.0 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +30 -19
  2. package/index.js +10 -3
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -27,13 +27,16 @@ You can add a file by the name `.hostmdxignore` at the root of your project to f
27
27
  You can also add a file by the name `host-mdx.js` at the root of your input folder as a config file with access to the following:
28
28
 
29
29
  ```js
30
+ onHostStart(port)
31
+ onHostEnd(port)
32
+ toTriggerRecreate(event, path)
30
33
  onSiteCreateStart(inputPath, outputPath)
31
34
  onSiteCreateEnd(inputPath, outputPath, wasInterrupted)
32
35
  onFileCreateStart(inputPath, outputPath, inFilePath, outFilePath)
33
36
  onFileCreateEnd(inputPath, outputPath, inFilePath, outFilePath, result)
34
- modBundleMDXSettings(inputPath, outputPath, settings)
37
+ modMDXCode(inputPath, outputPath, inFilePath, outFilePath, code)
35
38
  modGlobalArgs(inputPath, outputPath, globalArgs)
36
- toTriggerRecreate(event, path)
39
+ modBundleMDXSettings(inputPath, outputPath, settings)
37
40
  ```
38
41
 
39
42
  > **Note:** Any changes made to `host-mdx.js` or any new package added requires complete restart otherwise changes will not reflect due to [this bug](https://github.com/nodejs/node/issues/49442)
@@ -90,36 +93,44 @@ static/temp.jpg
90
93
  `host-mdx.js` file content:
91
94
 
92
95
  ```js
93
- export function onSiteCreateStart(inputPath, outputPath) {
96
+ export async function onHostStart(port) {
97
+ console.log("onHostStart", port)
98
+ }
99
+ export async function onHostEnd(port) {
100
+ console.log("onHostEnd", port)
101
+ }
102
+ export async function toTriggerRecreate(event, path) {
103
+ const isGOutputStream = /\.goutputstream-\w+$/.test(path);
104
+ if (isGOutputStream) {
105
+ return false;
106
+ }
107
+
108
+ return true;
109
+ }
110
+ export async function onSiteCreateStart(inputPath, outputPath) {
94
111
  console.log("onSiteCreateStart", inputPath, outputPath)
95
112
  }
96
- export function onSiteCreateEnd(inputPath, outputPath, wasSuccessful) {
113
+ export async function onSiteCreateEnd(inputPath, outputPath, wasSuccessful) {
97
114
  console.log("onSiteCreateEnd", inputPath, outputPath, wasSuccessful)
98
115
  }
99
- export function onFileCreateStart(inputFilePath, outputFilePath) {
116
+ export async function onFileCreateStart(inputFilePath, outputFilePath) {
100
117
  console.log("onFileCreateStart", inputFilePath, outputFilePath)
101
118
  }
102
- export function onFileCreateEnd(inputFilePath, outputFilePath) {
119
+ export async function onFileCreateEnd(inputFilePath, outputFilePath) {
103
120
  console.log("onFileCreateEnd", inputFilePath, outputFilePath)
104
121
  }
105
- export function onHostStart(port) {
106
- console.log("onHostStart", port)
122
+ export async function modMDXCode(inputPath, outputPath, inFilePath, outFilePath, code){
123
+ // Modify code ...
124
+ return code;
107
125
  }
108
- export function onHostEnd(port) {
109
- console.log("onHostEnd", port)
126
+ export async function modGlobalArgs(inputPath, outputPath, globalArgs){
127
+ // Modify globalArgs ...
128
+ return globalArgs;
110
129
  }
111
- export function modBundleMDXSettings(inputPath, outputPath, settings) {
130
+ export async function modBundleMDXSettings(inputPath, outputPath, settings) {
112
131
  // Modify settings ...
113
132
  return settings
114
133
  }
115
- export function toTriggerRecreate(event, path) {
116
- const isGOutputStream = /\.goutputstream-\w+$/.test(path);
117
- if (isGOutputStream) {
118
- return false;
119
- }
120
-
121
- return true;
122
- }
123
134
  ```
124
135
 
125
136
  Output Directory:
package/index.js CHANGED
@@ -192,12 +192,19 @@ async function createSite(inputPath, outputPath) {
192
192
  // Broadcast file creation started
193
193
  let absHtmlPath = path.format({ ...path.parse(absToOutput), base: '', ext: '.html' })
194
194
  log(`${currentPath} ---> ${absHtmlPath}`, true)
195
- await configs?.onFileCreateStart?.(inputPath, outputPath, currentPath, absHtmlPath, undefined)
195
+ await configs?.onFileCreateStart?.(inputPath, outputPath, currentPath, absHtmlPath)
196
196
 
197
197
 
198
- // convert mdx code into html & paste into file
198
+ // Intercept mdx code
199
199
  let mdxCode = fs.readFileSync(currentPath, 'utf8');
200
- let parentDir = path.dirname(currentPath)
200
+ if (typeof configs?.modMDXCode === 'function') {
201
+ log(`Modifying mdx code of ${currentPath}`, true);
202
+ mdxCode = await configs?.modMDXCode(inputPath, outputPath, currentPath, absHtmlPath, mdxCode);
203
+ }
204
+
205
+
206
+ // convert mdx code into html & paste into file
207
+ let parentDir = path.dirname(currentPath);
201
208
  let globalArgs = {
202
209
  hostmdxCwd: parentDir,
203
210
  hostmdxInputPath: inputPath,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "host-mdx",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "A cli tool to create and serve a static html website from a given mdx directory",
5
5
  "main": "index.js",
6
6
  "type": "module",