* add ~platform/DocumentTitle * add titles for some pages
This commit is contained in:
parent
1115135380
commit
1c8a3f0bbb
12 changed files with 843 additions and 823 deletions
22
src/platform/DocumentTitle.tsx
Normal file
22
src/platform/DocumentTitle.tsx
Normal file
|
@ -0,0 +1,22 @@
|
|||
import { children, createRenderEffect, onCleanup, type JSX } from "solid-js";
|
||||
|
||||
/**
|
||||
* Document title.
|
||||
*
|
||||
* The `children` must be plain text.
|
||||
*/
|
||||
export default function (props: { children?: JSX.Element }) {
|
||||
let otitle: string | undefined;
|
||||
|
||||
createRenderEffect(() => (otitle = document.title));
|
||||
|
||||
const title = children(() => props.children);
|
||||
|
||||
createRenderEffect(
|
||||
() => (document.title = (title.toArray() as string[]).join("")),
|
||||
);
|
||||
|
||||
onCleanup(() => (document.title = otitle!));
|
||||
|
||||
return <></>;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue