Skip to content

Commit

Permalink
feat(docs): baseline indicator (#8772)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoMcA authored May 10, 2023
1 parent 4d5f93a commit 35786d8
Show file tree
Hide file tree
Showing 19 changed files with 333 additions and 3 deletions.
21 changes: 20 additions & 1 deletion build/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import path from "node:path";

import chalk from "chalk";
import webFeatures from "web-features/index.json" assert { type: "json" };

import {
MacroInvocationError,
MacroLiveSampleError,
MacroRedirectedLinkError,
} from "../kumascript/src/errors.js";

import { Doc } from "../libs/types/document.js";
import { Doc, WebFeature, WebFeatureStatus } from "../libs/types/document.js";
import { Document, execGit } from "../content/index.js";
import { CONTENT_ROOT, REPOSITORY_URLS } from "../libs/env/index.js";
import * as kumascript from "../kumascript/index.js";
Expand Down Expand Up @@ -359,6 +361,8 @@ export async function buildDocument(
browserCompat &&
(Array.isArray(browserCompat) ? browserCompat : [browserCompat]);

doc.baseline = addBaseline(doc);

// If the document contains <math> HTML, it will set `doc.hasMathML=true`.
// The client (<Document/> component) needs to know this for loading polyfills.
if ($("math").length > 0) {
Expand Down Expand Up @@ -522,6 +526,21 @@ export async function buildDocument(
return { doc: doc as Doc, liveSamples, fileAttachments };
}

function addBaseline(doc: Partial<Doc>): WebFeatureStatus | undefined {
if (doc.browserCompat) {
for (const feature of Object.values<WebFeature>(webFeatures)) {
if (
feature.status &&
feature.compat_features?.some((query) =>
doc.browserCompat?.includes(query)
)
) {
return feature.status;
}
}
}
}

interface BuiltLiveSamplePage {
id: string;
html: string | null;
Expand Down
1 change: 1 addition & 0 deletions client/src/assets/icons/baseline/browser-check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions client/src/assets/icons/baseline/browser-cross.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions client/src/assets/icons/baseline/check-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions client/src/assets/icons/baseline/check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions client/src/assets/icons/baseline/chrome.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions client/src/assets/icons/baseline/cross-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions client/src/assets/icons/baseline/cross.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions client/src/assets/icons/baseline/edge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 35786d8

Please sign in to comment.