|
| 1 | +# Data-driven tables |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +GitHub Docs uses YAML files to manage some complex reference tables instead of hard-to-maintain Markdown tables. This approach provides: |
| 6 | + |
| 7 | +- **Maintainable format**: Stakeholders can easily update readable YAML files |
| 8 | +- **Single source of truth**: Centralized data prevents inconsistencies |
| 9 | +- **Accurate information**: Reduces errors and outdated content |
| 10 | +- **Self-service process**: Minimal engineering support needed |
| 11 | + |
| 12 | +> **Important**: The `.yml` files in this directory are maintained **manually**. Tables that need automatic updates from external sources require engineering work. |
| 13 | +
|
| 14 | +## Table of contents |
| 15 | + |
| 16 | +- [When to use this approach](#when-to-use-this-approach) |
| 17 | +- [How it works](#how-it-works) |
| 18 | +- [Step-by-step guide](#step-by-step-guide) |
| 19 | +- [Testing and validation](#testing-and-validation) |
| 20 | +- [Next steps](#next-steps) |
| 21 | + |
| 22 | +## When to use this approach |
| 23 | + |
| 24 | +Use data-driven tables when you have: |
| 25 | +- Complex reference tables with multiple columns |
| 26 | +- Data that needs regular updates by different stakeholders |
| 27 | +- Structured information that benefits from validation |
| 28 | + |
| 29 | +## How it works |
| 30 | + |
| 31 | +Every data-driven table needs **three files** that work together: |
| 32 | + |
| 33 | +| File type | Location | Purpose | |
| 34 | +|-----------|----------|---------| |
| 35 | +| **Data file** | `data/tables/` | Stores the table content in YAML format | |
| 36 | +| **Content file** | `content/` | Displays the table using Liquid templating | |
| 37 | +| **Schema file** | `src/data-directory/lib/data-schemas/` | Validates the YAML structure | |
| 38 | + |
| 39 | +**Estimated time**: 30-60 minutes for a new table |
| 40 | + |
| 41 | +## Step-by-step guide |
| 42 | + |
| 43 | +### Step 1: Create the data file |
| 44 | + |
| 45 | +Create a new `.yml` file in `data/tables/` with a descriptive name. |
| 46 | + |
| 47 | +**Copilot prompt template:** |
| 48 | +``` |
| 49 | +Create a YAML structure that will allow me to generate a table that looks like: |
| 50 | +[describe your table headers, rows, and columns OR attach an example] |
| 51 | +
|
| 52 | +See src/secret-scanning/data/public-docs.yml for an example. |
| 53 | +``` |
| 54 | + |
| 55 | +### Step 2: Create the content display |
| 56 | + |
| 57 | +In your content file, add Liquid code to render the table. Access your data at `{% data tables.TABLE_NAME %}` (where `TABLE_NAME` is your filename without `.yml`). |
| 58 | + |
| 59 | +**Copilot prompt template:** |
| 60 | +``` |
| 61 | +Create a Markdown table that is dynamically rendered using Liquid code. |
| 62 | +Pull data from data/tables/TABLE_NAME.yml. |
| 63 | +The table should look like: [describe your desired output OR attach an example] |
| 64 | +
|
| 65 | +See content/code-security/secret-scanning/introduction/supported-secret-scanning-patterns.md for an example. |
| 66 | +Liquid docs: https://shopify.github.io/liquid |
| 67 | +``` |
| 68 | + |
| 69 | +**💡 Tip**: Iterate between Steps 1 and 2 until the table renders correctly. |
| 70 | + |
| 71 | +### Step 3: Create the schema file |
| 72 | + |
| 73 | +Create a `.ts` file in `src/data-directory/lib/data-schemas/` with the same name as your YAML file. |
| 74 | + |
| 75 | +**Copilot prompt template:** |
| 76 | +``` |
| 77 | +Create a TypeScript schema following prior art under data-schemas that enforces |
| 78 | +the structure of the data/TABLE_NAME.yml file. |
| 79 | +
|
| 80 | +See src/data-directory/lib/data-schemas/learning-tracks.ts for an example. |
| 81 | +``` |
| 82 | + |
| 83 | +## Testing and validation |
| 84 | + |
| 85 | +After creating all three files: |
| 86 | + |
| 87 | +1. **Build the site**: Run `npm run build` |
| 88 | +2. **Test schemas**: Run `npm test -- src/data-directory/tests` |
| 89 | +3. **Fix any errors**: If you get failures in `src/data-directory/tests/data-schemas.js`: |
| 90 | + - Copy the error message |
| 91 | + - In VS Code Copilot Chat, type: "When I ran the schema test, I got this error:" and paste the error |
| 92 | + - Update your schema file based on Copilot's suggestions |
| 93 | +4. **Repeat testing** until all tests pass |
| 94 | + |
| 95 | +## Next steps |
| 96 | + |
| 97 | +Once your table is working and tests pass, create a pull request for review. |
| 98 | + |
| 99 | +The `docs-engineering` team must review and approve your implementation. |
0 commit comments