Skip to content

Commit 6b15ee2

Browse files
Add color coding to the to standards table in the docs page (#211)
* Added the color mapping with a react component. Needed to change the overview.md file to .mdx format. Contrast ratio was respected.
1 parent 384b6a8 commit 6b15ee2

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
/docs/06-releases
1717
/standards/*.md
1818
/standards/*/*.md
19+
/standards/*/*.mdx
1920
/standards/scs-*.yaml
2021

2122
# Dependencies

populateStds.js

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,42 @@ const trackIntros = {
1515
}
1616
const headerLegend = '*Legend to the column headings: Draft, Stable (but not effective), Effective, Deprecated (and no longer effective).'
1717

18+
const reactHighlightTableCellBackground = `
19+
import { useEffect } from 'react';
20+
export const TableCellStyleApplier = () => {
21+
// apply background color based on cell index
22+
const colorMapping = {
23+
3: '#FBFDE2', // draft
24+
4: '#E4FDE2', // stable
25+
5: '#E2EAFD', // effective
26+
6: '#FDE2E2' // deprecated
27+
};
28+
29+
30+
useEffect(() => {
31+
const divElement = document.querySelector('#color-table-cells');
32+
if (divElement) {
33+
// the next sibling of that element should be our table
34+
const tableElement = divElement.nextElementSibling;
35+
if (tableElement && tableElement.tagName.toLowerCase() === 'table') {
36+
tableElement.querySelectorAll('tbody tr').forEach((row) => {
37+
row.querySelectorAll('td').forEach((cell, index) => {
38+
// apply background for all cells that have more content than '-'
39+
if (colorMapping[index] && cell.textContent.trim() !== '-') {
40+
cell.style.backgroundColor = colorMapping[index];
41+
}
42+
});
43+
});
44+
}
45+
}
46+
}, []);
47+
48+
return null;
49+
};
50+
51+
<TableCellStyleApplier />
52+
`
53+
1854
var filenames = fs
1955
.readdirSync('standards/')
2056
.filter((fn) => fn.startsWith('scs-') && fn.endsWith('.md') && !fn.startsWith('scs-X'))
@@ -77,11 +113,13 @@ function mkLinkList(versions) {
77113
// walk down the hierarchy, building adr overview pages, track overview pages, and total overview page
78114
// as well as the new sidebar
79115
sidebarItems = []
80-
var lines = readPrefixLines('standards/standards/overview.md')
116+
var lines = readPrefixLines('standards/standards/overview.mdx')
81117
if (!lines.length) lines.push(`${intro}
82118
83119
${headerLegend}
120+
${reactHighlightTableCellBackground}
84121
`)
122+
lines.push('<div id="color-table-cells" />') // used to find the sibling table for color encoded background
85123
lines.push('| Standard | Track | Description | Draft | Stable* | Effective | Deprecated* |')
86124
lines.push('| --------- | ------ | ------------ | ----- | ------- | --------- | ----------- |')
87125
Object.entries(tracks).forEach((trackEntry) => {
@@ -185,7 +223,7 @@ ${headerLegend}
185223
fs.writeFileSync(`${trackPath}/index.md`, tlines.join('\n'), 'utf8')
186224
})
187225
lines.push('') // file should end with a single newline character
188-
fs.writeFileSync(`standards/standards/overview.md`, lines.join('\n'), 'utf8')
226+
fs.writeFileSync(`standards/standards/overview.mdx`, lines.join('\n'), 'utf8')
189227

190228
var newSidebars = `module.exports = ${JSON.stringify(sidebarItems, null, ' ')}`
191229
fs.writeFileSync('./sidebarsStandardsItems.js', newSidebars, 'utf8')

standards/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ In addition, SCS provides a certification framework that enables these providers
66

77
![Alt text](image.png)
88

9-
Learn more about these scopes as well as the currently certified clouds under [Certification](certification/overview.md). More details on individual standards can be found under [Standards](standards/overview.md).
9+
Learn more about these scopes as well as the currently certified clouds under [Certification](certification/overview.md). More details on individual standards can be found under [Standards](standards/overview.mdx).

0 commit comments

Comments
 (0)