@alauda/doom 2.1.0 → 2.2.0

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.
package/global.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  /// <reference types="@total-typescript/ts-reset" />
2
- /// <reference types="@alauda/doom/types" />
3
2
 
4
3
  type MDXProvidedComponents = typeof import('@alauda/doom/runtime')
5
4
 
@@ -8,10 +8,11 @@ export declare function extractInfoFromFrontmatter(filePath: string, rootDir: st
8
8
  context: string | undefined;
9
9
  weight?: number;
10
10
  }>;
11
- export declare function combineWalkResult(walks: {
11
+ export interface WalkResult {
12
12
  nav: NavItem[];
13
13
  sidebar: Record<string, DoomSidebar[]>;
14
- }[], versions: string[]): {
15
- nav: {};
16
- sidebar: {};
14
+ }
15
+ export declare function combineWalkResult(walks: WalkResult[], versions: string[]): {
16
+ nav: Record<string, NavItem[]>;
17
+ sidebar: Record<string, DoomSidebar[]>;
17
18
  };
@@ -39,8 +39,8 @@ export const mdProcessor = unified()
39
39
  .freeze();
40
40
  export const mdxProcessor = mdProcessor().use(remarkMdx).freeze();
41
41
  export const getFrontmatterNode = (ast) => {
42
- const firstNode = ast.children[0];
43
- return firstNode.type === 'yaml' ? firstNode : undefined;
42
+ const firstNode = ast.children.at(0);
43
+ return firstNode?.type === 'yaml' ? firstNode : undefined;
44
44
  };
45
45
  const { CI } = process.env;
46
46
  export const isCI = CI !== 'false' && !!CI;
@@ -16,6 +16,7 @@ export * from './no-paragraph-indent.ts';
16
16
  export * from './no-unmatched-anchor.ts';
17
17
  export * from './site.ts';
18
18
  export * from './table-size.ts';
19
+ export * from './title-required.ts';
19
20
  export * from './unit-case.ts';
20
21
  declare const doomLint: Plugin<[], Root>;
21
22
  export default doomLint;
@@ -15,6 +15,7 @@ export * from "./no-paragraph-indent.js";
15
15
  export * from "./no-unmatched-anchor.js";
16
16
  export * from "./site.js";
17
17
  export * from "./table-size.js";
18
+ export * from "./title-required.js";
18
19
  export * from "./unit-case.js";
19
20
  const doomLint = function () {
20
21
  this.use(() => remarkMessageControl({
@@ -0,0 +1,2 @@
1
+ import type { Root } from 'mdast';
2
+ export declare const titleRequired: import("unified-lint-rule").Plugin<Root, unknown>;
@@ -0,0 +1,44 @@
1
+ import { toString } from 'mdast-util-to-string';
2
+ import { lintRule } from 'unified-lint-rule';
3
+ import { visitParents } from 'unist-util-visit-parents';
4
+ import { parse } from 'yaml';
5
+ export const titleRequired = lintRule('doom-lint:title-required', (root, vfile) => {
6
+ let frontmatterTitle;
7
+ let headingTitle;
8
+ visitParents(root, (node, parents) => {
9
+ if (node.type === 'yaml') {
10
+ frontmatterTitle = parse(node.value)
11
+ ?.title;
12
+ }
13
+ function checkHeadingTitle(title) {
14
+ if (headingTitle) {
15
+ vfile.message('Multiple level 1 headings found, remove redundant heading or consolidate them into one.', {
16
+ ancestors: [...parents, node],
17
+ place: node.position,
18
+ });
19
+ }
20
+ else {
21
+ headingTitle = title;
22
+ }
23
+ }
24
+ if (node.type === 'heading') {
25
+ if (node.depth === 1) {
26
+ checkHeadingTitle(toString(node));
27
+ }
28
+ }
29
+ else if (node.type === 'html') {
30
+ for (const [, title] of node.value.matchAll(/<h1[^>]*>([\s\S]*?)<\/h1>/gi)) {
31
+ checkHeadingTitle(title);
32
+ }
33
+ }
34
+ else if (node.type === 'mdxJsxFlowElement' ||
35
+ node.type === 'mdxJsxTextElement') {
36
+ if (node.name === 'h1') {
37
+ checkHeadingTitle(toString(node));
38
+ }
39
+ }
40
+ });
41
+ if (!frontmatterTitle && !headingTitle) {
42
+ vfile.message('Title is required. Please add a title in the frontmatter or as a heading.', root);
43
+ }
44
+ });
package/lib/remarkrc.js CHANGED
@@ -10,7 +10,7 @@ import remarkLintLintMatchPunctuation from 'remark-lint-match-punctuation';
10
10
  import remarkLintNoChinesePunctuationInNumber from 'remark-lint-no-chinese-punctuation-in-number';
11
11
  import remarkLintNoDuplicateHeadingsInSection from 'remark-lint-no-duplicate-headings-in-section';
12
12
  import remarkLintNoHiddenTableCell from 'remark-lint-no-hidden-table-cell';
13
- import doomLint, { checkDeadLinks, noDeepHeading, noDeepList, noMultiOpenAPIPaths, noParagraphIndent, noUnmatchedAnchor, site, tableSize, unitCase, } from "./remark-lint/index.js";
13
+ import doomLint, { checkDeadLinks, noDeepHeading, noDeepList, noMultiOpenAPIPaths, noParagraphIndent, noUnmatchedAnchor, site, tableSize, titleRequired, unitCase, } from "./remark-lint/index.js";
14
14
  export default {
15
15
  plugins: [
16
16
  remarkDirective,
@@ -31,6 +31,7 @@ export default {
31
31
  noUnmatchedAnchor,
32
32
  site,
33
33
  tableSize,
34
+ titleRequired,
34
35
  unitCase,
35
36
  ],
36
37
  };
@@ -1,4 +1,5 @@
1
1
  /// <reference path="../../global.d.ts" preserve="true" />
2
+ /// <reference path="../types.d.ts" preserve="true" />
2
3
  export * from '../terms.js';
3
4
  export * from './components/index.js';
4
5
  export * from './hooks/index.js';
@@ -2,6 +2,8 @@
2
2
  /// <reference path="../../shim.d.ts" />
3
3
  // eslint-disable-next-line @typescript-eslint/triple-slash-reference
4
4
  /// <reference path="../../global.d.ts" preserve="true" />
5
+ // eslint-disable-next-line @typescript-eslint/triple-slash-reference
6
+ /// <reference path="../types.ts" preserve="true" />
5
7
  export * from '../terms.js';
6
8
  export * from './components/index.js';
7
9
  export * from './hooks/index.js';
package/lib/utils/fs.js CHANGED
@@ -1,4 +1,4 @@
1
- import fs from 'fs/promises';
1
+ import fs from 'node:fs/promises';
2
2
  export async function pathExists(path, type) {
3
3
  try {
4
4
  const stats = await fs.stat(path);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
6
  "repository": {
@@ -14,6 +14,9 @@
14
14
  "node": ">=22.18.0"
15
15
  },
16
16
  "bin": "lib/cli/index.js",
17
+ "imports": {
18
+ "#*": "./src/*"
19
+ },
17
20
  "exports": {
18
21
  "./assets/*": "./assets/*",
19
22
  "./config": "./lib/config.js",