Skip to main content

Changing Static Files Per-Branch



  • Pranab Dey

    this is a perfect example. thanks, @royall.
    Some doubts, what’s the meaning of this line - ln -sfv ~/keys/prod.json? what is sfv?
    Just one question, is it only working for the JSON file, or .js file path also work inside hook? (Suppose, I have two different js files inside the web/keys)

  • Royall

    what’s the meaning of this line - ln -sfv ~/keys/prod.json ? what is sfv?

    This means “create a symbolic link from keys/prod.json in my home directory”. The ~ placeholder stands for the $HOME directory, which is /app in this case.

    I’m using 3 options for ln:

    1. s for “symbolic link” (pointing to another file) instead of a hardlink (using the same inode at 2 locations)
    2. f for “force” in order to overwrite the link if it already exists
    3. v for “verbose” so it always prints a message in the deploy log

    You can use this approach for files of any type that need to change at deploy time, as many as you need. You could even link a whole directory, if necessary.

  • Pranab Dey

    Thanks, @royall. Understand now.
    Just one small doubt, correct me if I’m wrong.
    the first one is the symlink u create temporarily in home dir and 2nd one is the actual file path. So, for symlink, '/web' not needed? I thought ‘home’ means where '.platform, web, .yaml' files are there.

  • Royall

    This line:

    ln -sfv ~/keys/prod.json web/keys/key.json

    is a single command that creates a link at ~/web/keys/key.json pointing to the file ~/keys/prod.json.

    Specifying the link’s target file with ~ in front creates an absolute path. If I used keys/prod.json instead, the link at /app/web/keys/key.json would use a relative path to /app/web/keys/keys/prod.json, which is not what we want.

    More detail on symlinks at The Linux Documentation Project section 3.3.5

  • Pierre Martin

    Thanks for this guide.

    The problem that will very likely occur is for static sites that require outside API at bulld time (Static Site Generators). This is a current annoying limitation that would be great to overcome in’s roadmap, since the JAMStack is more and more important these days.

    If someone finds a solution or workaround, I’m interested!


Please sign in to leave a comment.