Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions dev/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ export default defineConfig({
},
{
version: "v1",
route: {
version: {
v1: { label: "v1 (legacy)" },
},
},

title: "SolidBase v1 Demo",
themeConfig: {
sidebar: {
Expand Down
7 changes: 6 additions & 1 deletion docs/src/routes/guide/(2)config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,17 @@ overrides: [
{
project: "solidbase",
version: "v1",
route: {
version: {
v1: { label: "v1 (legacy)" },
},
},
},
],
// ..
```

Route override selectors use route axis names. Override config is applied over the base config, and `themeConfig` is shallow-merged with the base `themeConfig`.
Route override selectors use route axis names. Override config is applied over the base config, and `themeConfig` is shallow-merged with the base `themeConfig`. Use the `route` key to patch route axis value metadata for a matching route — for example, renaming a version's `label` only when browsing that version's routes. Route value patches cannot change `path`, `href`, or `lang`; those are fixed by the `routes` config.

#### Miscellaneous options

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Version switcher for sites that configure `routes.version`.

- omitted when fewer than two version options are available
- uses Kobalte `Popover`
- applies `route` override patches from the resolved config to version labels
- displays each version option's `meta.label` when provided, otherwise the option name
- navigates to the selected version's route root
- scopes available versions to the current project
Expand Down
8 changes: 7 additions & 1 deletion docs/src/routes/reference/runtime-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,16 @@ function useSolidBaseRoutes(): {
axis: string,
selection?: Partial<SolidBaseRouteSelection>,
): SolidBaseRouteOption[];
routeOverride: Accessor<SolidBaseRouteValueOverride>;
};

type SolidBaseRouteSelection = Record<string, string>;

type SolidBaseRouteValueOverride = Record<
string,
Record<string, SolidBaseRouteValueConfig>
>;

type SolidBaseRouteOption = {
name: string;
axis: string;
Expand All @@ -166,7 +172,7 @@ type SolidBaseRouteOption = {
};
```

`current()` returns the active route axis values for the current pathname. `path(...)` returns an internal route prefix for the provided partial selection merged over the current selection. `options(...)` returns valid options for an axis and filters internal values through `routes.include`.
`current()` returns the active route axis values for the current pathname. `path(...)` returns an internal route prefix for the provided partial selection merged over the current selection. `options(...)` returns valid options for an axis and filters internal values through `routes.include`. `routeOverride()` returns the merged `route` override patches for the current selection, applied to the `meta` of options.

### `useSolidBaseRoute`

Expand Down
11 changes: 10 additions & 1 deletion src/client/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { solidBaseConfig } from "virtual:solidbase/config";
import { type Accessor, createMemo } from "solid-js";

import type { SolidBaseResolvedConfig } from "../config/index.js";
import { resolveSolidBaseRouteConfig } from "../config/route-config.js";
import {
resolveSolidBaseRouteConfig,
resolveSolidBaseRouteValueOverrides,
} from "../config/route-config.js";
import { useLocale } from "./locale.js";
import { useSolidBaseRoute } from "./routes.js";

Expand All @@ -18,10 +21,16 @@ export function useRouteSolidBaseConfig<ThemeConfig>(): Accessor<
currentRoute(),
);
const localeConfig = currentLocale().config.themeConfig ?? {};
const routeOverride = resolveSolidBaseRouteValueOverrides(
solidBaseConfig.routes,
solidBaseConfig.overrides ?? [],
currentRoute(),
);

return {
...routeConfig,
themeConfig: { ...routeConfig.themeConfig, ...localeConfig },
routeOverride,
};
});
}
21 changes: 17 additions & 4 deletions src/client/locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getSolidBaseRouteOptions,
getSolidBaseRoutePathWithRest,
getSolidBaseRouteSelectionForPath,
resolveSolidBaseRouteValueOverrides,
type SolidBaseRouteOption,
} from "../config/route-config.js";
import { useSolidBaseRoutes } from "./routes.js";
Expand Down Expand Up @@ -113,10 +114,22 @@ function getRouteLocaleForPath(path: string) {
const value = selection?.[LOCALE_AXIS];
if (!value) return undefined;

const option = getSolidBaseRouteOptions(solidBaseConfig.routes, LOCALE_AXIS, {
...selection,
[LOCALE_AXIS]: value,
}).find((option) => option.name === value);
const option = getSolidBaseRouteOptions(
solidBaseConfig.routes,
LOCALE_AXIS,
{
...selection,
[LOCALE_AXIS]: value,
},
resolveSolidBaseRouteValueOverrides(
solidBaseConfig.routes,
solidBaseConfig.overrides ?? [],
{
...selection,
[LOCALE_AXIS]: value,
},
),
).find((option) => option.name === value);

return option ? routeOptionToLocale(option) : undefined;
}
Expand Down
10 changes: 10 additions & 0 deletions src/client/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getSolidBaseRouteOptions,
getSolidBaseRouteSelectionForPath,
normalizeSolidBaseRouteSelection,
resolveSolidBaseRouteValueOverrides,
type SolidBaseRouteOption,
type SolidBaseRouteSelection,
} from "../config/route-config.js";
Expand All @@ -24,6 +25,13 @@ const [SolidBaseRoutesContextProvider, useSolidBaseRoutesContext] =
normalizeSolidBaseRouteSelection(solidBaseConfig.routes) ??
{},
);
const routeOverride = createMemo(() =>
resolveSolidBaseRouteValueOverrides(
solidBaseConfig.routes,
solidBaseConfig.overrides ?? [],
current(),
),
);

