Skip to content

Add hierarchical tree view for tag categories#3482

Open
oliver-howard wants to merge 5 commits intojaneczku:Developfrom
oliver-howard:master
Open

Add hierarchical tree view for tag categories#3482
oliver-howard wants to merge 5 commits intojaneczku:Developfrom
oliver-howard:master

Conversation

@oliver-howard
Copy link
Copy Markdown

SCR-20251106-jwzf

Problem

Closes #1185

Currently, Calibre-Web displays all tags as a flat list on the Categories page. When users create hierarchical tags using dot notation (e.g., Fantasy.Urban, SciFi.Space.Opera) in Calibre, they appear as separate, individual entries rather than a nested hierarchy. This makes navigation difficult and creates visual clutter for users with large, organized tag collections.

Solution

This PR implements hierarchical tag parsing and tree view display for the Categories page. Tags using period separators (.) are automatically parsed into a nested tree structure with expand/collapse functionality, matching how Calibre handles hierarchical tags.

Features Implemented

Core Functionality

  • Tree View Display: Tags with period separators are parsed into hierarchical tree structure
  • Expand/Collapse: Interactive navigation of parent/child categories with visual indicators (arrows, folder/tag icons)
  • Aggregated Counts: Parent categories show total book count from all subcategories
  • Smart Display: Tag names use chevron separator () instead of period for better readability within book view
  • Theme Compatible: Book count badges adapt to active theme colors (default, caliBlur, etc.)

Navigation Features

  • Sorting: Alphabetical (A-Z) and reverse alphabetical (Z-A) sorting maintained across all tree levels
  • Letter Filtering: Quick navigation by first letter for root-level categories
  • Responsive Layout: Flexbox-based design prevents horizontal scrolling at any screen width
  • Backward Compatible: Non-hierarchical tags (without periods) continue to work normally

Technical Implementation

Backend (cps/helper.py)

Added tag hierarchy parsing and tree building functions:

  • parse_tag_hierarchy() - Split hierarchical tag names into components
  • get_tag_leaf_name() - Extract leaf node from hierarchical tag
  • get_tag_display_name() - Format tags with chevron separator
  • is_hierarchical_tag() - Check if tag contains hierarchy separator
  • build_tag_tree() - Convert flat tag list to nested tree with aggregated counts
  • tree_to_list() - Flatten tree for template rendering with level metadata

Frontend

Display Updates

Additional Fix

  • cps/gdriveutils.py: Added null check for cli_param.gd_path to prevent errors when Google Drive is not configured

Usage Example

Users create hierarchical tags in Calibre using period separators:
Fantasy.Urban-Fantasy
Fantasy.Epic.High-Fantasy
SciFi.Dystopian.Space-Opera

These automatically display as an expandable tree in Calibre-Web's Categories page, with parent categories showing aggregated book counts.

Testing

  • Python 3.8+ compatible
  • Tested on macOS (Darwin 25.0.0)
  • Tree navigation and expand/collapse works at all nesting levels
  • Book counts aggregate correctly up the hierarchy
  • Sorting (A-Z, Z-A) functions correctly across all levels
  • Letter filtering works for root-level categories
  • Theme compatibility verified (default & caliBlur themes)
  • Tag links navigate to correct filtered book views
  • Backward compatible with non-hierarchical tags

Notes

  • No database schema changes required
  • Existing tag data is not modified
  • Feature is opt-in (use periods in Calibre tag names to create hierarchy)
  • Maintains existing Categories page functionality for flat tags

- Replace custom .count class with Bootstrap's .badge class for theme compatibility
- Remove hardcoded colors from tag icons and names to inherit from active theme
- Add flexbox constraints to prevent badge overflow and horizontal scrolling
- Set max-width: 100% on tag-tree, list items, and tag-node for proper containment
- Add min-width: 0 and overflow: hidden to tag names for text truncation
- Add flex-shrink: 0 to badges to prevent them from being squeezed out

This ensures badges display correctly in both default and custom themes
(e.g., caliBlur) without requiring horizontal scrolling.
@crash5
Copy link
Copy Markdown

crash5 commented Dec 23, 2025

I can't test it now, does it show the categories under opds/category too?

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.

2 participants