Skip to content

feat(extraction): Hugo design-system support — Markdown, Templates, CSS/SCSS, YAML, JSON#311

Open
alexander-kastil wants to merge 1 commit into
colbymchenry:mainfrom
alexander-kastil:feature/hugo-design-system
Open

feat(extraction): Hugo design-system support — Markdown, Templates, CSS/SCSS, YAML, JSON#311
alexander-kastil wants to merge 1 commit into
colbymchenry:mainfrom
alexander-kastil:feature/hugo-design-system

Conversation

@alexander-kastil
Copy link
Copy Markdown

What is Hugo?

Hugo is one of the most widely used open-source static site generators, built in Go. It powers documentation sites, corporate websites, developer blogs, and government portals across the industry. A Hugo project is organised around a distinct file tree: content (Markdown with front matter), layouts (Go html/template partials and base templates), assets (CSS/SCSS, JS), and data (YAML/JSON/TOML configuration and site data). Until now CodeGraph treated almost all of these as opaque blobs.

Why index CSS / SCSS?

Design systems live in CSS. When an AI agent needs to understand why a component looks the way it does, or wants to trace where a token like --color-primary is defined and consumed, it currently has no graph to walk — it can only grep. With full CSS/SCSS extraction:

  • Design tokens (--custom-properties, $scss-variables) become first-class variable nodes — searchable, linkable, and traceable across files.
  • Mixins and utility functions become function nodes, so an agent can find all callers of @include button-base() without a full-text search.
  • @layer declarations become namespace nodes, making cascade-layer architecture visible in the graph.
  • @use / @forward / @import produce real imports edges, so the SCSS module graph is walkable exactly like a TypeScript import graph.

This matters most for Hugo sites (which commonly have a bespoke SCSS design system), but the extractors work on any project that uses CSS or SCSS.

What this PR adds

New language support

Language Extensions What's extracted
Hugo Markdown .md .markdown Front matter fields (title, date, tags, …) as property nodes; headings as class/function nodes
Hugo Templates .html (under layouts/ or themes/), .gohtml .tmpl .gotmpl File as function node; {{ define }} blocks; {{ partial }} / {{ partialCached }} calls; {{ block }} slots; {{ template }} calls; $variable assignments
CSS .css CSS custom properties (--token), @keyframes, @layer, @import
SCSS / Sass .scss .sass Everything from CSS, plus $variables, @mixin, @function, %placeholder, @use / @forward, @include calls, @extend references
YAML .yml .yaml Upgraded from file-level tracking only → tree-sitter extraction of top-level mapping keys as variable nodes
JSON .json Tree-sitter extraction of top-level object keys as variable nodes

Hugo Template path gating

Plain .html files (e.g. email templates, test fixtures) are not processed. Only .html files whose path contains layouts/ or themes/ are routed to HugoTemplateExtractor. Files with explicit Hugo extensions (.gohtml, .tmpl, .gotmpl) are always processed regardless of path.

Infrastructure

  • src/types.ts — six new Language union members: json, markdown, gotemplate, css, scss, sass
  • src/extraction/grammars.ts — WASM grammar entries for YAML and JSON (tree-sitter); extension map entries for all new types; isLanguageSupported / isGrammarLoaded / getSupportedLanguages updated
  • src/extraction/languages/index.ts — YAML and JSON extractors registered
  • src/extraction/tree-sitter.ts — dispatch branches for the four new custom extractors

Test updates

  • __tests__/extraction.test.ts — replaced two assertions that incorrectly expected .css and .json to resolve to unknown
  • __tests__/security.test.ts — updated isSourceFile expectations now that CSS and Markdown are supported extensions

Test plan

  • npm test passes
  • npm run build succeeds (YAML + JSON WASM files copy into dist/)
  • Index a Hugo project and verify Markdown front matter fields appear as nodes
  • Index a Hugo project and verify {{ partial "nav.html" . }} produces a calls edge
  • Index an SCSS design-system file and verify $primary-color appears as a variable node
  • Confirm .html files outside layouts/ are not indexed as Hugo templates

🤖 Generated with Claude Code

- src/extraction/hugo-markdown-extractor.ts: new extractor for Hugo Markdown files, parsing front matter and headings.
- src/extraction/hugo-template-extractor.ts: new extractor for Hugo template files, handling partials, blocks, and template calls.
- src/extraction/languages/json.ts: new JSON extractor for top-level object keys in Hugo-related JSON files.
- src/extraction/languages/yaml.ts: new YAML extractor for top-level mapping keys in Hugo-related YAML files.
- src/extraction/scss-extractor.ts: new SCSS extractor extending CSSExtractor to handle SCSS-specific constructs like variables and mixins.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant