Advanced Features
Explore advanced Content Mode features: relations, slug generation, output paths, field validation, and helper functions.
Relations
Relations allow you to link content items across collections, creating powerful content relationships.
What are Relations?
Relations create connections between content items. For example, you can link blog posts to authors, products to categories, or pages to related content.
Configuration
Define relations in your collection configuration:
{
"fields": {
"author": {
"type": "relation",
"collection": "authors",
"valueField": "slug"
}
}
}
Usage in Content
Reference related content by slug in your content files:
---
title: "My Post"
author: "authors/john"
---
Usage in Templates
Relations are automatically resolved to full document objects in templates:
<!-- $doc.author.name -->
<!-- $doc.author.bio -->
<!-- $doc.author.avatar -->
Resolution
Relations are resolved during build time. If a relation reference is broken (the target doesn't exist), you'll get a warning but the build will continue.
Slug Generation
Slugs are automatically generated from titles or filenames, but you can customize this behavior.
Auto-Generation
If you don't specify a slug in your content file's front matter, Hammer automatically generates one from:
- The
titlefield (if present) - The filename (if no title is available)
Customization
Configure slug generation in your collection config:
"slug": {
"field": "title",
"fallback": "filename"
}
Slug Format
Slugs are automatically formatted to be:
- Lowercase
- Hyphens instead of spaces
- Special characters removed
- URL-safe
Uniqueness
Slugs should be unique within a collection. If duplicates exist, Hammer will handle them, but it's best practice to ensure uniqueness.
Output Path Patterns
Output paths use template syntax to create dynamic paths based on content properties.
Dynamic Paths
Use content properties in output paths:
"output": {
"filename": "blog/{{ slug }}/index.html"
}
Pattern Syntax
Available patterns:
-
{{ slug }}- Content slug -
{{ date }}- Publication date -
{{ collection }}- Collection name -
{{ fieldName }}- Any field from front matter
Examples
// Simple slug-based path
"filename": "blog/{{ slug }}/index.html"
// Date-based path
"filename": "posts/{{ date:yyyy }}/{{ date:MM }}/{{ slug }}.html"
// Collection-based path
"filename": "{{ collection }}/{{ slug }}/index.html"
Directory Creation
Hammer automatically creates nested directories as needed for your output paths.
Field Validation
Field validation helps ensure your content structure is correct and consistent.
Required Fields
Define required fields in your collection configuration:
{
"fields": {
"title": {
"type": "string",
"required": true
}
}
}
Type Validation
Field types ensure correct data types:
- String fields must be text
- Number fields must be numeric
- Boolean fields must be true/false
- Date fields must be valid dates
Warnings
Validation warnings are generated for:
- Missing required fields
- Incorrect field types
- Invalid date formats
Build Behavior
Validation warnings don't fail builds. They're logged to help you identify and fix issues, but the build continues.
Helper Functions
Helper functions provide utility functionality for templates.
formatDate
Format dates with custom formats:
<!-- $helpers.formatDate(doc.date) -->
<!-- $helpers.formatDate(doc.date, "dd MMM yyyy") -->
slugify
Generate URL-friendly slugs:
<!-- $helpers.slugify(doc.title) -->
markdown
Convert Markdown to HTML:
<!-- $!helpers.markdown(doc.summary) -->
relativePath
Calculate relative paths between files:
<!-- $helpers.relativePath(doc.slug, "index.html") -->
join
Join array elements with a separator:
<!-- $helpers.join(doc.tags, ", ") -->
default
Provide fallback values:
<!-- $helpers.default(doc.summary, "No summary available") -->
Content Caching
Content Mode uses caching to speed up builds by only re-parsing changed files.
Purpose
Caching improves build performance by:
- Only re-parsing changed content files
- Storing parsed content between builds
- Reducing build time for large sites
Cache Location
Content cache is stored in the build cache directory and is managed automatically by Hammer.
Cache Invalidation
The cache is automatically invalidated when:
- Content files are modified
- Configuration files change
- You perform a clean build
Style Guides
Style guides provide natural language descriptions for AI-assisted authoring.
Purpose
Style guides help AI IDEs (like Cursor) understand your content structure and provide better assistance when creating content.
Usage
Define style guides in your collection configuration:
"styleGuide": "Blog posts should be engaging, informative, and between 500-2000 words. Use clear headings and include examples where helpful."
Integration
Style guides are used by AI tools to:
- Provide context when generating content
- Suggest appropriate content structure
- Help maintain consistency across content
Next Steps
Now that you understand advanced features, explore:
- Workflow Examples to see advanced features in practice
- Best Practices for effective use of advanced features
- Troubleshooting if you encounter issues