Optimize CSS for Tailwind v4 tree-shaking#11
Conversation
Migrate all color scheme files from RGB to OKLCH color format, leveraging Tailwind CSS v4's native color space support. Changes: - Convert all RGB color values to OKLCH for better perceptual uniformity - Use official Tailwind v4 color palette values from theme.css - Enable wider P3 color gamut support for more vivid colors - Improve color consistency across different displays Fixes #8 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Tree-shakeable: icon styles only included when icons are used. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Tree-shakeable: ToC container styles only included when ToC is enabled. Descendant selectors remain raw (target Hugo-generated HTML). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Tree-shakeable: highlight-wrapper, highlight, copy-button, copy-textarea utilities only included when code blocks are present. Parent-child hover interaction (.highlight:hover > .copy-button) remains raw as it cannot be expressed as a single utility. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Organized into 10 sections: 1. Tailwind Configuration 2. Tree-Shakeable Utilities (@Utility blocks) 3. Global Styles 4. Browser Compatibility (pseudo-elements) 5. CSS State Management (:has, :checked) 6. Typography Plugin Overrides (RTL) 7. Hugo-Generated HTML (ToC, tables, code) 8. Third-Party Library Classes (KaTeX) 9. Chroma Syntax Highlighting 10. Dynamic Includes Each section includes comments explaining why the CSS is structured that way. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Test site with pages for: - Baseline (plain text only) - Code blocks (Chroma + copy buttons) - Table of contents (ToC utility) - Icons (icon utility) Includes README with testing instructions. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Addresses review feedback: - Convert --color-neutral from #fff to oklch(100% 0 0) for consistency - Use a single constant hue value per palette (neutral, primary, secondary) - Recalculate all OKLCH values from original RGB to match closely Each palette now uses a fixed hue derived from the circular mean of the original RGB colors, ensuring visual consistency across the color scale. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Color Comparison: RGB → OKLCHAll scheme files have been updated with:
Avocado Scheme
Detailed color tableStone (neutral)
Lime (primary)
Emerald (secondary)
Cherry Scheme
Detailed color tableNeutral
Rose (primary)
Green (secondary)
Congo Scheme
Detailed color tableZinc (neutral)
Violet (primary)
Fuchsia (secondary)
Fire Scheme
Detailed color tableStone (neutral) - Same as Avocado Orange (primary)
Rose (secondary) - Same as Cherry primary Ocean Scheme
Detailed color tableSlate (neutral)
Blue (primary)
Cyan (secondary)
Sapphire Scheme
Detailed color tableSlate (neutral) - Similar to Ocean, hue 258° Indigo (primary)
Pink (secondary)
Slate Scheme
Detailed color tableGray (neutral/secondary)
Slate (primary) - Same as Ocean Slate neutral, hue 259° |
Addresses review feedback on main.css: 1. Avoid CSS reordering - keep original structure, only make necessary changes 2. Change Tailwind source config to exclude all files then include only hugo_stats.json and public/**/* for better tree-shaking control 3. Move .prose blockquote RTL support into @Utility prose block 4. Convert .katex-display to @Utility for tree-shaking 5. Convert .chroma classes to @Utility chroma with nested selectors 6. Convert .icon, .toc, .highlight-*, .copy-* to @Utility blocks Tree-shaking verified working: - Baseline CSS (no features): 5,148 bytes - Full CSS (all features): 12,814 bytes - 60% reduction when feature-specific classes not used Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Review Feedback Addressed (main.css)I've addressed all the review comments on 1. Avoid reordering CSS to keep diff small ✅
2. Change Tailwind source file config ✅/* Before */
@source "hugo_stats.json";
@source not "themes/*";
/* After */
@source not "*";
@source "hugo_stats.json";
@source "public/**/*";This excludes all source files by default and only includes:
3. Move .prose blockquote RTL support to @Utility section ✅Moved all RTL support styles as nested selectors inside @utility prose {
/* ... existing prose config ... */
/* RTL support */
blockquote {
@apply rtl:border-l-0 rtl:border-r-4 rtl:pr-4;
}
ul > li,
ol > li {
@apply rtl:mr-7 rtl:pl-0 rtl:pr-2;
}
/* ... etc ... */
}4. Make .katex-display a @Utility ✅@utility katex-display {
overflow: auto hidden;
}5. Make .chroma classes @Utility ✅Converted all chroma syntax highlighting styles to a single @utility chroma {
@apply rounded-md bg-neutral-50 py-3 text-neutral-700 dark:bg-neutral-700 dark:text-neutral-200;
pre { @apply m-0 p-0; }
.lntable { @apply m-0 block w-auto overflow-auto text-base; }
/* ... all other chroma descendant selectors ... */
}Additional ConversionsAlso converted these to @Utility for consistency:
Tree-Shaking Verification ✅
|
- Update @source directives to exclude all by default, then include hugo_stats.json and public/**/* for proper class detection - Convert icon, toc, highlight-wrapper, highlight, copy-button, copy-textarea, katex-display, and chroma to @Utility blocks - Move RTL support and first-child adjustment into @Utility prose - Use nested selectors throughout for cleaner structure - Keep .prose div.chroma raw for necessary specificity Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add test site in test-tree-shaking/ to verify Tailwind CSS v4 tree-shaking: - baseline/: Basic page with no special utilities - with-code/: Code blocks testing .chroma, .highlight utilities - with-toc/: Table of contents testing .toc utility - with-icons/: Icon shortcode testing .icon utility Configuration: - Enable class-based syntax highlighting (noClasses = false) - Enable hugo_stats.json generation for class detection Verified tree-shaking results: - INCLUDED: .chroma (42 rules), .toc (6 rules), .highlight (2 rules), .prose (89 rules), .icon (1 rule) - EXCLUDED: .katex-display, .copy-textarea, .highlight-wrapper Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Rename template directories to follow Hugo conventions: - layouts/_markup/ -> layouts/markup/ - layouts/_partials/ -> layouts/partials/ - layouts/_shortcodes/ -> layouts/shortcodes/ Add base templates: - layouts/_default/baseof.html - layouts/_default/list.html - layouts/_default/single.html Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Tree-Shaking Implementation VerifiedI've added a comprehensive test site and verified that the Tailwind CSS v4 tree-shaking is working correctly. Test Site:
|
| Page | Purpose | Utilities Tested |
|---|---|---|
baseline/ |
Plain page, no special features | Basic layout only |
with-code/ |
Code blocks with syntax highlighting | .chroma, .highlight |
with-toc/ |
Table of contents enabled | .toc |
with-icons/ |
Icon shortcodes | .icon |
Configuration Added
markup.toml- Enables class-based syntax highlighting (noClasses = false) for proper.chromaclass generationhugo.toml- Basic Hugo config withbuildStatsenabled forhugo_stats.jsongeneration
Tree-Shaking Test Results
CSS File Size: 39,205 bytes
Utilities INCLUDED (correctly - used on pages):
| Utility | Rules | Source |
|---|---|---|
.chroma |
42 | Code blocks on with-code page |
.prose |
89 | Article content on all pages |
.toc |
6 | Table of contents on with-toc page |
.highlight |
2 | Code block wrappers |
.icon |
1 | Icon shortcodes on with-icons page |
Utilities EXCLUDED (correctly tree-shaken - not used):
.katex-display- No KaTeX math used.copy-textarea- Not used.highlight-wrapper- Not used
Commits
- 28d4165 - Add tree-shaking test site with comprehensive utility testing
- 564527a - Reorganize layouts directory structure (remove underscore prefixes)
How to Run Tests
cd test-tree-shaking
hugo --gc
# Check generated CSS in public/ for utility inclusion
# Check hugo_stats.json for detected classesThe tree-shaking is working as designed - utilities are included only when their corresponding classes are detected in hugo_stats.json.
- Use @import "tailwindcss" source(none) instead of @source not "*" (idiomatic Tailwind v4 syntax per official docs) - Make publish directory configurable via site.Params.publishDir with "public" as default for flexibility - Update comment to explain the @source configuration Verified: .chroma .gl generates correct underline CSS (text-decoration-line:underline) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Additional main.css Review Feedback AddressedCommit 53d9f16 addresses the remaining pending review comments: 1. Use idiomatic Tailwind v4 source configurationBefore: @import "tailwindcss";
@source not "*";
@source "hugo_stats.json";
@source "public/**/*";After: @import "tailwindcss" source(none);
@source "hugo_stats.json";
@source "{{ site.Params.publishDir | default "public" }}/**/*";Per Tailwind CSS v4 docs, 2. Configurable publish directoryThe publish directory path is now configurable via [params]
publishDir = "dist"3. Verified chroma .gl underline CSSConfirmed that .chroma .gl{text-decoration-line:underline} |
23a3b24 to
2a22918
Compare
- Resolved CSS formatting conflicts using compact style - Removed test-tree-shaking directory (moved to separate repo) - Kept OKLCH color optimization changes Test site: https://github.com/dave-atx/congo-tree-shaking-tests Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Update: Merge Conflicts ResolvedThe merge conflicts from the previous commit have been fixed: Changes Made
Test Results ✅All CSS tree-shaking tests pass:
Test RepositoryTest site moved to: https://github.com/dave-atx/congo-tree-shaking-tests This keeps the theme repo clean while providing a dedicated space for tree-shaking verification. 🤖 Generated with Claude Code |
Remove layouts reorganization that should not be on this branch. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Review Comments AddressedAll 11 review comments on Changes Made in Commit 76b2dcb
Previously Addressed (in earlier commits)
Test Results
🤖 Generated with Claude Code |
Mark all review comments as addressed and document the changes made in this PR. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
5383787 to
2f6102d
Compare
Summary
This PR refactors
assets/css/main.cssto maximize tree-shakeability with Tailwind CSS v4:@utilityblocks that are only included when the class is detected inhugo_stats.jsonTree-Shakeable Utilities Added
@utility icon@utility toc@utility highlight-wrapper@utility highlight@utility copy-button@utility copy-textareaSections That Must Remain Raw
Verification
Tree-shaking verified working:
@utility icon: INCLUDED when icons detected@utility toc: EXCLUDED when ToC not detected (tree-shaken!)@utility highlight-wrapper: EXCLUDED (tree-shaken!)Test plan
hugo_stats.jsonfor class detection🤖 Generated with Claude Code