Repository navigation
feat(pages): allow titleTemplate in middleware headDefaults
#797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
15d5e38
b6b9378
8139923
06f053a
7f9198f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,14 +17,14 @@ export type HeadConfig = HeadDescriptor & { | |
| /** | ||
| * Merge head descriptors with precedence: page > middleware > config. | ||
| * | ||
| * - `title`: page wins; `titleTemplate` from config wraps it (`%s` replaced) | ||
| * - `title`: page wins; `titleTemplate` from middleware, else config, wraps it (`%s` replaced) | ||
| * - `meta`: page overrides entries with same `name`/`property`; others appended | ||
| * - `link`/`script`: concatenated (config first, then middleware, then page) | ||
| * - `htmlAttrs`/`bodyAttrs`: shallow merge, page wins conflicts | ||
| */ | ||
| export function resolveHead( | ||
| configHead: HeadConfig | undefined, | ||
| middlewareHead: HeadDescriptor | undefined, | ||
| middlewareHead: HeadConfig | undefined, | ||
| pageHead: HeadDescriptor | undefined, | ||
| ): HeadDescriptor | undefined { | ||
| if (!configHead && !middlewareHead && !pageHead) { | ||
|
|
@@ -36,7 +36,7 @@ export function resolveHead( | |
|
|
||
| const title = pageHead?.title ?? middlewareHead?.title ?? configHead?.title; | ||
| if (title !== undefined) { | ||
| const template = configHead?.titleTemplate; | ||
| const template = middlewareHead?.titleTemplate ?? configHead?.titleTemplate; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no way to drop the site-wide suffix for a section. Two small additions would cover it:
I placed them in suggestions |
||
| result.title = template ? template.replace('%s', title) : title; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import type { Context, Env, MiddlewareHandler, Next, TypedResponse } from 'hono'; | ||
| import type { RedirectStatusCode } from 'hono/utils/http-status'; | ||
| import type { RewriteDestination, RouteDestination, RouteUrl, RouteUrlInput } from 'void/routes'; | ||
| import type { HeadDescriptor } from '../pages/head.ts'; | ||
| import type { HeadConfig, HeadDescriptor } from '../pages/head.ts'; | ||
| import type { AuthSession, AuthUser } from './auth.ts'; | ||
| import { base64ToBytes } from './base64.ts'; | ||
| import { executeComposedHandler, setHandlerComposition } from './handler-composition.ts'; | ||
|
|
@@ -36,7 +36,7 @@ type RewritePath = TypedRoutes extends true ? RouteUrl : RewriteDestination; | |
| export interface CloudContextVariables { | ||
| user: AuthUser | null; | ||
| session: AuthSession | null; | ||
| headDefaults?: HeadDescriptor; | ||
| headDefaults?: HeadConfig; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| [key: string]: unknown; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.