[Feature]: Layerable Category Button for Nested SubCategories #702
+181
−42
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Type of change
Checklist
Related Issue
#701 (comment)
Changes
Technical Implementation Details
I have introduced a hierarchical category system by refactoring
Categories.astro&content-utils.tsand adding a recursiveCategoryNode.astrocomponent tosrc/component/widget.How to Use?
For
mdfiles insrc\content\posts, using/to define the relationship between a Category and its SubCategories.Example:
category: Examples/Test1/Test21. content-utils.ts
Edited this file to enable Layerable Category in
Categories.astroandCategoryNode.astro.2. Categories.astro
URL Handling: Optimized URL generation by using c.url directly instead of getCategoryUrl(c.name).
Type Safety & Integrity: Explicitly converted badge counts using String(c.count).
Added c.name.trim() to prevent layout issues from whitespace.
Design Refinement: Changed COLLAPSED_HEIGHT from 120px to 7.5rem for better responsive scaling.
3. CategoryNode.astro
Located in
src/components/widget, this component handles the recursive rendering of the category tree.Key Features:
Recursive Rendering: Supports infinite nesting levels.
Native Collapse/Expand: Uses the <details> element for a lightweight, accessible accordion effect.
Visual Hierarchy: Implements dynamic indentation (depth * 12px) to visualize the tree structure.
Hybrid Display Modes:
Uniform Classic Mode: If none of the categories in the current level have subcategories, all items revert to the "Classic Mode" (no arrows, no dots) for a clean look.
Visual Alignment Mode: If at least one item in the current level is expandable, the UI adapts to maintain vertical alignment:
Expandable items display a rotation arrow.
Non-expandable items display a dot marker to occupy the same visual space as the arrow, ensuring all category names remain perfectly aligned.
UX & Interaction Optimization:
Smart Event Propagation: Clicking the category name triggers the timeline view, while clicking the arrow or empty area toggles the sub-category collapse/expand state.
Hover States: Smooth transitions for colors, backgrounds, and indentation.
How To Test
Refer to [How to Use] in [Changes]. Once you edited the
categoryinmdwithxx/xx, you will be able to see Layerable Category Button.Screenshots (if applicable)