A modern, self-hosted content management system built with Astro and Directus CMS. Perfect for documentation sites, blogs, or any content-driven website.
- Astro + Directus Template
- π Chapter-based content with rich text editing
- π Static site generation for optimal performance
- π Self-hosted with complete data ownership
- π Built-in i18n support via Directus
- π¨ Clean, responsive design
- π³ Docker-based deployment
- Astro - Static site generator
- Directus - Headless CMS
- PostgreSQL - Database
- Docker - Containerization
- Node.js 18+ and Yarn
- Docker Desktop (or Docker Engine + Docker Compose)
git clone git@github.com:commoddity/astro_directus.git
cd astro_directus
yarn install# Automatically generate .env with secure keys
yarn env:initThis script (scripts/populate-local-env.sh) will:
- Generate secure random keys for
KEYandSECRET - Create
.envwith all necessary configuration - Set default admin credentials
# Start all services with status monitoring
yarn startThis script (scripts/start-services.sh) will:
- Start Docker services (Directus + PostgreSQL)
- Wait for all services to be ready
- Display service URLs and credentials
- Show helpful next steps
Example output:
π Starting Docker services...
[+] Running 4/4
β Network astro-directus-network Created
β Container postgres Healthy
β Container directus Started
β Container astro Started
β³ Waiting for services to be ready...
ποΈ PostgreSQL... β
Ready
π¨ Directus... β
Ready
π Astro... β
Ready
β
All services are up and running!
π Service URLs:
π Astro Site: http://localhost:4321
π¨ Directus CMS: http://localhost:8055
ποΈ PostgreSQL: localhost:5432
π Default Credentials:
Email: admin@example.com
Password: admin123
π Next to run the setup (if not already done): yarn setup
π‘ To stop the services: yarn stop
π₯ Hot reloading is enabled for Astro!
Open a new terminal and run:
yarn setupThis creates the chapters collection and configures permissions.
Visit http://localhost:8055 and login:
- Email:
admin@example.com - Password:
admin123
π You're ready to add content!
- Login to Directus at http://localhost:8055
- Navigate to Content β Chapters
- Click "+ Create Item"
- Fill in the fields:
- Title: Display name (e.g., "Getting Started")
- Slug: URL-friendly identifier (e.g., "getting-started")
- Order: Number for sorting (1, 2, 3, etc.)
- Content: Your chapter content (see formatting below)
- Images: Optional images (see below)
- Click Save
The chapter will immediately appear on your site at http://localhost:4321/chapters/[slug]
Directus supports rich text and HTML in the content field. You can use:
Use the WYSIWYG editor in Directus:
- Bold, Italic,
Strikethrough - Headings (H2, H3, etc.)
- Bulleted and numbered lists
- Blockquotes
- Code blocks
- Links
You can also write raw HTML for more control:
<h2>Section Title</h2>
<p>This is a paragraph with <strong>bold text</strong>.</p>
<ul>
<li>List item 1</li>
<li>List item 2</li>
</ul>
<blockquote>
This is a quote
</blockquote>
<pre><code>
// Code block
function example() {
return "Hello World";
}
</code></pre>If you prefer Markdown, you can:
- Write in Markdown
- Convert to HTML using a tool like Markdown to HTML
- Paste the HTML into the content field
- In the chapter editor, find the Images field
- Click "+ Add New" or "Select Existing"
- Upload your image(s) or choose from library
- Save the chapter
Images will automatically display below the chapter content.
-
Upload image to Directus:
- Go to File Library in Directus
- Upload your image
- Copy the file ID (visible in the URL or file details)
-
Reference in content:
<img src="http://localhost:8055/assets/[FILE_ID]" alt="Description" />
Or use the WYSIWYG editor's image insert button.
- File formats: Use JPEG for photos, PNG for graphics with transparency
- Size: Resize large images before upload (recommended max width: 1200px)
- Alt text: Always include descriptive alt text for accessibility
- File names: Use descriptive names (e.g.,
chapter-1-diagram.png)
Chapters are sorted by the Order field:
- Set
Order: 1for the first chapter - Set
Order: 2for the second, etc. - Navigation between chapters respects this order
astro_directus/
βββ src/
β βββ pages/
β β βββ index.astro # Homepage
β β βββ chapters/
β β βββ index.astro # All chapters list
β β βββ [slug].astro # Individual chapter page
β βββ lib/
β βββ directus.ts # Directus API client
βββ public/
β βββ favicon.svg # Site favicon
βββ scripts/
β βββ populate-local-env.sh # Generate .env with secure keys
β βββ start-services.sh # Start all services with monitoring
β βββ stop-services.sh # Stop all services
β βββ setup-directus.sh # Directus schema setup automation
βββ tmp/ # Docker volumes (gitignored)
β βββ uploads/ # Directus uploaded files
β βββ data/ # PostgreSQL database
βββ .env # Environment config (gitignored)
βββ .env.example # Environment template
βββ docker-compose.yml # Docker services config
βββ astro.config.mjs # Astro configuration
βββ package.json # Dependencies & scripts
βββ tsconfig.json # TypeScript config
Key variables in .env:
| Variable | Description | Default |
|---|---|---|
KEY |
Directus encryption key | (generate with openssl) |
SECRET |
Directus session secret | (generate with openssl) |
ADMIN_EMAIL |
Initial admin email | admin@example.com |
ADMIN_PASSWORD |
Initial admin password | admin123 |
PUBLIC_DIRECTUS_URL |
Directus API URL | http://localhost:8055 |
DB_DATABASE |
Database name | directus |
DB_USER |
Database user | directus |
DB_PASSWORD |
Database password | directus |