patrickarlt / acetate

A flexible, fast and easy to extend static site generator for Node
http://acetate.io
ISC License
20 stars 13 forks source link

Allow configuration for pathname in addition to host and port #67

Open lheberlie opened 7 years ago

lheberlie commented 7 years ago

Hey Pat,

Request:

It would be helpful to allow for configuration while running acetate in server/watch mode to have a pathname in addition to host and port.

Description:

When normally running acetate in server/watch mode the dev server will launch with http://localhost:3000/ where content is served from the build output folder configuration.

It would be helpful to have a configuration option where the build output folder configuration is served from http://localhost:3000/foo/bar and all page metadata would remain available.

Justification

This will help with content creators who are not familiar with the acetate build system to author relative links correctly in markdown (md) pages. Often content creators will go up too far in the relative directory tree [foo](../../../folder/index.html) which works fine when hosted from http://localhost:3000 but after deployment the link is broken.

Contact me if this does not accurately describe the issue.

--Lloyd

cc: @bsvensson

patrickarlt commented 7 years ago

@lheberlie Since browsersync doesn't support an option like this https://www.browsersync.io/docs/options and I'm not really sure why they would, I've implimented this in the following way:

  1. In acetate@2.0.0-rc.2, acetate.load(pattern) now accepts an additional options object, acetate.load(pattern, options).
  2. One of those options is a basePath which will be prepend to all page url and dest properties.

So:

acetate.load('**/*.+(html|md)', {
  basePath: 'javascript/latest' // no leading or trailing slashes
})

would now mean that all files matching **/*.+(html|md) will now be output to build/javascript/latest and their URLs will be served accordingly so the dev server will serve the site under /javascript/latest/.

This does have implications for relativeUrl thought. Since relativeUrl is the relative path back to the root of the build folder if you use { basePath: 'javascript/latest' } your relative URL from index.htmlwill now be ../../ instead of ``. To me this is expected behavior but it would be easily worked around with a transformer.

This is part of acetate@2.0.0-rc.2 which we are currently testing on the developers site but I hope to have a stable release soon.

jgravois commented 6 years ago

we've had success with the basePath option developing https://esri.github.io/arcgis-rest-js/

74 would make it possible to launch the browser to display the nested folder using CLI and close the loop on @lheberlie's request too (i think).