Skip to content

Commit

Permalink
chore: add api type
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk committed Jan 1, 2024
1 parent e295e99 commit c402855
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 15 deletions.
4 changes: 1 addition & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
"request": "launch",
"name": "site generate",
"runtimeArgs": ["-r", "ts-node/register", "-r", "tsconfig-paths/register"],
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart",
"args": ["${workspaceFolder}/scripts/site/generate.ts", "getting-started"],
"args": ["${workspaceFolder}/scripts/site/generate.ts", "auto-focus"],
"env": {
"TS_NODE_PROJECT": "${workspaceFolder}/scripts/site/tsconfig.json",
"TS_NODE_TRANSPILE_ONLY": "true"
Expand All @@ -31,7 +30,6 @@
"name": "schematics test",
"runtimeArgs": ["-r", "ts-node/register"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"sourceMaps": true,
"internalConsoleOptions": "openOnSessionStart",
"env": {
Expand Down
2 changes: 1 addition & 1 deletion packages/abc/auto-focus/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Allows to focus HTML-element right after its appearance, By default, it will tak

## API

### [auto-focus]
### [auto-focus]:standalone

| Property | Description | Type | Default |
|----------|-------------|------|---------|
Expand Down
2 changes: 1 addition & 1 deletion packages/abc/auto-focus/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module: import { AutoFocusModule } from '@delon/abc/auto-focus';

## API

### [auto-focus]
### [auto-focus]:standalone

| 成员 | 说明 | 类型 | 默认值 |
|----|----|----|-----|
Expand Down
16 changes: 10 additions & 6 deletions scripts/site/utils/generate-md.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@ const converters = [highlight()].concat([
(node: any) => {
const tagName = JsonML.getTagName(node) as string;
const children = JsonML.getChildren(node);
const sluggedId = generateSluggedId(children).id;
const sluggedData = generateSluggedId(children);
// <a href="#${sluggedId}" class="anchor">#</a>
const childrenHtml = children.map(toHtml).join('');
// const childrenHtml = children.map(toHtml).join('');
// const goTo = tagName === 'h2' ? `<a onclick="window.location.hash = '${sluggedId}'" class="anchor">#</a>` : '';
const apiTypes = ['directive', 'standalone', 'service', 'class']
.filter(key => (sluggedData as any)[key] === true)
.map(w => `<label class="api-type-label ${w}">${w}</label>`)
.join('');
const copy =
/h[0-9]{1}/g.test(tagName) && +tagName.substring(1) > 1
? `<a class="lake-link"><i data-anchor="${sluggedId}"></i></a>`
? `<a class="lake-link"><i data-anchor="${sluggedData.id}"></i></a>`
: ``;
return `<${tagName} id="${sluggedId}">${copy}${childrenHtml}</${tagName}>`;
return `<${tagName} id="${sluggedData.id}">${copy}${sluggedData.id}${apiTypes}</${tagName}>`;
}
],
[
Expand All @@ -54,7 +58,7 @@ const converters = [highlight()].concat([
],
[
(node: any) => JsonML.isElement(node) && JsonML.getTagName(node) === 'a',
(node: any, index: number) => {
(node: any, _: number) => {
const attrs = { ...JsonML.getAttributes(node) };
let target = attrs.href.startsWith('//') || attrs.href.startsWith('http') ? ' target="_blank"' : '';
if (~attrs.href.indexOf('ng-alain.com')) target = '';
Expand All @@ -65,7 +69,7 @@ const converters = [highlight()].concat([
],
[
(node: any) => !Array.isArray(node),
(node: any, index: number) => {
(node: any, _: number) => {
if (!node.url) return '';
return `<!--${node.url}-->`;
}
Expand Down
20 changes: 16 additions & 4 deletions scripts/site/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ export function genValidId(id: string): string {
return id.replace(/[() `?]*/g, '');
}

export function generateSluggedId(children: any): { id: string; text: string } {
export function generateSluggedId(children: any): {
id: string;
text: string;
directive: boolean;
standalone: boolean;
service: boolean;
class: boolean;
} {
const headingText = children
.map((node: any) => {
if (JsonML.isElement(node)) {
Expand All @@ -52,10 +59,15 @@ export function generateSluggedId(children: any): { id: string; text: string } {
}
return node;
})
.join('');
.join('')
.trim();
return {
id: genValidId(headingText.trim()),
text: headingText
id: genValidId(headingText).split(':')[0],
text: headingText,
directive: children.some((node: any) => JsonML.isElement(node)),
standalone: headingText.includes(':standalone'),
service: headingText.includes(':service'),
class: headingText.includes(':class')
};
}

Expand Down
39 changes: 39 additions & 0 deletions src/styles/_markdown.less
Original file line number Diff line number Diff line change
Expand Up @@ -499,3 +499,42 @@
margin-top: 40px;
}
}

label.api-type-label {
display: inline;
margin-left: 8px;
padding: 1px 10px;
font-size: 12px;
font-weight: 400;
line-height: 18px;
color: #ffffffd9;
text-transform: uppercase;
vertical-align: middle;
border-radius: 2px;

&.component {
color: @primary-color;
border: 2px solid @primary-color
}

&.standalone {
color: @warning-color;
border: 2px solid @warning-color
}

&.directive {
color: @magenta-6;
border: 2px solid @magenta-6
}

&.service {
color: @success-color;
border: 2px solid @success-color
}

&.class {
color: @volcano-6;
border: 2px solid @volcano-6
}

}

0 comments on commit c402855

Please sign in to comment.