feat: add seo title and favicon respecting basePath
This commit is contained in:
committed by
Mathias Schopmans
parent
57d7e85331
commit
554607a58d
Binary file not shown.
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 4.2 KiB |
7
src/lib/format.ts
Normal file
7
src/lib/format.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
// Format the title of the page
|
||||
import { getAppName } from "@/lib/data";
|
||||
|
||||
export function formatTitle(title: string = ""): string {
|
||||
if (!title) return getAppName();
|
||||
return `${title} | ${getAppName()}`;
|
||||
}
|
||||
@@ -1,5 +1,12 @@
|
||||
import { type ClassValue, clsx } from "clsx";
|
||||
|
||||
import config from "../../next.config.mjs";
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return clsx(inputs);
|
||||
}
|
||||
|
||||
export function assetUrl(path: string) {
|
||||
if (!config.basePath) return path;
|
||||
return `${config.basePath}${path}`;
|
||||
}
|
||||
|
||||
@@ -2,15 +2,20 @@ import Head from "next/head";
|
||||
import { useRouter } from "next/router";
|
||||
|
||||
import { getQuadrant, getQuadrants } from "@/lib/data";
|
||||
import { formatTitle } from "@/lib/format";
|
||||
import { CustomPage } from "@/pages/_app";
|
||||
|
||||
const QuadrantPage: CustomPage = () => {
|
||||
const { query } = useRouter();
|
||||
const quadrant = getQuadrant(query.quadrant as string);
|
||||
|
||||
if (!quadrant) return null;
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>Quadrant Page</title>
|
||||
<title>{formatTitle(quadrant.title)}</title>
|
||||
<meta name="description" content={quadrant.description} />
|
||||
</Head>
|
||||
|
||||
<h1>Quadrant: {query.quadrant}</h1>
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { NextPage } from "next";
|
||||
import type { AppProps } from "next/app";
|
||||
import Head from "next/head";
|
||||
|
||||
import { Layout, type LayoutClass } from "@/components/Layout/Layout";
|
||||
import { formatTitle } from "@/lib/format";
|
||||
import { assetUrl } from "@/lib/utils";
|
||||
import "@/styles/globals.css";
|
||||
|
||||
export type CustomPage<P = {}, IP = P> = NextPage<P, IP> & {
|
||||
@@ -14,8 +17,15 @@ type CustomAppProps = AppProps & {
|
||||
|
||||
export default function App({ Component, pageProps, router }: CustomAppProps) {
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>{formatTitle()}</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link rel="icon" href={assetUrl("/favicon.ico")} />
|
||||
</Head>
|
||||
<Layout layoutClass={Component.layoutClass}>
|
||||
<Component {...pageProps} key={router.asPath} />
|
||||
</Layout>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import Head from "next/head";
|
||||
|
||||
import { formatTitle } from "@/lib/format";
|
||||
import { CustomPage } from "@/pages/_app";
|
||||
|
||||
const HelpAndAbout: CustomPage = () => {
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>Help and About</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
<title>{formatTitle("Help and About")}</title>
|
||||
</Head>
|
||||
|
||||
<h1>Help and about</h1>
|
||||
|
||||
@@ -1,20 +1,7 @@
|
||||
import Head from "next/head";
|
||||
|
||||
import { CustomPage } from "@/pages/_app";
|
||||
|
||||
const Home: CustomPage = () => {
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>Create Next App</title>
|
||||
<meta name="description" content="Generated by create next app" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
</Head>
|
||||
|
||||
<h1>Hello world.</h1>
|
||||
</>
|
||||
);
|
||||
return <h1>Hello world.</h1>;
|
||||
};
|
||||
|
||||
export default Home;
|
||||
|
||||
Reference in New Issue
Block a user