Skip to content

Retain specific files when using --cleanDestinationDir #14937

@ilovelinux

Description

@ilovelinux

Usecase

I'm using Codeberg Pages to host my website, you can find the repostitory at https://codeberg.org/ilovelinux/pages

I have two branches:

  • main: hugo project
  • pages: hugo build (output of public/)

Since I'm using Codeberg Pages with a custom domain, I also need a .domains file1 to be pushed in the pages branch.

When I

  • Have files in the static/ directory.
  • Switch to main branch.
  • Create the public/ folder using a git worktree of the pages branch.
  • Run hugo build --cleanDestinationDir.

I need

  • To remove outdated content
  • To retain:
    • .git file created by git worktree2.
    • .domains file used by Codeberg Pages in order to allow custom domains1.
    • _redirects file for redirects (however I'm not using it yet)3.

Instead

  • The files I need to be retained are deleted.

Proposal

Add a configuration field to list relative file paths to public/ that should be retained when using --cleanDestinationDir.

Example

 filesToRetain:
  - .git
  - .domains
  - _redirects
  - foo/bar/.mysecretfile

Files retained:

  • public/.git
  • public/.domains
  • public/_redirects
  • public/foo/bar/.mysecretfile

Note

I'm not suggesting to use filesToRetain as configuration field, but I couldn't think of a better name.

Notes

Important

--cleanDestinationDir does nothing when when the static/ directory doesn't exist since its value is used inside the copyStaticTo function.

syncer.Delete = conf.configs.Base.CleanDestinationDir

Workaround

Warning

This approach is error-prone.

I implemented a workaround in my Makefile that:

Related issues & PR

Footnotes

  1. https://docs.codeberg.org/codeberg-pages/using-custom-domain/ 2

  2. https://git-scm.com/docs/git-worktree#_details

  3. https://docs.codeberg.org/codeberg-pages/redirects/

  4. https://git-scm.com/docs/git-submodule#Documentation/git-submodule.txt-absorbgitdirs

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions