Open RichardHightower opened 4 days ago
In the past I used https://gohugo.io/
Allow users to switch between pre-configured Hugo themes while maintaining consistent content structure.
# themes_config.yaml
themes:
docsy:
name: "docsy"
repo: "https://github.com/google/docsy.git"
config_template: "docsy_config.toml"
dependencies:
- postcss-cli
- autoprefixer
papermod:
name: "PaperMod"
repo: "https://github.com/adityatelange/hugo-PaperMod.git"
config_template: "papermod_config.toml"
# List available themes
hugo-site theme list
# Switch themes
hugo-site theme switch --name docsy
# Install new theme
hugo-site theme add --name mytheme --repo URL
website-generator/
├── themes/
│ ├── configs/ # Theme-specific config templates
│ │ ├── docsy.toml
│ │ └── papermod.toml
│ └── patches/ # Theme-specific fixes/customizations
└── scripts/
└── theme_manager.py
Tool to create and manage Hugo shortcodes for common documentation patterns.
# shortcodes_config.yaml
shortcodes:
note:
template: "note.html"
params:
- type: [info, warning, danger]
- title
api:
template: "api.html"
params:
- method: [GET, POST, PUT, DELETE]
- endpoint
- response_type
{{< note type="warning" title="Important" >}}
This is a warning message
{{< /note >}}
{{< api method="GET" endpoint="/users" response_type="json" >}}
shortcodes/
├── templates/ # Shortcode HTML templates
├── examples/ # Usage examples
└── generator.py # Shortcode generation script
Automatically generate Hugo taxonomies from content analysis.
# taxonomy_config.yaml
analyzers:
tech_stack:
patterns:
- "uses (.*?) for"
- "built with (.*?)"
status:
patterns:
- "Status: (.*?)"
allowed_values:
- "Draft"
- "Review"
- "Published"
# Generated taxonomy config
[taxonomies]
tech_stack = "tech_stacks"
status = "statuses"
category = "categories"
taxonomy/
├── patterns/ # Taxonomy detection patterns
├── blacklist/ # Terms to ignore
└── analyzer.py # Content analysis script
Support for multiple language versions of documentation with automated translation workflows.
# i18n_config.yaml
languages:
es:
name: "Spanish"
weight: 1
translator: "deepl" # Translation service to use
fr:
name: "French"
weight: 2
translator: "google"
i18n/
├── languages/ # Language-specific configurations
├── translations/ # Translation memory/cache
├── glossary/ # Technical term translations
└── translator.py # Translation management script
# Add new language
hugo-site lang add --code es
# Update translations
hugo-site lang sync --code es
# Generate language switcher
hugo-site lang menu
Generate PDF versions of documentation with customizable layouts and styling.
# pdf_config.yaml
pdf:
layouts:
default:
page_size: "A4"
margins: "2cm"
fonts:
heading: "Roboto"
body: "OpenSans"
print:
page_size: "Letter"
margins: "1inch"
include_toc: true
metadata:
author: "Documentation Team"
subject: "Technical Documentation"
keywords: "docs, technical, api"
pdf/
├── templates/ # PDF layout templates
├── styles/ # PDF-specific CSS
├── assets/ # PDF-specific images/logos
└── generator.py # PDF generation script
# Generate PDF for all content
hugo-site pdf generate
# Generate PDF for specific section
hugo-site pdf generate --section api
# Use specific layout
hugo-site pdf generate --layout print
class FeatureConfig:
def __init__(self, config_path: Path):
self.config = self._load_yaml(config_path)
self.validate_config()
def validate_config(self):
"""Validate feature-specific configuration"""
def add_feature_commands(subparsers):
"""Add feature-specific commands to CLI"""
feature_parser = subparsers.add_parser('feature_name')
feature_parser.add_argument('--option', help='Feature option')
class FeatureError(Exception):
"""Base class for feature-specific errors"""
pass
def handle_feature_error(func):
"""Decorator for feature error handling"""
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except FeatureError as e:
logging.error(f"Feature error: {e}")
raise
return wrapper
def setup_feature_logging(feature_name: str):
"""Setup feature-specific logging"""
logger = logging.getLogger(feature_name)
handler = logging.FileHandler(f"{feature_name}.log")
logger.addHandler(handler)
Would you like me to elaborate on any of these features or create a detailed implementation plan for any specific one?
A tool that takes Hugo's generated HTML output and creates PDFs using WeasyPrint or alternative PDF engines. The tool will maintain Hugo's styling and structure while creating print-ready documentation.
pdf-generator/
├── config/
│ ├── pdf_config.yaml # PDF generation settings
│ └── print_styles.css # Print-specific CSS
├── templates/
│ ├── cover.html # PDF cover page template
│ └── footer.html # PDF footer template
├── output/
│ └── pdfs/ # Generated PDFs
└── scripts/
├── pdf_generator.py # Main generation script
└── toc_generator.py # TOC processing script
# pdf_config.yaml
output:
path: "output/pdfs"
filename_template: "{title}-{date}"
pdf:
page_size: "A4"
margins:
top: "25mm"
right: "25mm"
bottom: "25mm"
left: "25mm"
fonts:
default: "DejaVu Sans"
code: "DejaVu Sans Mono"
headers:
include: true
height: "15mm"
footers:
include: true
height: "15mm"
page_numbers: true
sections:
- name: "full"
title: "Complete Documentation"
content: "/**/*.html"
- name: "api"
title: "API Documentation"
content: "/api/**/*.html"
/* print_styles.css */
@media print {
@page {
size: A4;
margin: 25mm;
@top-center {
content: string(doctitle);
}
@bottom-right {
content: counter(page);
}
}
/* Hide navigation and UI elements */
nav, .sidebar, .breadcrumbs {
display: none !important;
}
/* Ensure code blocks don't break across pages */
pre {
page-break-inside: avoid;
}
/* Add QR code to link back to online version */
a[href^="http"]:after {
content: " (URL: " attr(href) ")";
}
}
class PDFGenerator:
def __init__(self, hugo_public_dir: Path, config_path: Path):
self.hugo_dir = hugo_public_dir
self.config = self._load_config(config_path)
self.weasyprint = weasyprint.HTML
def generate_pdfs(self):
"""Generate PDFs for all configured sections"""
for section in self.config['sections']:
self._generate_section_pdf(section)
def _generate_section_pdf(self, section):
"""Generate PDF for a specific section"""
# 1. Collect HTML files
html_files = self._collect_html_files(section['content'])
# 2. Process HTML
processed_html = self._process_html(html_files)
# 3. Add cover page
final_html = self._add_cover_page(processed_html, section)
# 4. Generate PDF
self._generate_pdf(final_html, section['name'])
def _process_html(self, html_files):
"""Process HTML files for PDF generation"""
# Combine HTML files
# Update internal links
# Add page breaks
# Process table of contents
# Generate PDFs for all sections
hugo-pdf generate
# Generate PDF for specific section
hugo-pdf generate --section api
# Use custom configuration
hugo-pdf generate --config my_config.yaml
# Override output directory
hugo-pdf generate --output ./my-pdfs
class PDFGenerationError(Exception):
"""Base class for PDF generation errors"""
pass
class HTMLProcessingError(PDFGenerationError):
"""Error during HTML processing"""
pass
class PDFRenderingError(PDFGenerationError):
"""Error during PDF rendering"""
pass
Pre-processing
HTML Collection
HTML Processing
PDF Generation
from pathlib import Path
from pdf_generator import PDFGenerator
# After Hugo build
hugo_public = Path("websites/my-docs/public")
config_path = Path("config/pdf_config.yaml")
generator = PDFGenerator(hugo_public, config_path)
generator.generate_pdfs()
weasyprint>=54.0
pyyaml>=6.0
bs4>=4.9.3 # For HTML processing
Multiple PDF Engines
Advanced Styling
Optimization
Integration
Would you like me to elaborate on any part of this specification or create example code for a specific component?
Use a tool to turn the output markdown files into webpages. In the past I used https://gohugo.io/.
Hugo Site Generator Specification
Overview
A simple tool that takes markdown files from
output/flat
and creates a Hugo-ready website underwebsites/EXPORT_NAME
. The tool focuses on proper Hugo organization and configuration rather than markdown conversion.Directory Structure
Program Flow
1. Site Creation
2. Content Organization
3. Configuration
Core Features
1. Content Preparation
2. Front Matter Addition
3. Theme Setup
Command Line Interface
Dependencies
Code Structure
Usage Example
Key Differences from Previous Approach
Future Enhancements
The main advantage of this approach is its simplicity - it focuses on organizing content for Hugo rather than trying to handle conversion and templating ourselves. Hugo's built-in features handle most of the complex work.
Would you like me to create example code for any specific component of this system?