|
1 | 1 | import path from "node:path";
|
2 | 2 |
|
3 | 3 | import chalk from "chalk";
|
| 4 | +import webFeatures from "web-features/index.json" assert { type: "json" }; |
| 5 | + |
4 | 6 | import {
|
5 | 7 | MacroInvocationError,
|
6 | 8 | MacroLiveSampleError,
|
7 | 9 | MacroRedirectedLinkError,
|
8 | 10 | } from "../kumascript/src/errors.js";
|
9 | 11 |
|
10 |
| -import { Doc } from "../libs/types/document.js"; |
| 12 | +import { Doc, WebFeature, WebFeatureStatus } from "../libs/types/document.js"; |
11 | 13 | import { Document, execGit } from "../content/index.js";
|
12 | 14 | import { CONTENT_ROOT, REPOSITORY_URLS } from "../libs/env/index.js";
|
13 | 15 | import * as kumascript from "../kumascript/index.js";
|
@@ -359,6 +361,8 @@ export async function buildDocument(
|
359 | 361 | browserCompat &&
|
360 | 362 | (Array.isArray(browserCompat) ? browserCompat : [browserCompat]);
|
361 | 363 |
|
| 364 | + doc.baseline = addBaseline(doc); |
| 365 | + |
362 | 366 | // If the document contains <math> HTML, it will set `doc.hasMathML=true`.
|
363 | 367 | // The client (<Document/> component) needs to know this for loading polyfills.
|
364 | 368 | if ($("math").length > 0) {
|
@@ -522,6 +526,21 @@ export async function buildDocument(
|
522 | 526 | return { doc: doc as Doc, liveSamples, fileAttachments };
|
523 | 527 | }
|
524 | 528 |
|
| 529 | +function addBaseline(doc: Partial<Doc>): WebFeatureStatus | undefined { |
| 530 | + if (doc.browserCompat) { |
| 531 | + for (const feature of Object.values<WebFeature>(webFeatures)) { |
| 532 | + if ( |
| 533 | + feature.status && |
| 534 | + feature.compat_features?.some((query) => |
| 535 | + doc.browserCompat?.includes(query) |
| 536 | + ) |
| 537 | + ) { |
| 538 | + return feature.status; |
| 539 | + } |
| 540 | + } |
| 541 | + } |
| 542 | +} |
| 543 | + |
525 | 544 | interface BuiltLiveSamplePage {
|
526 | 545 | id: string;
|
527 | 546 | html: string | null;
|
|
0 commit comments