Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Components documentation improvements #2121

Merged
merged 39 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
277bcd6
docs: add using components guide
HiDeoo Jul 10, 2024
968077b
docs: add tabs component reference
HiDeoo Jul 10, 2024
c9dacee
docs: add badge component reference
HiDeoo Jul 10, 2024
36021e8
docs: update badge component reference
HiDeoo Aug 2, 2024
4d23e0c
docs: update tabs component reference
HiDeoo Aug 2, 2024
d8bd18d
docs: add asides component reference
HiDeoo Aug 2, 2024
35e1fa8
docs: add cards component reference
HiDeoo Aug 2, 2024
2dd642b
docs: add link cards component reference
HiDeoo Aug 2, 2024
61f14b5
docs: add card grids component reference
HiDeoo Aug 2, 2024
0c4fbe8
docs: add code component reference
HiDeoo Aug 2, 2024
5034465
docs: add file tree component reference
HiDeoo Aug 2, 2024
e9a94ac
docs: add steps component reference
HiDeoo Aug 2, 2024
67144f6
docs: add icons component reference
HiDeoo Aug 2, 2024
3229ea6
docs: add icons reference page
HiDeoo Aug 2, 2024
ea2fa02
Merge branch 'main' into hd-feat-docs-components
HiDeoo Aug 19, 2024
93d24be
docs: update tabs `syncKey` with persistence
HiDeoo Aug 19, 2024
96d398b
docs: add link button component reference
HiDeoo Aug 19, 2024
c75bc4d
docs: add markdoc grammar
HiDeoo Sep 6, 2024
1b3e216
docs: add markdoc examples
HiDeoo Sep 6, 2024
1ac47f1
Merge branch 'main' into hd-feat-docs-components
HiDeoo Sep 7, 2024
d2afef9
docs: apply suggestions
HiDeoo Sep 16, 2024
fc3e60b
refactor: use `import` for markdoc grammar
HiDeoo Sep 16, 2024
d4a0a51
feat: tweak component preview UI
HiDeoo Sep 16, 2024
99d5036
feat: remove old `icons-list` component
HiDeoo Sep 16, 2024
32c02ed
docs: remove old components guide
HiDeoo Sep 16, 2024
6584e1c
fix: ignore markdoc grammar type
HiDeoo Sep 16, 2024
0d57e9e
docs: remove most example filenames
HiDeoo Sep 16, 2024
a213827
Merge branch 'main' into hd-feat-docs-components
HiDeoo Sep 16, 2024
133ca46
docs: fix broken fallback content links
HiDeoo Sep 16, 2024
8032a5d
fix: markdoc grammar type
HiDeoo Sep 17, 2024
2bcb756
feat: add netlify redirect
HiDeoo Sep 17, 2024
47ea951
fix: add netlify root language redirect
HiDeoo Sep 17, 2024
d4fd0b3
docs: delete old components guide translations
HiDeoo Sep 17, 2024
c15c7fe
fix: example highlighted lines
HiDeoo Sep 17, 2024
a870d0f
docs: tweak available components sidebar sentence
HiDeoo Sep 17, 2024
087b09f
Merge branch 'main' into hd-feat-docs-components
HiDeoo Sep 18, 2024
bedbc1c
feat: add `component.preview` ui label
HiDeoo Sep 18, 2024
1873562
Merge branch 'main' into hd-feat-docs-components
HiDeoo Sep 18, 2024
1f61a1c
Merge branch 'main' into hd-feat-docs-components
HiDeoo Sep 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineConfig } from 'astro/config';
import starlight from '@astrojs/starlight';
import starlightLinksValidator from 'starlight-links-validator';
import markdocGrammar from './grammars/markdoc.tmLanguage.json';

