Skip to content

Commit fdf7b70

Browse files
bitbloxhubPi/GPT-5.6-Luna
andauthored
feat: add configurable hash location routing (#360)
Co-authored-by: Pi/GPT-5.6-Luna <gpt-5.6-luna@pi.local>
1 parent 90b23eb commit fdf7b70

4 files changed

Lines changed: 15 additions & 11 deletions

File tree

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@ There are two functions exposeed to build the directory containing the static se
1515

1616
| Name | Description | Available Options |
1717
|---|---|---|
18-
| `mkMultiSearch` | to build a search with multiple scopes (modules). | `baseHref`, `title` and `scopes` |
19-
| `mkSearch` | is a thin wrapper around `mkMultiSearch` to only use one scope (module). | `modules`, `optionsJSON`, `optionsPrefix`, `urlPrefix`, `baseHref` and `title` |
18+
| `mkMultiSearch` | to build a search with multiple scopes (modules). | `baseHref`, `title`, `hashLocation` and `scopes` |
19+
| `mkSearch` | is a thin wrapper around `mkMultiSearch` to only use one scope (module). | `modules`, `optionsJSON`, `optionsPrefix`, `urlPrefix`, `baseHref`, `title` and `hashLocation` |
2020

2121
### Explanation of options
2222

2323
| Name | Description |
2424
|---|---|
2525
| `baseHref` | The directory to where the search is going to be deployed relative to the domain. Defaults to `/`. |
2626
| `title` | The title on the top left. Defaults to `NüschtOS Search`. |
27+
| `hashLocation` | Use hash-based routing (`/#/...`) instead of path-based routing. Defaults to `false` and should be enabled when the web server or page provider does not automatically fall back to `index.html` or `404.html`. <br> For example, this can occur when embedding NüschtOS Search into a larger documentation site hosted on a static server that only serves the root `404.html`. Hash-based routing encodes URL path information in the URL hash instead, so the browser always requests `index.html`, regardless of the current page. |
2728
| `modules` | A list of NixOS modules as an attrset or file similar to the `nixosSystem` function. Exclusive with `optionsJSON`. |
2829
| `optionsJSON` | Path to a pre-generated `options.json` file. Exclusive with `modules`. |
2930
| `optionsPrefix` | A static prefix to append to all options. An extra `dot` is always appended. Defaults to being empty. |

nix/frontend.nix

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ stdenv.mkDerivation (finalAttrs: {
6262
mkdir -p $out
6363
cp -rL ./dist/browser/* $out/
6464
cp ./dist/3rdpartylicenses.txt $out
65-
# support for GitHub Pages
66-
cp $out/index.html $out/404.html
65+
${lib.optionalString (!config.hashLocation) ''
66+
# support for GitHub Pages and other 404.html-respecting static hosts
67+
cp $out/index.html $out/404.html
68+
''}
6769
runHook postInstall
6870
'';
6971

nix/wrapper.nix

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,15 @@ rec {
134134
'');
135135

136136
# also update README examples
137-
mkMultiSearch = { scopes, baseHref ? "/", title ? "NüschtOS Search" }@args:
137+
mkMultiSearch = { scopes, baseHref ? "/", title ? "NüschtOS Search", hashLocation ? false }@args:
138138
let
139139
chunkSize = 300;
140140
drv = nuscht-search {
141141
config =
142142
assert lib.assertMsg (lib.hasSuffix "/" baseHref) "baseHref needs a trailing slash";
143143
assert lib.assertMsg (lib.hasPrefix "/" baseHref) "baseHref needs to start with a slash";
144144
{
145-
inherit baseHref title chunkSize;
145+
inherit baseHref title hashLocation chunkSize;
146146
dataBase = "${baseHref}data/";
147147
scopes = map (scope: {
148148
inherit (scope) name;
@@ -158,11 +158,11 @@ rec {
158158
};
159159

160160
# also update README examples
161-
mkSearch = { baseHref ? "/", title ? "NüschtOS Search", ... }@args:
161+
mkSearch = { baseHref ? "/", title ? "NüschtOS Search", hashLocation ? false, ... }@args:
162162
let
163163
drv = mkMultiSearch {
164-
inherit baseHref title;
165-
scopes = [ ({ name = ""; } // (lib.removeAttrs args [ "baseHref" "title" ])) ];
164+
inherit baseHref title hashLocation;
165+
scopes = [ ({ name = ""; } // (lib.removeAttrs args [ "baseHref" "title" "hashLocation" ])) ];
166166
};
167167
in
168168
drv // {

src/app/app.config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { ApplicationConfig, provideBrowserGlobalErrorListeners, provideZoneChangeDetection } from '@angular/core';
2-
import { provideRouter } from '@angular/router';
2+
import { provideRouter, withHashLocation } from '@angular/router';
33

44
import { routes } from './app.routes';
5+
import { CONFIG } from './core/config.domain';
56
import { provideHttpClient, withFetch } from '@angular/common/http';
67

78
export const appConfig: ApplicationConfig = {
89
providers: [
910
provideBrowserGlobalErrorListeners(),
1011
provideZoneChangeDetection({ eventCoalescing: true }),
11-
provideRouter(routes),
12+
provideRouter(routes, ...(CONFIG.hashLocation ? [withHashLocation()] : [])),
1213
provideHttpClient(withFetch()),
1314
]
1415
};

0 commit comments

Comments
 (0)