# qsgen3 Themes How-To Guide
This guide explains how to create and customize themes for qsgen3, based on how the code actually interprets and processes themes.
## Table of Contents
1. [Theme Basics](#theme-basics)
2. [Theme Directory Structure](#theme-directory-structure)
3. [Creating Your First Theme](#creating-your-first-theme)
4. [Layout Templates](#layout-templates)
5. [Static Assets (CSS, JS, Images)](#static-assets-css-js-images)
6. [Theme Configuration](#theme-configuration)
7. [Advanced Theme Features](#advanced-theme-features)
8. [Theme Best Practices](#theme-best-practices)
9. [Troubleshooting](#troubleshooting)
## Theme Basics
### What is a Theme?
A qsgen3 theme is a collection of layout templates and static assets (CSS, JavaScript, images) that define the visual appearance and structure of your generated website. Themes allow you to:
- Customize the HTML structure of your pages
- Apply custom CSS styling
- Include JavaScript functionality
- Override default layouts with theme-specific designs
### How qsgen3 Processes Themes
When you specify a theme in your `site.conf`, qsgen3 follows this processing order:
1. **Theme Detection**: Looks for the theme directory at `themes/{theme_name}/`
2. **Layout Override**: If the theme has a `layouts/` directory, it **completely replaces** the default layouts
3. **Static File Copying**: Copies static files from both root `static/` and theme `static/` directories
4. **CSS Linking**: Automatically links the theme's main CSS file in generated HTML
**Important**: When a theme provides layouts, qsgen3 uses **only** the theme's layouts. There is no fallback to default layouts for individual templates. If you want to use a theme, ensure it provides all necessary layout files (`index.html`, `post.html`, `page.html`, `rss.xml`).
### Included Example Theme
qsgen3 includes a `minimal` theme that demonstrates the proper theme structure:
```
themes/minimal/
├── layouts/ # Complete set of templates
│ ├── index.html # Homepage layout
│ ├── post.html # Blog post layout
│ ├── page.html # Static page layout
│ └── rss.xml # RSS feed template
├── static/ # Theme assets
│ └── css/
│ └── style.css # Clean, minimal styling
└── README.md # Theme documentation
```
To use the minimal theme:
1. Set `site_theme="minimal"` in your `site.conf`
2. Set `site_theme_css_file="css/style.css"`
3. Run `./bin/qsgen3`
## Theme Directory Structure
### Standard Theme Structure
```
themes/
└── your-theme-name/
├── layouts/ # Optional: Custom layout templates
│ ├── index.html # Homepage layout (overrides default)
│ ├── post.html # Blog post layout (overrides default)
│ ├── page.html # Static page layout (overrides default)
│ └── rss.xml # RSS feed template (overrides default)
└── static/ # Theme's static assets
├── css/
│ └── style.css # Main theme CSS
├── js/
│ └── theme.js # Theme JavaScript
└── images/
└── logo.png # Theme images
```
**Important**: By default, qsgen3 uses the `layouts/` directory in your project root (as specified by `paths_layouts_dir` in `site.conf`). When a theme provides its own `layouts/` directory, it completely overrides the default layouts directory.
### Alternative Structure (Legacy Support)
For themes that don't use the `static/` subdirectory:
```
themes/
└── your-theme-name/
├── layouts/ # Optional: Custom layout templates
├── css/ # CSS files directly in theme root
│ └── style.css
├── js/ # JavaScript files
└── images/ # Image files
```
### How Layout Override Works
1. **Default**: qsgen3 uses templates from your project's `layouts/` directory (configurable via `paths_layouts_dir`)
2. **Theme Override**: If `themes/your-theme/layouts/` exists, qsgen3 uses **only** those templates
3. **No Fallback**: If a theme provides layouts, there is no fallback to default layouts. The theme must provide all required templates.
**Note**: The project root `layouts/` directory serves as default templates for projects not using themes, or as a fallback when no theme is specified.
## Creating Your First Theme
### Step 1: Create the Theme Directory
```bash
mkdir -p themes/my-theme/static/css
mkdir -p themes/my-theme/static/js
mkdir -p themes/my-theme/layouts
```
### Step 2: Create a Basic CSS File
Create `themes/my-theme/static/css/style.css`:
```css
/* Basic theme styles */
body {
font-family: 'Arial', sans-serif;
line-height: 1.6;
margin: 0;
padding: 0;
background-color: #f4f4f4;
}
header {
background: #333;
color: white;
padding: 1rem;
text-align: center;
}
header h1 a {
color: white;
text-decoration: none;
}
main {
max-width: 800px;
margin: 2rem auto;
padding: 0 1rem;
background: white;
border-radius: 8px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
article {
padding: 2rem;
}
footer {
text-align: center;
padding: 1rem;
background: #333;
color: white;
margin-top: 2rem;
}
```
### Step 3: Configure Your Site
Update your `site.conf`:
```bash
# Theme configuration
site_theme="my-theme"
site_theme_css_file="css/style.css"
```
### Step 4: Test Your Theme
```bash
./bin/qsgen3
```
Your site should now use your custom theme!
## Layout Templates
### Understanding Pandoc Templates
qsgen3 uses Pandoc templates with special variable syntax:
- `$variable$` - Simple variable substitution
- `$if(variable)$...$endif$` - Conditional blocks
- `$for(list)$...$endfor$` - Loop over lists
- `$body$` - The main content (converted from Markdown)
### Available Variables
#### Site-wide Variables (from site.conf)
- `$site_name$` - Your site's name
- `$site_tagline$` - Your site's tagline
- `$site_url$` - Your site's URL
- `$current_year$` - Current year (auto-generated)
#### Content Variables (from Markdown frontmatter)
- `$title$` - Page/post title
- `$author$` - Content author
- `$date$` - Publication date
- `$description$` - Page description
- `$body$` - The converted Markdown content
#### Special Variables
- `$css$` - CSS file paths (handled automatically)
- `$math$` - Math rendering support (if enabled)
### Creating Custom Layouts
#### Basic Post Layout (`layouts/post.html`)
```html
```
### 4. Configure Site (`site.conf`)
```bash
site_theme="modern-blog"
site_theme_css_file="css/style.css"
```
### 5. Generate Site
```bash
./bin/qsgen3
```
Your modern, responsive blog theme is now ready!
---
## Summary
This guide covers everything you need to know about creating themes for qsgen3. Key points to remember:
1. **Complete Override**: When a theme provides layouts, it completely replaces default layouts
2. **No Partial Fallback**: Themes must provide all necessary templates (`index.html`, `post.html`, `page.html`, `rss.xml`)
3. **Static File Merging**: Theme static files are copied after root static files, allowing themes to override default assets
4. **CSS Automation**: The main theme CSS file is automatically linked in generated HTML
Understanding this processing flow is key to creating effective themes that work reliably across different configurations.