$ show hexojs/hexo
Hexo is a mature, plugin-driven static site generator written in TypeScript for Node.js. It transforms Markdown (or other markup) content into a fully static website, supporting themes, helpers, tags, filters, and generators via a consistent extension API. The core architecture centers on a `Hexo` class that orchestrates configuration loading, plugin registration, file watching (via `Box`), content processing (processors), rendering (renderers with Nunjucks and highlight.js/prism), and static file generation. It includes a built-in CLI (`hexo new`, `hexo generate`, `hexo deploy`, etc.) and a lightweight database (`warehouse`) for metadata. The codebase is well-tested with extensive unit tests and CI across multiple OS/Node versions. While the architecture is clean and extensible, some technical debt exists (e.g., reliance on `bluebird` promises, `@ts-expect-error` workarounds, and complex regex-based processing).
The LLM identified 3 files worth highlighting for reuse:
The `Box` class provides a generic file-watching and processing pipeline. It monitors a directory for changes (create, update, delete), uses a `Cache` model with SHA1 hashing and mtime to detect modifications, and dispatches events to registered processors. This pattern is reusable in any project that needs to react to file system changes with efficient change detection, independent of Hexo's domain.
`BinaryRelationIndex` implements an efficient in-memory index for many-to-many relationships (e.g., post-tag, post-category). It stores pairs of IDs and provides fast methods to query by either side, add/remove relationships, and list all pairs. This is a self-contained data structure that can be extracted and reused in any application requiring bidirectional many-to-many lookups without a full database.
The `Injector` extension point allows plugins to insert HTML snippets at specific locations in generated pages (e.g., `<head>`, `<body>`, before `</body>`). It maintains a registry of injection points and content, and provides a `render` method to apply all injections. This pattern is reusable for any HTML generation system that needs a hook-based content injection mechanism, decoupled from the rendering pipeline.