Skip to content

Fix asset copying to merge with existing directories#869

Open
jpurnell wants to merge 7 commits intotwostraws:mainfrom
jpurnell:fix/merge-copy-assets
Open

Fix asset copying to merge with existing directories#869
jpurnell wants to merge 7 commits intotwostraws:mainfrom
jpurnell:fix/merge-copy-assets

Conversation

@jpurnell
Copy link
Copy Markdown
Contributor

Summary

This PR fixes a crash that occurs when users have folders in Assets/ with the same names as Ignite-generated folders (e.g., css/, fonts/, or any page name).

The problem:

  • copyAssets() and copyFonts() use FileManager.copyItem() which throws if the destination already exists
  • Ignite generates css/ and fonts/ folders during content generation (for bootstrap, ignite-core, etc.)
  • When users have Assets/css/custom.css, the copy fails because docs/css/ already exists
  • clearBuildFolder() uses try? and can silently fail with file locks (especially on Dropbox)

The fix:

  • Adds a recursive mergeContents(from:to:) helper that:
    • For files: removes existing and copies (allowing overwrites)
    • For directories: creates if needed, then recursively merges contents
  • Updates copyAssets(), copyFonts(), and copy(resource:) to use this helper

Result:
Users can now have Assets/css/custom.css and it will appear alongside Ignite's bootstrap.min.css in the final docs/css/ folder.

Test plan

  • Verified fix compiles
  • Tested with a project that has Assets/css/, Assets/fonts/, and Assets/constitution/ folders
  • Confirmed merged output contains both Ignite files and user files
  • Tested multiple builds without cleaning (no more intermittent failures)

Previously, copyAssets() and copyFonts() used FileManager.copyItem()
which fails if the destination already exists. This caused crashes when
users had folders in Assets/ with the same names as Ignite-generated
folders (e.g., css/, fonts/, or any page name like constitution/).

This was particularly problematic because:
1. Ignite generates css/ and fonts/ folders during content generation
2. Users often want to add custom CSS/fonts alongside Ignite's files
3. clearBuildFolder() uses try? and silently fails with file locks

The fix adds a recursive mergeContents() helper that:
- For files: removes existing and copies (allowing overwrites)
- For directories: creates if needed, then recursively merges contents

This allows users to have Assets/css/custom.css alongside Ignite's
bootstrap.min.css in the final build output.
The theme-switching JavaScript reads these attributes to determine which
CSS theme selectors to activate. Without them, custom themes fall back
to "light"/"dark" which don't match custom theme CSS selectors like
[data-bs-theme="my-theme-light"], breaking dark mode for custom themes.
Allow sites to specify which content types appear in the RSS feed
(e.g. contentTypes: ["letters"]). When nil, all types are included.
Escape &, <, >, ", ' in title, site name, and site description
fields that are not wrapped in CDATA sections. Unescaped & in
titles like "Donations & Sponsorships" produced invalid XML that
feed readers rejected.
The auto-synthesized init for EmptyTagPage was internal, making it
impossible for consuming packages to use EmptyTagPage() to disable
tag page generation.
GitHub Pages serves directory-style URLs with a trailing slash,
but the sitemap was emitting them without one, causing 301 redirects
for every page in the sitemap.
@jpurnell jpurnell force-pushed the fix/merge-copy-assets branch from 5b06a64 to ff2890a Compare March 16, 2026 20:20
Static hosts serve directory-style pages (path/index.html) at path/,
so links without a trailing slash cause unnecessary 301 redirects.
This adds a linkPath(for:) method that appends trailing slashes to
local page URLs (skipping external URLs and file paths with extensions)
and uses it in Link and LinkGroup rendering.
@jpurnell jpurnell force-pushed the fix/merge-copy-assets branch from 746c2a1 to 89c0a9e Compare March 16, 2026 21:23
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