Skip to content

Commit

Permalink
fix: support dynamic page titles
Browse files Browse the repository at this point in the history
  • Loading branch information
nanochromatic committed Aug 18, 2024
1 parent 5673fb2 commit b2dbc98
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { ThemeIcon } from './components/ThemeIcon';
import PlaylistPage from './pages/PlaylistPage';
import PlaylistBuilderPage from './pages/PlaylistBuilderPage';
import HotPage from './pages/HotPage';
import { startCase } from 'lodash-es';

const history = createBrowserHistory();

Expand Down Expand Up @@ -211,18 +212,17 @@ const Footer = (): ReactElement => {
};

const siteTitle = 'MapleStory Music - BGM & OST Database';
const pageTitles: { [name: string]: string } = {
'/': siteTitle,
'/playlist': `${siteTitle} - Playlist`,
'/stats': `${siteTitle} - Stats`,
'/about': `${siteTitle} - About`,
'/playlist-builder': `${siteTitle} - Playlist Builder`,
const getPageTitle = (path: string): string => {
if (path === '/') {
return siteTitle;
}
return `${siteTitle} | ${startCase(path)}`;
};

const Main = (): ReactElement => {
const location = useLocation();
useEffect(() => {
document.title = pageTitles[location.pathname] ?? siteTitle;
document.title = getPageTitle(location.pathname);
}, [location]);
return (
<main>
Expand Down

0 comments on commit b2dbc98

Please sign in to comment.