@alauda/doom 0.6.7 → 0.6.8

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.
@@ -3,13 +3,11 @@ import os from 'node:os';
3
3
  import path from 'node:path';
4
4
  import { logger } from '@rspress/shared/logger';
5
5
  import { render } from 'ejs';
6
- import remarkFrontmatter from 'remark-frontmatter';
7
- import remarkStringify from 'remark-stringify';
8
6
  import { simpleGit } from 'simple-git';
9
7
  import { parse, stringify } from 'yaml';
10
8
  import { cyan, red } from 'yoctocolors';
11
9
  import { parseToc } from './remark-toc.js';
12
- import { getFrontmatterNode, mdProcessor, mdxProcessor, stringifySettings, } from './utils.js';
10
+ import { getFrontmatterNode, mdProcessor, mdxProcessor } from './utils.js';
13
11
  const remotesFolder = path.resolve(os.homedir(), '.doom/remotes');
14
12
  export const refCache = new Map();
15
13
  const resolveReference_ = async (localBasePath, items, refName, force) => {
@@ -223,25 +221,23 @@ export const remarkReplace = function ({ lang, localBasePath, root, items, force
223
221
  if (!maybeHaveRef(filepath, content)) {
224
222
  return;
225
223
  }
226
- const processor = this()
227
- .use(remarkFrontmatter)
228
- .use(remarkStringify, stringifySettings);
224
+ const isMdx = filepath.endsWith('.mdx');
225
+ const processor = isMdx ? mdxProcessor : mdProcessor;
229
226
  const originalAst = vfile.data.original
230
227
  ? ast
231
228
  : processor.parse((content = await fs.readFile(filepath, 'utf8')));
232
229
  const frontmatterNode = getFrontmatterNode(originalAst);
233
230
  let frontmatter = frontmatterNode &&
234
231
  parse(frontmatterNode.value);
235
- const isMdx = filepath.endsWith('.mdx');
236
232
  const relativePath = path.relative(root, filepath);
237
233
  const currLang = lang === null ? 'zh' : relativePath.split('/')[0];
238
- const references = [];
239
234
  const newAstChildren = [];
240
235
  const newContentChildren = [];
241
236
  let index = 0;
242
237
  let start = null;
243
238
  let refName = '';
244
239
  let matched;
240
+ let checkContent = false;
245
241
  for (const node of ast.children) {
246
242
  index++;
247
243
  if (node.type !== (isMdx ? 'mdxFlowExpression' : 'html')) {
@@ -256,9 +252,10 @@ export const remarkReplace = function ({ lang, localBasePath, root, items, force
256
252
  }
257
253
  if ((matched = node.value.match(isMdx ? MDX_REF_START_PATTERN : MD_REF_START_COMMENT_PATTERN))) {
258
254
  if (start != null) {
259
- logger.warn(`Invalid reference start block ${node.value}, nested reference blocks are not allowed`);
255
+ logger.warn(`Invalid reference start block ${red(node.value)}, nested reference blocks are not allowed`);
260
256
  }
261
257
  else {
258
+ checkContent = true;
262
259
  start = index;
263
260
  refName = matched[1].trim();
264
261
  }
@@ -268,10 +265,9 @@ export const remarkReplace = function ({ lang, localBasePath, root, items, force
268
265
  }
269
266
  if ((isMdx ? MDX_REF_END_PATTERN : MD_REF_END_COMMENT_PATTERN).test(node.value)) {
270
267
  if (start == null) {
271
- logger.warn(`Invalid reference end block ${node.value}, no matching start block found`);
268
+ logger.warn(`Invalid reference end block ${red(node.value)}, no matching start block found`);
272
269
  }
273
270
  else {
274
- references.push([start, index]);
275
271
  start = null;
276
272
  }
277
273
  const resolved = await resolveReference(localBasePath, items, refName, force);
@@ -315,7 +311,7 @@ export const remarkReplace = function ({ lang, localBasePath, root, items, force
315
311
  }
316
312
  }
317
313
  if (start != null) {
318
- logger.warn(`Invalid reference start block ${start}, no matching end block found, adding for you`);
314
+ logger.warn(`Invalid reference start block ${red(refName)}, no matching end block found, adding for you`);
319
315
  newContentChildren.push({
320
316
  type: isMdx ? 'mdxFlowExpression' : 'html',
321
317
  value: isMdx ? '/* reference-end */' : '<!-- reference-end -->',
@@ -327,13 +323,17 @@ export const remarkReplace = function ({ lang, localBasePath, root, items, force
327
323
  value: stringify(frontmatter).trim(),
328
324
  });
329
325
  }
330
- const newContent = processor.stringify({
331
- ...ast,
332
- children: newContentChildren.flat().filter((n) => n.type !== 'mdxjsEsm'),
333
- });
334
- if (content !== newContent) {
335
- await fs.writeFile(filepath, newContent);
336
- return;
326
+ if (checkContent) {
327
+ const newContent = processor.stringify({
328
+ ...ast,
329
+ children: newContentChildren
330
+ .flat()
331
+ .filter((n) => n.type !== 'mdxjsEsm'),
332
+ });
333
+ if (content !== newContent) {
334
+ await fs.writeFile(filepath, newContent);
335
+ return;
336
+ }
337
337
  }
338
338
  ast.children = newAstChildren.flat();
339
339
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "0.6.7",
3
+ "version": "0.6.8",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
6
  "repository": {