eleventy icon indicating copy to clipboard operation
eleventy copied to clipboard

Add an option to keep the symlinks

Open regseb opened this issue 2 years ago • 3 comments

Is your feature request related to a problem? Please describe. The symlinks are not kept. They are replaced by the pointed file / directory.

Describe the solution you'd like Add an option to eleventyConfig.addPassthroughCopy() to keep the links.

Additional context I want to use elevent to deploy a site on GitHub Pages. But the beginning of the URL is different in local and in production:

I want to use the /MY-PROJECT/foo/baz/ URL in the layout. So I created the MY-PROJECT symlink that goes back to the root:

  • foo/
    • bar.md
  • MY-PROJECT -> .

I expect to have in _site:

  • foo/
    • bar/
      • index.html
  • MY-PROJECT -> .

regseb avatar Sep 11 '22 17:09 regseb

This doesn't address symlinks, but this link/config might be useful: https://www.11ty.dev/docs/config/#deploy-to-a-subdirectory-with-a-path-prefix since it discusses deploying to GitHub Pages specifically:

DEPLOY TO A SUBDIRECTORY WITH A PATH PREFIX If your site lives in a different subdirectory (particularly useful with GitHub Pages), use pathPrefix to specify this. It’s used by the url filter and inserted at the beginning of all absolute URL href links. It does not affect your file structure. Leading or trailing slashes are all normalized away, so don’t worry about it.

Basically you could dynamically set the pathPrefix config in your .eleventy.js config file based on the current NODE_ENV (so locally it just writes to / but if you set your NODE_ENV to "prod" or something when deploying to GitHub Pages, it can add your MY_PROJECT/ prefix). Similarly, you can set the config via the command line so your package.json build scripts might look like:

"build:dev": "npx @11ty/eleventy",
"build:prod": "npx @11ty/eleventy --pathprefix=MY_PROJECT",
...

Where the trick is that you'd need to be sure to use the url filter in order for Eleventy to tweak the URLs with the specified prefix.

pdehaan avatar Sep 11 '22 18:09 pdehaan

Ah, I think there is a trick to doing symlinks, https://www.11ty.dev/docs/copy/#advanced-options But looks like it might not be generally available until the upcoming Eleventy v2 release:

"New in 2.0.0-canary.12, you can pass additional configuration options to the recursive-copy package. This unlocks the use passthrough file copy with symlinks, transforming or renaming copied files."

Where the latest versions of @11ty/eleventy are:

npm info @11ty/eleventy dist-tags --json

{
  "latest": "1.0.2",
  "beta": "1.0.0-beta.10",
  "canary": "2.0.0-canary.15"
}

And you can install the "canary" v2 version using npm i @11ty/eleventy@canary -D.


UPDATE: I'm also reminded of the new HTML <base> plugin, which is also available in canary.15.

"With this new plugin, you no longer need to use the url filter in your HTML content. This plugin adds an Eleventy Transform that will modify your HTML output and inject your Path Prefix in your template content."

pdehaan avatar Sep 11 '22 18:09 pdehaan

Thanks for the pathprefix option. I will define both scripts in the package.json:

{
    "scripts": {
        "docs:build": "eleventy",
        "docs:serve": "eleventy --serve"
    }
}

And execute this command in GitHub Actions:

npm run docs:build  -- --pathprefix=MY_PROJECT

I tested with the canary version and the expand option. There is still the problem: the infinite recursive creation of the directory. By directly using recursive-copy, the symlink is kept.

regseb avatar Sep 11 '22 19:09 regseb