return {
routes: solidBaseConfig.routes,
Expand All @@ -38,7 +46,9 @@ const [SolidBaseRoutesContextProvider, useSolidBaseRoutesContext] =
solidBaseConfig.routes,
axis,
selection ?? current(),
routeOverride(),
),
routeOverride,
};
});

Expand Down
25 changes: 20 additions & 5 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@ import type { PluginOption } from "vite";
import defaultTheme from "../default-theme/index.js";
import { type MdxOptions, solidBaseMdx } from "./mdx.js";
import type { IssueAutoLinkConfig } from "./remark-plugins/issue-autolink.js";
import type { SolidBaseRoutesConfig } from "./route-config.js";
import type {
SolidBaseRoutesConfig,
SolidBaseRouteValueOverride,
SolidBaseRouteValueOverrideConfig,
} from "./route-config.js";
import { validateSolidBaseRoutesConfig as validateRoutes } from "./route-config.js";
import solidBaseVitePlugin from "./vite-plugin/index.js";

export type { SolidBaseRouteOption } from "./route-config.js";
export type {
SolidBaseRouteOption,
SolidBaseRouteValueOverride,
SolidBaseRouteValueOverrideConfig,
} from "./route-config.js";
export { getSolidBaseRouteFallbackOptions } from "./route-config.js";

const SOLID_BASE_OVERRIDE_CONFIG_KEYS = [
Expand All @@ -26,6 +34,7 @@ const SOLID_BASE_OVERRIDE_CONFIG_KEYS = [
"issueAutolink",
"lang",
"locales",
"route",
"themeConfig",
"editPath",
"lastUpdated",
Expand Down Expand Up @@ -73,7 +82,9 @@ export type SolidBaseResolvedConfig<ThemeConfig> = Omit<
SolidBaseConfig<ThemeConfig>,
ResolvedConfigKeys
> &
Required<Pick<SolidBaseConfig<ThemeConfig>, ResolvedConfigKeys>>;
Required<Pick<SolidBaseConfig<ThemeConfig>, ResolvedConfigKeys>> & {
routeOverride?: SolidBaseRouteValueOverride;
};

export type LocaleConfig<ThemeConfig> = {
label: string;
Expand All @@ -84,8 +95,12 @@ export type LocaleConfig<ThemeConfig> = {

export type SolidBaseRouteOverride<ThemeConfig> = Partial<
Omit<SolidBaseConfig<ThemeConfig>, "routes" | "overrides">
> &
Record<string, unknown>;
> & {
route?: Record<
string,
Record<string, SolidBaseRouteValueOverrideConfig | string>
>;
} & Record<string, unknown>;

export type SitemapConfig = {
hostname?: string;
Expand Down
Loading
Loading