From 7951a4152d0095e6c3d9adb4fd19166058b9c96d Mon Sep 17 00:00:00 2001 From: Maximilian Franzke <787658+mfranzke@users.noreply.github.com> Date: Wed, 21 Sep 2022 19:28:22 +0200 Subject: [PATCH] refactor: make removing index.html from URL configurable (#1428) * refactor: providing the configurability for whether to remove index.html from the URL #1427 * docs(configuration): added entry for noIndexHtmlremoval --- packages/docs/src/docs/advanced-config-options.md | 8 ++++++++ .../src/scripts/lit-components/pl-viewport/pl-viewport.js | 8 ++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/docs/src/docs/advanced-config-options.md b/packages/docs/src/docs/advanced-config-options.md index 89b00e645..bc74c780b 100644 --- a/packages/docs/src/docs/advanced-config-options.md +++ b/packages/docs/src/docs/advanced-config-options.md @@ -113,6 +113,14 @@ This replaces the now obsolete `debug` flag. **default**: `info` +## noIndexHtmlremoval (optional) + +You might host your pattern lab in an environment that doesn't acknowledge the default file to be `index.html` in case that none is provided – Gitlab Pages is an example for this, where you might publish your preview builds to during development. So in case that you get a URL like `/index.html`, it will redirect to `/?p=all`. You might not be able to share this resulting URL or even do a refresh of the page, as the server would respond with a 404 error. + +To disable this redirect which is similar to how Single Page Applications work, you could set the optional configuration `"noIndexHtmlremoval"` to `true`. + +**default**: `false` + ## outputFileSuffixes Sets the naming of output pattern files. Suffixes are defined for 'rendered', 'rawTemplate', and 'markupOnly' files. This configuration is needed for some PatternEngines that use the same input and output file extensions. Most users will not have to change this. diff --git a/packages/uikit-workshop/src/scripts/lit-components/pl-viewport/pl-viewport.js b/packages/uikit-workshop/src/scripts/lit-components/pl-viewport/pl-viewport.js index 0e778de01..ffbef44d7 100644 --- a/packages/uikit-workshop/src/scripts/lit-components/pl-viewport/pl-viewport.js +++ b/packages/uikit-workshop/src/scripts/lit-components/pl-viewport/pl-viewport.js @@ -152,7 +152,9 @@ class IFrame extends BaseLitComponent { : window.location.protocol + '//' + window.location.host + - window.location.pathname.replace('index.html', '') + + (window.config.noIndexHtmlremoval + ? window.location.pathname + : window.location.pathname.replace('index.html', '')) + '?p=' + currentPattern; @@ -512,7 +514,9 @@ class IFrame extends BaseLitComponent { : window.location.protocol + '//' + window.location.host + - window.location.pathname.replace('index.html', '') + + (window.config.noIndexHtmlremoval + ? window.location.pathname + : window.location.pathname.replace('index.html', '')) + '?p=' + currentPattern;