export const locales = {
root: { label: 'English', lang: 'en' },
Expand Down Expand Up @@ -130,6 +131,13 @@ export default defineConfig({
},
autogenerate: { directory: 'guides' },
},
{
label: 'Components',
translations: {
fr: 'Composants',
},
autogenerate: { directory: 'components' },
},
{
label: 'Reference',
translations: {
Expand Down Expand Up @@ -162,6 +170,7 @@ export default defineConfig({
autogenerate: { directory: 'resources' },
},
],
expressiveCode: { shiki: { langs: [markdocGrammar] } },
plugins: process.env.CHECK_LINKS
? [
starlightLinksValidator({
Expand Down
34 changes: 34 additions & 0 deletions docs/grammars/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Starlight Docs Grammars

This directory contains additional grammars for the Starlight documentation website.

## Grammars

The following additional grammars are generated and available for use:

- [Markdoc](https://github.com/markdoc/language-server)

## Usage

To generate the grammars from their source files, run:

```sh
pnpm grammars
```

To include the grammars in the Starlight documentation website, update the `expressiveCode.shiki.langs` array in the `astro.config.mjs` file:

```diff
starlight({
expressiveCode: {
shiki: {
langs: [
JSON.parse(
fs.readFileSync('./grammars/existing.tmLanguage.json', 'utf-8'),
+ fs.readFileSync('./grammars/new.tmLanguage.json', 'utf-8'),
),
],
},
},
});
```
74 changes: 74 additions & 0 deletions docs/grammars/generate.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// @ts-check

import fs from 'node:fs/promises';

const markdown = {
repo: 'shikijs/textmate-grammars-themes',
tmLanguagePath: 'packages/tm-grammars/grammars/markdown.json',
};

const markdoc = {
repo: 'markdoc/language-server',
// We don't need the Markdoc grammar, only the Markdoc Markdown grammar.
// tmLanguagePath: 'syntaxes/markdoc.tmLanguage.json',
markdownTmLanguagePath: 'syntaxes/markdoc.markdown.tmLanguage.json',
};

/**
* Download a TextMate grammar file from a GitHub repository.
* @param {string} repo
* @param {string} path
*/
async function fetchTmLanguage(repo, path) {
const url = `https://raw.githubusercontent.com/${repo}/main/${path}`;
const response = await fetch(url);
const data = await response.json();
return data;
}

// Download the TextMate grammar files for Markdown.
const markdownTmLanguage = await fetchTmLanguage(markdown.repo, markdown.tmLanguagePath);

// Download the TextMate grammar files for Markdoc Markdown.
const markdocMarkdownTmLanguage = await fetchTmLanguage(
markdoc.repo,
markdoc.markdownTmLanguagePath
);

// Reference: https://macromates.com/manual/en/language_grammars

// Update the name and scope name for the Markdoc grammar.
markdownTmLanguage.name = 'markdoc';
markdownTmLanguage.scopeName = 'text.html.markdoc';

// Merge the Markdown and Markdoc Markdown grammar repositories.
markdownTmLanguage.repository = {
...markdownTmLanguage.repository,
...markdocMarkdownTmLanguage.repository,
};

// Include the Markdoc Markdown grammar rules at the beginning of the Markdown grammar.
for (const rule of Object.keys(markdocMarkdownTmLanguage.repository)) {
// Skip shortcut rules as they break syntax highlighting of child content that includes dots in
// words and we don't ever use them.
if (rule === 'shortcut') continue;

markdownTmLanguage.repository.block.patterns.unshift({ include: `#${rule}` });
markdownTmLanguage.repository.inline.patterns.unshift({ include: `#${rule}` });
}

// Write the grammar to a file.
await fs.writeFile(
'./grammars/markdoc.tmLanguage.json',
JSON.stringify(
markdownTmLanguage,
(key, value) => {
// The `applyEndPatternLast` property should be a boolean and not a number.
if (key === 'applyEndPatternLast') return Boolean(value);
return value;
},
2
)
);

console.log('Markdoc grammar generated successfully.');
Loading
Loading