Writing Documentation
Contributing to Sayr’s documentation is one of the easiest ways to help the project. You can edit docs directly on GitHub without cloning the repository or setting up a local environment.
Quick Start: Edit on GitHub
Section titled “Quick Start: Edit on GitHub”Every documentation page has an “Edit page” link at the bottom. Click it to:
- Fork the repository (if you haven’t already)
- Edit the file directly in GitHub’s web editor
- Submit a pull request with your changes
That’s it! No local setup required.
How the Docs Work
Section titled “How the Docs Work”Sayr’s documentation is built with Starlight, a documentation theme for Astro. It transforms Markdown files into a beautiful documentation site.
Key Features
Section titled “Key Features”- Markdown/MDX — Write in standard Markdown with optional MDX for React components
- Automatic navigation — Sidebar generated from file structure
- Code highlighting — Syntax highlighting with Expressive Code
- Last updated dates — Automatically tracked via Git history
- Edit links — Direct links to edit any page on GitHub
File Structure
Section titled “File Structure”Documentation lives in the marketing app:
apps/marketing/├── src/│ ├── content/│ │ └── docs/│ │ └── docs/ # All documentation pages│ │ ├── index.md # Homepage (/docs)│ │ ├── quick-start.md│ │ ├── api/│ │ │ ├── overview.md│ │ │ ├── ws.mdx│ │ │ └── reference.mdx│ │ ├── guides/│ │ │ └── visibility.md│ │ ├── self-hosting/│ │ │ └── railway.md│ │ └── contributing/│ │ ├── local-development.mdx│ │ ├── architecture.md│ │ └── ...│ └── assets/│ └── logo.svg└── astro.config.mjs # Sidebar and site configURL Mapping
Section titled “URL Mapping”Files map to URLs as follows:
| File Path | URL |
|---|---|
docs/index.md | /docs |
docs/quick-start.md | /docs/quick-start |
docs/api/overview.md | /docs/api/overview |
docs/guides/visibility.md | /docs/guides/visibility |
Creating a New Page
Section titled “Creating a New Page”1. Choose the Right Location
Section titled “1. Choose the Right Location”| Content Type | Location | Example |
|---|---|---|
| User guides | docs/guides/ | Feature tutorials, how-tos |
| API documentation | docs/api/ | Endpoints, WebSocket events |
| Self-hosting | docs/self-hosting/ | Deployment guides |
| Contributing | docs/contributing/ | Developer documentation |
2. Create the File
Section titled “2. Create the File”Create a new .md or .mdx file with frontmatter:
---title: Your Page Titledescription: A brief description for SEO and previews---
Your content here...Frontmatter Reference
Section titled “Frontmatter Reference”Every documentation page starts with YAML frontmatter:
---title: Page Title # Required - shown in sidebar and page headerdescription: Brief description # Required - used for SEO meta tagssidebar: order: 1 # Optional - controls sidebar position label: Custom Label # Optional - override sidebar text badge: New # Optional - add a badge (New, Beta, etc.) hidden: false # Optional - hide from sidebar---Writing Style Guide
Section titled “Writing Style Guide”Tone and Voice
Section titled “Tone and Voice”- Be direct — Get to the point quickly
- Be practical — Focus on what users need to do
- Be inclusive — Avoid jargon; explain technical terms
- Use “you” — Address the reader directly
Structure
Section titled “Structure”- Start with the goal — What will readers accomplish?
- Show, don’t just tell — Include code examples
- Use headings liberally — Make content scannable
- Keep paragraphs short — 2-4 sentences max
Formatting Conventions
Section titled “Formatting Conventions”| Element | Convention |
|---|---|
| File paths | Backticks: `apps/marketing/` |
| Commands | Code blocks with bash language |
| UI elements | Bold: Click Save |
| Keyboard shortcuts | Cmd/Ctrl + S |
| Variables/placeholders | {placeholder} or <placeholder> |
Code Blocks
Section titled “Code Blocks”Always specify the language for syntax highlighting:
```typescriptconst example = "highlighted code";```For terminal commands:
```bashpnpm dev```Callouts
Section titled “Callouts”Starlight supports callout boxes for important information:
:::noteHelpful additional information.:::
:::tipSuggestions for best practices.:::
:::cautionImportant warnings about potential issues.:::
:::dangerCritical warnings about destructive actions.:::These render as styled boxes:
Tables
Section titled “Tables”Use tables for structured information:
| Column 1 | Column 2 | Column 3 ||----------|----------|----------|| Data | Data | Data |These render as styled tables:
| Column 1 | Column 2 | Column 3 |
|---|---|---|
| Data | Data | Data |
-
Internal links: Use relative paths starting with
/docs/See the [Architecture Overview](/docs/contributing/architecture) -
External links: Use full URLs
Learn more at [Starlight docs](https://starlight.astro.build/)
Using MDX
Section titled “Using MDX”For pages that need React components, use .mdx extension:
---title: Interactive Page---
import { MyComponent } from '../../components/MyComponent';
Regular markdown content...
<MyComponent prop="value" />
More markdown...Configuration
Section titled “Configuration”The sidebar uses starlight-sidebar-topics to create separate navigation topics. Configuration is in apps/marketing/astro.config.mjs:
starlightSidebarTopics([ { label: "Documentation", link: "/docs/", icon: "open-book", id: "docs", items: [ { label: "Getting Started", items: [ { label: "Introduction", slug: "docs" }, { label: "Quick Start", slug: "docs/quick-start" }, ], }, { label: "Guides", autogenerate: { directory: "/docs/guides" }, }, // ... ], }, { label: "Contributing", link: "/docs/contributing/local-development/", icon: "github", id: "contributing", items: [ // Contributing navigation items... ], },]),Configuration Options
Section titled “Configuration Options”- Manual items: Explicitly listed pages with
{ label, slug } - Autogenerate: Automatically includes all pages in a directory
- Topics: Separate top-level navigation tabs (Documentation, Contributing)
Local Preview
Section titled “Local Preview”To preview documentation changes locally:
# From repository rootpnpm -F marketing dev
# Opens at http://localhost:3002Checklist Before Submitting
Section titled “Checklist Before Submitting”- Frontmatter includes
titleanddescription - Content follows the writing style guide
- Code blocks have language specified
- Links use correct paths (internal:
/docs/..., external: full URL) - Images have alt text (if any)
- Page renders correctly in local preview (if testing locally)
Automatic Page Metadata
Section titled “Automatic Page Metadata”Every documentation page displays metadata that’s automatically populated from Git history.
Author
Section titled “Author”The author is the person who created the file (made the first commit). Their GitHub avatar and linked username appear below the page title.
Contributors
Section titled “Contributors”Contributors are anyone who has committed changes to the file after the initial creation. They appear as a row of avatars, linking to their GitHub profiles.
Last Updated
Section titled “Last Updated”The last updated date reflects when the file was last modified, based on the most recent Git commit that touched the file.
How It Works
Section titled “How It Works”The metadata is populated through a build-time pre-computation system that extracts Git history during the build process.
Build Time Process:
- An Astro integration (
apps/marketing/src/integrations/precompute-contributors.ts) runs duringpnpm run build - It scans all documentation files in
src/content/docs/ - For each file, it executes
git log --followto retrieve the complete commit history - Author data is extracted from the oldest commit (file creation)
- Contributor data is aggregated from all subsequent commits
- For each contributor with a GitHub username, profile data (avatar URL, profile link) is fetched from GitHub’s API
- All metadata (including GitHub avatars) is written to
src/data/contributors.json - This JSON file is committed to the repository and copied to
dist/server/data/anddist/client/data/during builds
Runtime Process:
- Route middleware (
apps/marketing/src/routeData/contributors.ts) loads the pre-computed JSON at server startup - For each page request, it looks up the file path in the cached contributor data
- Metadata is attached to the route context with all GitHub data already included
- The
PageTitlecomponent renders the author, contributors, and last updated information using pre-fetched avatars
Email-to-GitHub Mapping:
The system extracts GitHub usernames using two methods:
- GitHub noreply emails: Automatically parsed from formats like
[email protected]or[email protected] - Manual mapping: Custom emails (like
[email protected]) are mapped to GitHub usernames in the integration’sEMAIL_TO_GITHUBconfiguration
Once a GitHub username is identified, the build process fetches the user’s avatar URL and profile link from GitHub’s API. This data is stored in contributors.json, eliminating the need for any runtime API calls.
Related Resources
Section titled “Related Resources”- Starlight Documentation — Full Starlight reference
- Markdown Guide — Markdown syntax reference
- Pull Request Guidelines — How to submit your changes