-
Notifications
You must be signed in to change notification settings - Fork 510
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(baseline): hide when feature status differs from BCD key status (#…
- Loading branch information
Showing
4 changed files
with
62 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,37 @@ | ||
import { features } from "web-features"; | ||
import { computeBaseline } from "compute-baseline"; | ||
|
||
export function getWebFeatureStatus(...bcdKeys: string[]) { | ||
if (bcdKeys.length === 0) { | ||
return; | ||
import type { Doc } from "../libs/types/document.js"; | ||
|
||
export function addBaseline(doc: Partial<Doc>) { | ||
if ( | ||
doc.browserCompat && | ||
doc.browserCompat.length == 1 && | ||
!doc.mdn_url?.includes("/docs/MDN/") | ||
) { | ||
const bcdKey = doc.browserCompat[0]; | ||
const { featureStatus, keyStatus } = getStatuses(bcdKey); | ||
|
||
if (!featureStatus) { | ||
return; | ||
} | ||
|
||
if (featureStatus.baseline !== keyStatus.baseline) { | ||
return; | ||
} | ||
|
||
return featureStatus; | ||
} | ||
} | ||
|
||
function getStatuses(bcdKey: string) { | ||
for (const feature of Object.values(features)) { | ||
if ( | ||
feature.status && | ||
feature.compat_features?.some((feature) => bcdKeys.includes(feature)) | ||
) { | ||
return feature.status; | ||
if (feature.status && feature.compat_features?.includes(bcdKey)) { | ||
return { | ||
featureStatus: feature.status, | ||
keyStatus: computeBaseline({ compatKeys: [bcdKey] }), | ||
}; | ||
} | ||
} | ||
return {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters