Documentation links change from the "server" mode and "build" mode.
When linking related documentation pages together using markdown, the links will either work in "server" mode, or "build" mode, but not both.
Given these pages in the docs/ folder:
01-getting-started.md
02-change-log.md
When running in "server" mode, a link from the first page to the second is written as: [Change Log](./change_log).
When running in "build" mode, a link from the first page to the second is written as: [Change Log](./change_log.html)
docs/ folder (i.e. "01-getting-started.md" and "02-change-log.md")[Change Log](./change-log).Conversely:
docs/ folder (i.e. "01-getting-started.md" and "02-change-log.md")[Change Log](./change-log.html).Expected behavior: Links from the "server" mode and "build" mode will be consistent, and don't require re-writing, depending on the way that fractal is run.
Actual behavior: Links from the "server" mode and "build" mode must be written differently, meaning that either the links don't work during development, or the links don't work in the published static site.
Reproduces how often: 100%
Reduced test case: https://gist.github.com/dzwarg/f555265c7ba1ba789d458dbc578382ea
I guess the build mecanism should be refactored to output components as index.html files into sub-folders to avoid having to add the .html extension…
In the meantime, I suggest you create a custom method for the templating language of your choice to dynamically build one or the other based on the Node environment. Here's an example as a Nunjucks filter:
link(handle) {
const name = handle.replace('@', '');
let prefix = '';
let ext = '';
if (process.env.NODE_ENV === 'production') {
prefix = '../..';
ext = '.html';
}
return `<a href="${prefix}/components/detail/${name}${ext}">${handle}</a>`;
},
You can then add a link to a component with {{ '@my-component-handle' | link }}, for example in you components notes or in docs.
See Nunjucks adapter docs on how to configure a custom filter.
Also note that this requires your Node environment to be properly set when running Fractal commands. For example:
$ NODE_ENV=production fractal build
My worry with the proposed feature is that it's a big change. Arguably a BC breaking change. It's something that _could_ potentially be hidden behind a configuration option, but I'm a bit wary that configuring Fractal is already a bit opaque (in that it differs from the way you configure _most_ other Node apps), and adding more options adds overhead.
I think that _in general_ a better way to link between docs/components would be a good compromise. Maybe we could leverage the current handle system, so something like [Foo](@foo) could be re-written to the correct URL. This would also allow components to be moved without docs breaking. The fact that it's an invalid link _may_ be a concern, but bearing in mind that these links won't work _anyway_ until Fractal is either built, or running in server mode - maybe that doesn't matter?
Was just trying to find a solution to this, being able to leverage the handle system would be very helpful!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Reopened this since this is actually a bug in core.
In order to get the correct URLs, you should use the path helper that's been provided by most official adapters. For example, with the default handlebars adapter, [Change Log]({{path './change_log'}}) should do the trick.
However, the core utility function that the path helpers in adapters use, returns early for relative paths. This is a bug, since even relative paths should be appended with the proper file extension.
Most helpful comment
My worry with the proposed feature is that it's a big change. Arguably a BC breaking change. It's something that _could_ potentially be hidden behind a configuration option, but I'm a bit wary that configuring Fractal is already a bit opaque (in that it differs from the way you configure _most_ other Node apps), and adding more options adds overhead.
I think that _in general_ a better way to link between docs/components would be a good compromise. Maybe we could leverage the current handle system, so something like
[Foo](@foo)could be re-written to the correct URL. This would also allow components to be moved without docs breaking. The fact that it's an invalid link _may_ be a concern, but bearing in mind that these links won't work _anyway_ until Fractal is either built, or running in server mode - maybe that doesn't matter?