Skip to content

Instantly share code, notes, and snippets.

@davep
Created May 3, 2026 08:20
Show Gist options
  • Select an option

  • Save davep/1494163d2b34206054575053b82f90df to your computer and use it in GitHub Desktop.

Select an option

Save davep/1494163d2b34206054575053b82f90df to your computer and use it in GitHub Desktop.
Gemini CLI's plan to refactor generator.py in BlogMore

Refactoring Plan: Modularizing SiteGenerator

Goal: Break down the 2,146-line src/blogmore/generator.py into a focused package to improve maintainability, reduce "God Object" complexity, and adhere to a <1000 line-per-file standard.

1. Directory Structure

Create a new package directory: src/blogmore/generator/.

2. Proposed Module Map

Sub-module Responsibilities
site.py High-level orchestration. Contains the SiteGenerator class and the primary generate() loop.
assets.py Implementation of icon generation, FontAwesome optimization, CSS/JS minification, and static/extras copying.
paths.py URL calculations, output path resolution, and canonical URL logic.
context.py Global template context preparation and sidebar page resolution.
grouping.py Logic for grouping posts by tags, categories, and dates; includes word-cloud calculation logic.
listing.py The generate_paginated_listing boilerplate used by archives, tags, and categories.
utils.py Shared helpers like minified_filename and paginate_posts.
constants.py Filename constants and internal configuration lists (e.g., PAGE_SPECIFIC_CSS).
__init__.py Public API surface to ensure backward compatibility for from blogmore.generator import SiteGenerator.

3. High-Impact Changes

  • Abstract the Rendering Pipeline: Consolidate the repetitive 5-step pattern used in over 10 different _generate_X_page methods into a single internal utility.
  • Unify Minification: Merge the nearly identical CSS and JS minification logic to reduce code duplication.
  • Centralize Path Logic: Replace manual string manipulation and repeated lstrip("/") calls with centralized helpers in paths.py.
  • Encapsulate Side Effects: Move low-level file system operations (like shutil.copy2 and minify_html) out of the main class and into focused asset handlers.

4. Validation Strategy

  • Ensure all 330+ unit tests in tests/test_generator.py pass.
  • Verify that integration tests in tests/test_integration.py confirm the site still builds correctly end-to-end.
  • Maintain private method wrappers in SiteGenerator where necessary to avoid breaking tests that rely on internal method names.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment