mirror of
https://github.com/zmkfirmware/zmk.git
synced 2026-03-26 07:55:17 -05:00
feat(docs): Add TOC to supported hardware page.
This commit is contained in:
committed by
Pete Johanson
parent
158ac27207
commit
c8c273d83b
70
docs/src/components/hardware-utils.ts
Normal file
70
docs/src/components/hardware-utils.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
import {
|
||||
Board,
|
||||
HardwareMetadata,
|
||||
Interconnect,
|
||||
Shield,
|
||||
} from "../hardware-metadata";
|
||||
|
||||
export interface InterconnectDetails {
|
||||
interconnect?: Interconnect;
|
||||
boards: Board[];
|
||||
shields: Shield[];
|
||||
}
|
||||
|
||||
export interface GroupedMetadata {
|
||||
onboard: Board[];
|
||||
interconnects: Record<string, InterconnectDetails>;
|
||||
}
|
||||
|
||||
function groupedBoard(agg: GroupedMetadata, board: Board) {
|
||||
if (board.features?.includes("keys")) {
|
||||
agg.onboard.push(board);
|
||||
} else if (board.exposes) {
|
||||
board.exposes.forEach((element) => {
|
||||
let ic = agg.interconnects[element] ?? {
|
||||
boards: [],
|
||||
shields: [],
|
||||
};
|
||||
ic.boards.push(board);
|
||||
agg.interconnects[element] = ic;
|
||||
});
|
||||
} else {
|
||||
console.error("Board without keys or interconnect");
|
||||
}
|
||||
|
||||
return agg;
|
||||
}
|
||||
|
||||
function groupedShield(agg: GroupedMetadata, shield: Shield) {
|
||||
shield.requires.forEach((id) => {
|
||||
let ic = agg.interconnects[id] ?? { boards: [], shields: [] };
|
||||
ic.shields.push(shield);
|
||||
agg.interconnects[id] = ic;
|
||||
});
|
||||
|
||||
return agg;
|
||||
}
|
||||
|
||||
function groupedInterconnect(agg: GroupedMetadata, item: Interconnect) {
|
||||
let ic = agg.interconnects[item.id] ?? { boards: [], shields: [] };
|
||||
ic.interconnect = item;
|
||||
agg.interconnects[item.id] = ic;
|
||||
|
||||
return agg;
|
||||
}
|
||||
|
||||
export function groupedMetadata(items: HardwareMetadata[]) {
|
||||
return items.reduce<GroupedMetadata>(
|
||||
(agg, hm) => {
|
||||
switch (hm.type) {
|
||||
case "board":
|
||||
return groupedBoard(agg, hm);
|
||||
case "shield":
|
||||
return groupedShield(agg, hm);
|
||||
case "interconnect":
|
||||
return groupedInterconnect(agg, hm);
|
||||
}
|
||||
},
|
||||
{ onboard: [] as Board[], interconnects: {} }
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user