Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f3906cb

Browse files
committed
chore(docs): add media docs support
- Added '@nvidia-elements/media' to the configuration and package.json. - Updated Eleventy configuration to include public component documentation for media. - Enhanced example URL generation to support media components. - Refactored coverage calculation logic in API template for better clarity. - Updated pnpm lockfile to reflect new dependencies and versions. Signed-off-by: Cory Rylan <[email protected]>
1 parent 1e56150 commit f3906cb

9 files changed

Lines changed: 40 additions & 9 deletions

File tree

knip.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export default {
2424
'@nvidia-elements/forms',
2525
'@nvidia-elements/lint',
2626
'@nvidia-elements/markdown',
27+
'@nvidia-elements/media',
2728
'@nvidia-elements/styles',
2829
'@semantic-release/commit-analyzer',
2930
'@semantic-release/github',

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

projects/internals/eslint/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ Applied to `src/**/*.ts`, `src/**/*.tsx`, test files, and `*.examples.ts`.
7474
**Source hygiene**
7575

7676
- **`no-dead-code`**. Flags commented-out imports, exports, declarations, control-flow, and test blocks. The project currently sets this to `warn` during cleanup.
77+
- **`no-deep-class-inheritance`**. Limits class inheritance chains to two superclass hops by default, stopping at configured `allowedRoots` such as `HTMLElement` and `LitElement`.
7778
- **`require-spdx-header`**. Every source file must start with the two-line SPDX header (`SPDX-FileCopyrightText` copyright + `SPDX-License-Identifier: Apache-2.0`). The rule accepts any 4-digit year; auto-fix preserves an existing year and falls back to the current year only when inserting a header from scratch.
7879

7980
### Example rules (plugin `local-typescript`, files `**/*.examples.ts`)

projects/site/eleventy.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ export default function (eleventyConfig) {
222222
* - Access the collection data in templates and layouts
223223
* - Sort and filter content based on frontmatter or other criteria
224224
*
225-
* This collection includes all markdown files in src/docs/elements/, making component docs easily accessible throughout the site build process.
225+
* This collection includes public component docs, making component metadata accessible throughout the site build process.
226226
*
227227
* Used by `../src/docs/elements/_tabs/api.11ty.js` to generate the API documentation page for each component.
228228
*/
@@ -233,6 +233,7 @@ export default function (eleventyConfig) {
233233
'src/docs/elements/data-grid/index.md',
234234
'src/docs/code/*.md',
235235
'src/docs/monaco/*.md',
236+
'src/docs/media/*.md',
236237
'src/docs/markdown/index.md'
237238
]);
238239
});

projects/site/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@
8888
"../forms/dist/**/*.examples.json",
8989
"../markdown/dist/**/*.js",
9090
"../markdown/dist/**/*.examples.json",
91+
"../media/dist/**/*.js",
92+
"../media/dist/**/*.examples.json",
9193
"../monaco/dist/**/*.js",
9294
"../monaco/dist/**/*.examples.json",
9395
"../internals/metadata/static/**",
@@ -121,6 +123,10 @@
121123
"script": "../markdown:build",
122124
"cascade": false
123125
},
126+
{
127+
"script": "../media:build",
128+
"cascade": false
129+
},
124130
{
125131
"script": "../monaco:build",
126132
"cascade": false
@@ -244,6 +250,7 @@
244250
"@nvidia-elements/forms": "workspace:*",
245251
"@nvidia-elements/lint": "workspace:*",
246252
"@nvidia-elements/markdown": "workspace:*",
253+
"@nvidia-elements/media": "workspace:*",
247254
"@nvidia-elements/core": "workspace:*",
248255
"@nvidia-elements/monaco": "workspace:*",
249256
"@nvidia-elements/styles": "workspace:*",

projects/site/src/_11ty/layouts/docs.11ty.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ function getSection(url) {
3636
if (section === 'integrations') return 'integrations';
3737
if (section === 'foundations') return 'foundations';
3838
if (section === 'patterns') return 'patterns';
39+
if (section === 'media') return 'elements';
3940
if (section === 'code' || section === 'monaco' || section === 'markdown') return 'code';
4041
if (section === 'labs') return 'labs';
4142
if (section === 'internal' || section === 'api-design') return 'internal';

projects/site/src/_11ty/templates/api.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ export function elementSummary(tag) {
5858
const element = elements.find(d => d.name === tag);
5959
const testReports = Object.values(tests.projects);
6060
const unitTestResults = testReports.flatMap(report => report.coverage.testResults);
61-
const coverageTotal =
62-
unitTestResults.find(result => result.file?.includes(tag.replace('nve-', '')))?.branches.pct ?? 0;
61+
const coverageTotal = getElementCoverageTotal(tag, unitTestResults);
6362
const lighthouseResults = testReports
6463
.flatMap(report => report.lighthouse)
6564
.flatMap(result => result.testResults)
@@ -93,6 +92,18 @@ export function elementSummary(tag) {
9392
</section>`;
9493
}
9594

95+
function getElementCoverageTotal(tag, unitTestResults) {
96+
const elementName = tag.replace('nve-', '');
97+
const implementationPath = `${elementName}/${elementName}.ts`;
98+
const exactResult = unitTestResults.find(result => result.file === implementationPath);
99+
const fileNameResult = unitTestResults.find(result => result.file?.endsWith(`/${elementName}.ts`));
100+
const broadResult = unitTestResults.find(
101+
result => result.file?.includes(elementName) && !result.file.endsWith('/define.ts')
102+
);
103+
104+
return (exactResult ?? fileNameResult ?? broadResult)?.branches.pct;
105+
}
106+
96107
/**
97108
* Generates the component support buttons section for a given custom element tag.
98109
* @param {string} tag - The component tag name
@@ -192,15 +203,16 @@ export function badgeStatus(status, container = '', content = '') {
192203
*/
193204
export function badgeCoverage(value, container = '', content = '') {
194205
let status = 'unknown';
195-
let formattedValue = value
206+
const hasCoverage = Number.isFinite(value);
207+
const formattedValue = hasCoverage
196208
? new Intl.NumberFormat('default', {
197209
style: 'percent',
198210
minimumFractionDigits: 2,
199211
maximumFractionDigits: 2
200212
}).format(value / 100)
201-
: null;
213+
: 'unknown';
202214

203-
if (value !== undefined) {
215+
if (hasCoverage) {
204216
if (value >= 90) {
205217
status = 'success';
206218
} else if (value >= 70) {

projects/site/src/docs/elements/_tabs/examples.11ty.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ export const data = {
2626
eleventyComputed: {
2727
noindex: data => data.component.data.hideExamplesTab || !data.component.data.tag
2828
},
29-
// Generate URLs in the format /docs/elements/{component-name}/examples/ or /docs/code/{component-name}/examples/ or /docs/monaco/{component-name}/examples/
29+
// Generate URLs in the format /docs/elements/{component-name}/examples/ or package-specific component docs paths.
3030
permalink: data => {
3131
const filePath = data.component.filePathStem;
3232
let dir = 'elements';
3333
if (filePath.includes('/code/')) dir = 'code';
3434
else if (filePath.includes('/monaco/')) dir = 'monaco';
35+
else if (filePath.includes('/media/')) dir = 'media';
3536
else if (filePath.includes('/markdown/')) dir = '';
3637
return `/docs/${dir}/${data.component.fileSlug}/examples/`;
3738
}

projects/starters/eleventy-ssr/src/index.11ty.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import { ApiService, ExamplesService } from '@internals/metadata';
44

5+
const ssrPackageNames = ['@nvidia-elements/code', '@nvidia-elements/core', '@nvidia-elements/media'];
6+
const hasSsrEntrypoint = entrypoint => ssrPackageNames.some(packageName => entrypoint?.startsWith(`${packageName}/`));
7+
58
const elements = (await ApiService.getData()).data.elements;
69
const examples = (await ExamplesService.getData())
710
.filter(
@@ -14,10 +17,11 @@ const examples = (await ExamplesService.getData())
1417
)
1518
.map(example => {
1619
const element = elements.find(e => e.name === example.element && !e.manifest?.deprecated);
17-
return element
20+
const entrypoint = element?.manifest?.metadata?.entrypoint;
21+
return element && hasSsrEntrypoint(entrypoint)
1822
? {
1923
name: example.element,
20-
entrypoint: element?.manifest?.metadata?.entrypoint,
24+
entrypoint,
2125
template: example.template
2226
.replaceAll('<label>', '<label slot="label">')
2327
.replaceAll('<nve-control-message>', '<nve-control-message slot="messages">')

0 commit comments

Comments
 (0)