Skip to content

Commit

Permalink
fix(curriculum): set document.title
Browse files Browse the repository at this point in the history
  • Loading branch information
caugner committed Jan 31, 2024
1 parent 3e46674 commit ef8a090
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
3 changes: 2 additions & 1 deletion client/src/curriculum/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { CurriculumModule } from "./module";
import "./index.scss";
import { TopNavigation } from "../ui/organisms/top-navigation";
import { ArticleActionsContainer } from "../ui/organisms/article-actions-container";
import { topic2css } from "./utils";
import { topic2css, useDocTitle } from "./utils";

export function Curriculum(appProps: HydrationData) {
return (
Expand Down Expand Up @@ -56,6 +56,7 @@ export function CurriculumLanding(props: HydrationData<any, CurriculumDoc>) {
}
);
const { doc }: { doc?: CurriculumDoc } = data || props || {};
useDocTitle(doc);
return (
<>
{doc && (
Expand Down
4 changes: 3 additions & 1 deletion client/src/curriculum/module.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Sidebar } from "./sidebar";
import { TopNavigation } from "../ui/organisms/top-navigation";
import { ArticleActionsContainer } from "../ui/organisms/article-actions-container";
import { TopicIcon } from "./topic-icon";
import { topic2css } from "./utils";
import { topic2css, useDocTitle } from "./utils";

export function CurriculumModule(props: HydrationData<any, CurriculumDoc>) {
const dataURL = `./index.json`;
Expand Down Expand Up @@ -38,6 +38,8 @@ export function CurriculumModule(props: HydrationData<any, CurriculumDoc>) {
}
);
const { doc }: { doc?: CurriculumDoc } = data || props || {};
useDocTitle(doc);

return (
<>
{doc && (
Expand Down
3 changes: 2 additions & 1 deletion client/src/curriculum/overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Sidebar } from "./sidebar";
import { ModulesList } from "./modules-list";
import { TopNavigation } from "../ui/organisms/top-navigation";
import { ArticleActionsContainer } from "../ui/organisms/article-actions-container";
import { topic2css } from "./utils";
import { topic2css, useDocTitle } from "./utils";

export function CurriculumModuleOverview(
props: HydrationData<any, CurriculumDoc>
Expand Down Expand Up @@ -39,6 +39,7 @@ export function CurriculumModuleOverview(
}
);
const { doc }: { doc?: CurriculumDoc } = data || props || {};
useDocTitle(doc);
return (
<>
{doc && (
Expand Down
17 changes: 17 additions & 0 deletions client/src/curriculum/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// Using this import fails the build...

import { useEffect } from "react";
import { CurriculumDoc } from "../../../libs/types/curriculum";

//import { Topic } from "../../../libs/types/curriculum";
export enum Topic {
WebStandards = "Web Standards & Semantics",
Expand All @@ -24,3 +28,16 @@ export function topic2css(topic?: Topic) {
return "none";
}
}

const TITLE_SUFFIX = "MDN Curriculum";
export function useDocTitle(doc?: CurriculumDoc) {
useEffect(() => {
if (!doc) {
return;
}
document.title =
doc.title && doc.title !== TITLE_SUFFIX
? `${doc.title} | MDN Curriculum`
: "MDN Curriculum";
}, [doc]);
}

0 comments on commit ef8a090

Please sign in to comment.