Astro Versioned Documentation System
A foundational guide to understanding and setting up the versioned documentation hub using Astro.
Table of Contents
Overview
This documentation system provides:
- Automatic versioning: Support for multiple versions of the same document
- Smart discovery: Automatically finds and organizes markdown files
- Category organization: Directory structure becomes navigation structure
- Responsive design: Mobile-friendly interface with Tailwind CSS
- Zero configuration: Drop markdown files and theyβre automatically processed
Key Features
- π File-based routing - Documents are automatically discovered
- π Version management - Support for
document_v1.md,document_v2.mdnaming - ποΈ Category support - Organize docs in subdirectories
- π¨ Customizable themes - Built with Tailwind CSS
- β‘ Performance optimized - Caching and efficient file scanning
- π± Mobile responsive - Works great on all device sizes
Quick Start
1. Fork and Clone
git clone https://github.com/yourusername/astro-docs-system.git
cd astro-docs-system
npm install
2. Add Your First Document
Create a file at /src/pages/docs/getting-started.md:
# Getting Started
Welcome to your documentation system!
This is your first document.
3. Start Development Server
npm run dev
Visit http://localhost:4321/docs to see your documentation.
Architecture
Core Components
-
Preprocessing Script (
scripts/preprocess-markdown.js)- Runs before dev/build
- Automatically adds layout frontmatter to markdown files
- Calculates correct relative paths
-
Document Utilities (
src/utils/docUtils.ts)- Scans and discovers all documentation files
- Parses version information from filenames
- Provides caching for performance
- Groups documents by category and version
-
Layout System
MarkdownLayout.astro- Wrapper for individual docsDocsLayout.astro- Base layout with navigationMarkdownNav.astro- Version switcher and breadcrumbs
-
Index Page (
src/pages/docs/index.astro)- Overview of all available documentation
- Category organization
- Version selection interface
File Processing Flow
1. Developer adds .md file to /src/pages/docs/
2. preprocess-markdown.js runs (dev/build)
3. Script adds layout frontmatter automatically
4. Astro builds page using MarkdownLayout
5. docUtils.ts scans and categorizes all docs
6. Navigation components show versions/related docs
File Organization
Naming Conventions
Single Documents
/src/pages/docs/
βββ installation.md # Latest version
βββ installation_v1.md # Version 1
βββ installation_v2.md # Version 2
βββ configuration.md # Latest version
Categorized Documents
/src/pages/docs/
βββ api/
β βββ authentication.md # Latest
β βββ authentication_v1.md # Version 1
β βββ endpoints.md # Latest
βββ guides/
β βββ deployment.md # Latest
β βββ troubleshooting.md # Latest
βββ reference/
βββ cli-commands.md # Latest
Version Resolution
The system intelligently resolves document versions:
- Latest Version: Files without
_vXsuffix (e.g.,guide.md) - Specific Versions: Files with
_vXsuffix (e.g.,guide_v1.md,guide_v2.md) - URL Mapping:
/docs/guideβ serves latest version/docs/guide_v1β serves version 1 specifically
Category Structure
Directory structure automatically becomes navigation:
docs/api/authentication.md β Docs β API β Authentication
docs/guides/deployment.md β Docs β Guides β Deployment
docs/configuration.md β Docs β Configuration
This documentation system provides the foundation for a versioned documentation hub. The architecture is designed to be extended with additional features, customizations, and integrations as needed.