Skip to content

Show proper title based on project #1170

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

Merged
merged 3 commits into from
May 1, 2025
Merged
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
5 changes: 4 additions & 1 deletion src/solidbase-theme/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ import { I18nProvider } from "~/i18n/i18n-context";
import { Title } from "@solidjs/meta";
import { useThemeListener } from "@kobalte/solidbase/client";
import { usePace } from "@kobalte/solidbase/default-theme/pace.js";
import { useProjectTitle } from "~/ui/use-project-title";

export default function (props: RouteSectionProps) {
useThemeListener();
usePace();

const projectTitle = useProjectTitle();

return (
<I18nProvider>
<Title>Solid Docs</Title>
<Title>{projectTitle()}</Title>
<ErrorBoundary fallback={() => <NotFound />}>
<Layout>{props.children}</Layout>
</ErrorBoundary>
Expand Down
4 changes: 3 additions & 1 deletion src/ui/docs-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { coreEntries } from "solid:collection";
import { Pagination } from "~/ui/pagination";
import { EditPageLink } from "./edit-page-link";
import { PageIssueLink } from "./page-issue-link";
import { useProjectTitle } from "./use-project-title";

interface DocsLayoutProps {
entries: typeof coreEntries;
Expand All @@ -13,6 +14,7 @@ interface DocsLayoutProps {

export const DocsLayout = (props: DocsLayoutProps) => {
const location = useLocation();
const projectTitle = useProjectTitle();

const collection = () =>
location.pathname.includes("/reference/")
Expand Down Expand Up @@ -40,7 +42,7 @@ export const DocsLayout = (props: DocsLayoutProps) => {
<Show when={props.entries} keyed>
<>
<Show when={titles()?.title} fallback={<Title>SolidDocs</Title>}>
{(title) => <Title>{`${title()} - SolidDocs`}</Title>}
{(title) => <Title>{`${title()} - ${projectTitle()}`}</Title>}
</Show>
<div id="rr" class="flex relative justify-center">
<article class="w-fit overflow-hidden pb-16 lg:px-5 expressive-code-overrides lg:max-w-none">
Expand Down
5 changes: 4 additions & 1 deletion src/ui/not-found.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import { Title } from "@solidjs/meta";
import { Layout } from "./layout";
import { HttpStatusCode } from "@solidjs/start";
import { A } from "~/ui/i18n-anchor";
import { useProjectTitle } from "./use-project-title";

export function NotFound() {
const projectTitle = useProjectTitle();

return (
<>
<Title>404 - SolidDocs</Title>
<Title>Not Found - {projectTitle()}</Title>
<Layout isError>
<HttpStatusCode code={404} />
<div class="flex flex-col items-center">
Expand Down
35 changes: 35 additions & 0 deletions src/ui/use-project-title.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { type Accessor, createEffect, createSignal } from "solid-js";
import { useMatch } from "@solidjs/router";

const SOLID_START_TITLE = "SolidStart Docs";
const SOLID_ROUTER_TITLE = "Solid Router Docs";
const SOLID_META_TITLE = "Solid Meta Docs";
const SOLID_TITLE = "Solid Docs";

type ProjectTitle =
| typeof SOLID_START_TITLE
| typeof SOLID_ROUTER_TITLE
| typeof SOLID_META_TITLE
| typeof SOLID_TITLE;

export function useProjectTitle(): Accessor<ProjectTitle> {
const [title, setTitle] = createSignal<ProjectTitle>(SOLID_TITLE);

const isStart = useMatch(() => "/solid-start/*");
const isRouter = useMatch(() => "/solid-router/*");
const isMeta = useMatch(() => "/solid-meta/*");

createEffect(() => {
if (isStart()) {
setTitle(SOLID_START_TITLE);
} else if (isRouter()) {
setTitle(SOLID_ROUTER_TITLE);
} else if (isMeta()) {
setTitle(SOLID_META_TITLE);
} else {
setTitle(SOLID_TITLE);
}
});

return title;
}