@alauda/doom 1.18.2 → 1.18.3
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/lib/remark-lint/index.d.ts +1 -0
- package/lib/remark-lint/index.js +1 -0
- package/lib/remark-lint/site.d.ts +2 -0
- package/lib/remark-lint/site.js +38 -0
- package/lib/remarkrc.js +2 -1
- package/lib/runtime/components/ExternalSiteLink.js +3 -4
- package/lib/runtime/components/_ExternalSiteBase.js +1 -1
- package/package.json +1 -1
|
@@ -12,6 +12,7 @@ export * from './no-heading-punctuation.ts';
|
|
|
12
12
|
export * from './no-heading-special-characters.ts';
|
|
13
13
|
export * from './no-heading-sup-sub.ts';
|
|
14
14
|
export * from './no-paragraph-indent.ts';
|
|
15
|
+
export * from './site.ts';
|
|
15
16
|
export * from './table-size.ts';
|
|
16
17
|
export * from './unit-case.ts';
|
|
17
18
|
declare const doomLint: Plugin<[], Root>;
|
package/lib/remark-lint/index.js
CHANGED
|
@@ -11,6 +11,7 @@ export * from "./no-heading-punctuation.js";
|
|
|
11
11
|
export * from "./no-heading-special-characters.js";
|
|
12
12
|
export * from "./no-heading-sup-sub.js";
|
|
13
13
|
export * from "./no-paragraph-indent.js";
|
|
14
|
+
export * from "./site.js";
|
|
14
15
|
export * from "./table-size.js";
|
|
15
16
|
export * from "./unit-case.js";
|
|
16
17
|
const doomLint = function () {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { lintRule } from 'unified-lint-rule';
|
|
3
|
+
import { visitParents } from 'unist-util-visit-parents';
|
|
4
|
+
import { SITES_FILE } from "../cli/constants.js";
|
|
5
|
+
import { pathExists } from "../utils/fs.js";
|
|
6
|
+
import { resolveStaticConfig } from "../utils/helpers.js";
|
|
7
|
+
const SITE_ELEMENTS = new Set([
|
|
8
|
+
'ExternalApisOverview',
|
|
9
|
+
'ExternalSite',
|
|
10
|
+
'ExternalSiteLink',
|
|
11
|
+
]);
|
|
12
|
+
const sitesConfigFilePath = path.resolve(SITES_FILE);
|
|
13
|
+
let sites;
|
|
14
|
+
export const site = lintRule('doom:lint-site', async (root, vfile) => {
|
|
15
|
+
if (!sites) {
|
|
16
|
+
if (await pathExists(sitesConfigFilePath, 'file')) {
|
|
17
|
+
sites = await resolveStaticConfig(sitesConfigFilePath);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
sites = [];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
visitParents(root, 'mdxJsxFlowElement', (element, parents) => {
|
|
24
|
+
if (!sites?.length || !element.name || !SITE_ELEMENTS.has(element.name)) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const nameAttr = element.attributes.find((attr) => attr.type === 'mdxJsxAttribute' && attr.name === 'name');
|
|
28
|
+
const nameVal = nameAttr?.value;
|
|
29
|
+
if (typeof nameVal === 'string' &&
|
|
30
|
+
sites.some((site) => site.name === nameVal)) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
vfile.message(`Invalid site \`name\` property value \`${typeof nameVal === 'string' ? nameVal : nameVal?.value}\` which should be static string matching a site name from \`${SITES_FILE}\` config.`, {
|
|
34
|
+
ancestors: [...parents, element],
|
|
35
|
+
place: (nameAttr ?? element).position,
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
});
|
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, noParagraphIndent, tableSize, unitCase, } from "./remark-lint/index.js";
|
|
13
|
+
import doomLint, { checkDeadLinks, noDeepHeading, noDeepList, noParagraphIndent, site, tableSize, unitCase, } from "./remark-lint/index.js";
|
|
14
14
|
export default {
|
|
15
15
|
plugins: [
|
|
16
16
|
remarkDirective,
|
|
@@ -27,6 +27,7 @@ export default {
|
|
|
27
27
|
noDeepHeading,
|
|
28
28
|
noDeepList,
|
|
29
29
|
noParagraphIndent,
|
|
30
|
+
site,
|
|
30
31
|
tableSize,
|
|
31
32
|
unitCase,
|
|
32
33
|
],
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useLang, useSite } from '@rspress/core/runtime';
|
|
3
3
|
import { addTrailingSlash, isExternalUrl, normalizeHref, parseUrl, removeLeadingSlash, } from '@rspress/shared';
|
|
4
4
|
import { DEFAULT_PAGE_EXTENSIONS } from '@rspress/shared/constants';
|
|
@@ -7,17 +7,16 @@ import virtual from 'doom-@global-virtual';
|
|
|
7
7
|
import { useMemo } from 'react';
|
|
8
8
|
import { isUnversioned } from '../../shared/helpers.js';
|
|
9
9
|
import { useIsPrint } from '../hooks/index.js';
|
|
10
|
-
import { Directive } from './Directive.js';
|
|
11
10
|
const ExternalSiteLink_ = ({ name, href = '', className, ...props }) => {
|
|
12
11
|
const isPrint = useIsPrint();
|
|
13
12
|
const { site: siteData } = useSite();
|
|
14
13
|
const site = useMemo(() => virtual.sites?.find((s) => s.name === name), [name]);
|
|
15
14
|
const lang = useLang();
|
|
16
15
|
if (!site) {
|
|
17
|
-
|
|
16
|
+
throw new Error(`No site with name \`${name}\` found, please ensure it's already defined at \`sites.yaml\``);
|
|
18
17
|
}
|
|
19
18
|
if (isExternalUrl(href)) {
|
|
20
|
-
|
|
19
|
+
throw new Error(`Invalid href \`${href}\` found`);
|
|
21
20
|
}
|
|
22
21
|
let { url, hash } = parseUrl(href);
|
|
23
22
|
const extname = url.split('.').at(-1);
|
|
@@ -34,7 +34,7 @@ export const ExternalSiteBase = ({ name, template }) => {
|
|
|
34
34
|
const lang = useLang();
|
|
35
35
|
const displayName = useMemo(() => site?.displayName?.[lang] || site?.displayName?.en || name.toUpperCase(), [lang, name, site?.displayName]);
|
|
36
36
|
if (!site) {
|
|
37
|
-
|
|
37
|
+
throw new Error(`No site with name \`${name}\` found, please ensure it's already defined at \`sites.yaml\``);
|
|
38
38
|
}
|
|
39
39
|
const Notes = template === 'apisOverview' ? ApisOverviewNotes : SiteNotes;
|
|
40
40
|
const Note = Notes[lang] || Notes.en;
|