|
| 1 | +<!-- OPENSPEC:START --> |
| 2 | +# OpenSpec Instructions |
| 3 | + |
| 4 | +These instructions are for AI assistants working in this project. |
| 5 | + |
| 6 | +Always open `@/openspec/AGENTS.md` when the request: |
| 7 | +- Mentions planning or proposals (words like proposal, spec, change, plan) |
| 8 | +- Introduces new capabilities, breaking changes, architecture shifts, or big performance/security work |
| 9 | +- Sounds ambiguous and you need the authoritative spec before coding |
| 10 | + |
| 11 | +Use `@/openspec/AGENTS.md` to learn: |
| 12 | +- How to create and apply change proposals |
| 13 | +- Spec format and conventions |
| 14 | +- Project structure and guidelines |
| 15 | + |
| 16 | +Keep this managed block so 'openspec update' can refresh the instructions. |
| 17 | + |
| 18 | +<!-- OPENSPEC:END --> |
| 19 | + |
| 20 | +# Hugo Blog AI Assistant Instructions |
| 21 | + |
| 22 | +## 🏗️ Project Overview |
| 23 | + |
| 24 | +This is a Hugo-based static blog system using PaperMod theme, deployed on GitHub Pages. The system features multilingual support (Chinese/English), AI-powered content tools, and automated workflows. |
| 25 | + |
| 26 | +### Core Architecture |
| 27 | +- **Hugo Version**: 0.152.2 (extended) |
| 28 | +- **Theme**: PaperMod (standard multi-page architecture) |
| 29 | +- **Languages**: Chinese (default), English |
| 30 | +- **Deployment**: GitHub Pages via GitHub Actions |
| 31 | +- **Content Structure**: Multi-language content under `content/zh/` and `content/en/` |
| 32 | + |
| 33 | +## 📁 Key Directory Structure |
| 34 | + |
| 35 | +``` |
| 36 | +hobbytp.github.io/ |
| 37 | +├── config/_default/ # Hugo configuration files |
| 38 | +├── content/ # Multilingual content |
| 39 | +│ ├── zh/ # Chinese content |
| 40 | +│ └── en/ # English content |
| 41 | +├── static/ # Static assets (images, CSS, JS) |
| 42 | +├── layouts/ # Hugo template overrides |
| 43 | +├── assets/ # SCSS/CSS processing |
| 44 | +├── tools/ # Python tools for content management |
| 45 | +│ ├── content-analysis/ # AI-powered content analysis |
| 46 | +│ ├── image-optimization/ # Image optimization tools |
| 47 | +│ ├── performance-monitor/ # Performance analysis |
| 48 | +│ └── pdf-exporter/ # PDF export functionality |
| 49 | +├── scripts/ # Automation scripts |
| 50 | +├── .github/workflows/ # CI/CD workflows |
| 51 | +└── public/ # Generated site (gitignored) |
| 52 | +``` |
| 53 | + |
| 54 | +## 🛠️ Hugo Configuration |
| 55 | + |
| 56 | +### Main Configuration (`config/_default/hugo.toml`) |
| 57 | +- **BaseURL**: `https://hobbytp.github.io/` |
| 58 | +- **Title**: "Peng Tan's AI Blog" |
| 59 | +- **Theme**: PaperMod |
| 60 | +- **Default Language**: Chinese (`zh`) |
| 61 | +- **Build Settings**: Production-ready with optimizations enabled |
| 62 | + |
| 63 | +### Key Features |
| 64 | +- **Multilingual Support**: Separate content trees per language |
| 65 | +- **Image Optimization**: WebP support, quality settings |
| 66 | +- **Performance Caching**: Resource caching strategies |
| 67 | +- **SEO**: Robots.txt enabled, Git info disabled |
| 68 | + |
| 69 | +## 🚀 Development Workflow |
| 70 | + |
| 71 | +### Local Development |
| 72 | +```bash |
| 73 | +# Start development server |
| 74 | +make dev |
| 75 | +# or |
| 76 | +docker-compose up hugo |
| 77 | +``` |
| 78 | + |
| 79 | +The development server runs on `http://localhost:1313` with: |
| 80 | +- Live reload enabled |
| 81 | +- Draft content visible |
| 82 | +- Fast rendering disabled for better debugging |
| 83 | + |
| 84 | +### Building for Production |
| 85 | +```bash |
| 86 | +# Production build |
| 87 | +make build |
| 88 | +# or |
| 89 | +make full-build # Includes optimization and analysis |
| 90 | +make full-build-ai # AI-enhanced build process |
| 91 | +``` |
| 92 | + |
| 93 | +## 🧪 Testing & Validation |
| 94 | + |
| 95 | +### Architecture Validation |
| 96 | +```bash |
| 97 | +# Run complete architecture validation |
| 98 | +make validate-architecture |
| 99 | +``` |
| 100 | + |
| 101 | +The validation script checks: |
| 102 | +- Template architecture compliance (PaperMod standard) |
| 103 | +- CSS file size limits (≤1000 lines) |
| 104 | +- No problematic CSS selectors |
| 105 | +- Hugo build success |
| 106 | +- SPA mode disabled status |
| 107 | + |
| 108 | +### Content Quality Analysis |
| 109 | +```bash |
| 110 | +# Basic content analysis |
| 111 | +make analyze-content |
| 112 | + |
| 113 | +# AI-enhanced content analysis |
| 114 | +make analyze-content-ai |
| 115 | + |
| 116 | +# Analyze specific file |
| 117 | +make analyze-content FILE=./content/zh/some-article.md |
| 118 | +``` |
| 119 | + |
| 120 | +### Performance Analysis |
| 121 | +```bash |
| 122 | +# Performance monitoring |
| 123 | +make analyze-performance |
| 124 | +make performance-report |
| 125 | +``` |
| 126 | + |
| 127 | +## 📦 Deployment |
| 128 | + |
| 129 | +### GitHub Actions CI/CD |
| 130 | +- **Trigger**: Push to `main` or `gh-pages` branches |
| 131 | +- **Process**: Build → Deploy to GitHub Pages |
| 132 | +- **Environment**: Production Hugo build with minification |
| 133 | +- **Dependencies**: Node.js for PostCSS processing |
| 134 | + |
| 135 | +### Deployment Workflow (`.github/workflows/hugo.yml`) |
| 136 | +1. Checkout repository with submodules |
| 137 | +2. Setup Hugo v0.152.2 extended |
| 138 | +3. Install Node.js dependencies (PostCSS, Autoprefixer) |
| 139 | +4. Build site with `hugo --minify --configDir=config` |
| 140 | +5. Deploy to GitHub Pages |
| 141 | + |
| 142 | +## 🎨 Customization Guidelines |
| 143 | + |
| 144 | +### CSS Architecture |
| 145 | +- **Main File**: `assets/css/custom.css` (~745 lines) |
| 146 | +- **Pipeline**: Hugo CSS bundling with minification and fingerprinting |
| 147 | +- **Limits**: Keep under 1000 lines for performance |
| 148 | +- **Approach**: Override PaperMod CSS variables, avoid CDN dependencies |
| 149 | + |
| 150 | +### Template Customization |
| 151 | +- **Location**: `layouts/` directory |
| 152 | +- **Standard**: Follow Hugo template hierarchy |
| 153 | +- **Compliance**: Must be PaperMod compatible |
| 154 | +- **Forbidden**: No SPA templates or complex JavaScript routing |
| 155 | + |
| 156 | +## 🤖 AI-Powered Tools |
| 157 | + |
| 158 | +### Content Analysis (`tools/content-analysis/`) |
| 159 | +- **Basic**: Word count, reading time, structure analysis |
| 160 | +- **AI-Enhanced**: Content quality scoring, SEO recommendations |
| 161 | +- **Dashboard**: JSON data generation for frontend analytics |
| 162 | + |
| 163 | +### Image Management |
| 164 | +```bash |
| 165 | +# Optimize existing images |
| 166 | +make optimize-images |
| 167 | + |
| 168 | +# Generate AI cover images |
| 169 | +make generate-ai-covers |
| 170 | + |
| 171 | +# Generate covers for specific directory |
| 172 | +make generate-covers-for-directory DIRECTORY=papers |
| 173 | +``` |
| 174 | + |
| 175 | +### PDF Export |
| 176 | +```bash |
| 177 | +# Export all articles to PDF |
| 178 | +make export-pdf |
| 179 | + |
| 180 | +# Export specific article |
| 181 | +make export-pdf FILE=./content/zh/article.md |
| 182 | +``` |
| 183 | + |
| 184 | +## ⚙️ Makefile Commands |
| 185 | + |
| 186 | +### Development |
| 187 | +- `make dev` - Start development server |
| 188 | +- `make fresh` - Clean and restart |
| 189 | +- `make stop` - Stop services |
| 190 | + |
| 191 | +### Build & Deploy |
| 192 | +- `make build` - Production build |
| 193 | +- `make full-build` - Complete build process |
| 194 | +- `make clean` - Clean build artifacts |
| 195 | + |
| 196 | +### Analysis & Optimization |
| 197 | +- `make analyze-content` - Content quality analysis |
| 198 | +- `make analyze-performance` - Performance monitoring |
| 199 | +- `make optimize-images` - Image optimization |
| 200 | + |
| 201 | +### AI Tools |
| 202 | +- `make analyze-content-ai` - AI-enhanced analysis |
| 203 | +- `make generate-ai-covers` - AI cover generation |
| 204 | +- `make generate-json-data-ai` - AI analytics data |
| 205 | + |
| 206 | +## 🚨 Architecture Constraints |
| 207 | + |
| 208 | +### ✅ Allowed |
| 209 | +- Standard Hugo template hierarchy |
| 210 | +- PaperMod theme customization |
| 211 | +- CSS custom properties for theming |
| 212 | +- Hugo's built-in features and optimizations |
| 213 | +- Progressive enhancement JavaScript |
| 214 | + |
| 215 | +### ❌ Forbidden |
| 216 | +- SPA mode activation (templates preserved but disabled) |
| 217 | +- External CSS frameworks via CDN |
| 218 | +- Complex JavaScript routing systems |
| 219 | +- Modifying core PaperMod templates unnecessarily |
| 220 | +- CSS `:contains()` selectors |
| 221 | +- `assets/css/custom.css` > 1000 lines |
| 222 | + |
| 223 | +## 🔧 Environment Setup |
| 224 | + |
| 225 | +### Required Tools |
| 226 | +- **Hugo**: v0.152.2+ extended |
| 227 | +- **Docker**: For containerized development |
| 228 | +- **Python**: For AI tools (conda `news_collector` environment) |
| 229 | +- **Node.js**: For PostCSS processing |
| 230 | + |
| 231 | +### Environment Variables |
| 232 | +Key variables in `.env` file: |
| 233 | +- `VOLCENGINE_ACCESS_KEY`, `VOLCENGINE_SECRET_KEY` - Default AI image generation |
| 234 | +- `MODELSCOPE_API_KEY` - Alternative AI service |
| 235 | +- `OPENAI_API_KEY` - OpenAI integration |
| 236 | +- `TEXT2IMAGE_PROVIDER` - AI service selection |
| 237 | + |
| 238 | +## 📋 Best Practices |
| 239 | + |
| 240 | +### Before Committing |
| 241 | +1. Run `make validate-architecture` |
| 242 | +2. Test with `make build` |
| 243 | +3. Check CSS file size limits |
| 244 | +4. Verify template compliance |
| 245 | + |
| 246 | +### Content Creation |
| 247 | +1. Use proper front matter with language tags |
| 248 | +2. Place content in correct language directory |
| 249 | +3. Test with `make analyze-content` |
| 250 | +4. Generate covers with AI tools when needed |
| 251 | + |
| 252 | +### Performance Optimization |
| 253 | +1. Optimize images before adding to content |
| 254 | +2. Use Hugo's built-in image processing |
| 255 | +3. Monitor with `make analyze-performance` |
| 256 | +4. Keep CSS bundle size minimal |
| 257 | + |
| 258 | +## 📚 Documentation |
| 259 | + |
| 260 | +- **Architecture**: `ARCHITECTURE.md` - Detailed system architecture |
| 261 | +- **Development**: `CLAUDE.md` - Development guidelines |
| 262 | +- **Project**: `README.md` - General project information |
| 263 | +- **Layouts**: `docs/layout-overview.md` - Template structure |
| 264 | + |
| 265 | +--- |
| 266 | + |
| 267 | +**Current Architecture Status**: ✅ STABLE & PRODUCTION-READY |
| 268 | +**Last Updated**: Based on analysis of Hugo v0.152.2, PaperMod theme, and current tooling |
| 269 | +**Maintainer**: Follow the established patterns and validation procedures for any changes. |
0 commit comments