From 2b5654a6c8a0402136ec1e222822f38931a88d1f Mon Sep 17 00:00:00 2001 From: Benson Cho <100653148+bcho892@users.noreply.github.com> Date: Sun, 21 Jul 2024 14:57:39 +1200 Subject: [PATCH] add robots and sitemap generation (#665) * add robots and sitemap generation * add link for icon * fix typo in tailwind config --- .../workflows/deploy-client-production.yml | 1 + client/environment.d.ts | 4 +-- client/next.config.mjs | 3 -- client/src/app/layout.tsx | 1 + client/src/app/robots.ts | 22 ++++++++++++++ client/src/app/sitemap.ts | 29 +++++++++++++++++++ client/tailwind.config.ts | 10 +++---- 7 files changed, 59 insertions(+), 11 deletions(-) create mode 100644 client/src/app/robots.ts create mode 100644 client/src/app/sitemap.ts diff --git a/.github/workflows/deploy-client-production.yml b/.github/workflows/deploy-client-production.yml index 01ed79d8c..3675c9cee 100644 --- a/.github/workflows/deploy-client-production.yml +++ b/.github/workflows/deploy-client-production.yml @@ -19,6 +19,7 @@ env: NEXT_PUBLIC_SANITY_PROJECT_ID: ${{secrets.PROD_SANITY_PROJECT_ID}} NEXT_PUBLIC_SANITY_DATASET: production NEXT_CONFIG_ENV: production + FRONTEND_BASE_URL: ${{secrets.PROD_FRONTEND_URL}} jobs: Deploy-Client: diff --git a/client/environment.d.ts b/client/environment.d.ts index b4c72ded3..f09613b58 100644 --- a/client/environment.d.ts +++ b/client/environment.d.ts @@ -21,12 +21,12 @@ declare global { readonly NEXT_PUBLIC_ENV_STRIPE_PUBLISHABLE_KEY: string /** Used for deployments */ readonly NEXT_CONFIG_ENV?: "production" | "staging" - /** What all paths should be prefixed with */ - readonly DEPLOYMENT_BASE_PATH?: string /** The project to fetch content from in sanity */ readonly NEXT_PUBLIC_SANITY_PROJECT_ID: string /** The dataset to use - for local use this should only be set to staging */ readonly NEXT_PUBLIC_SANITY_DATASET: "production" | "staging" + /** Used for `sitemap.xml` and `robots.txt` generation, should **NOT** include a trailing slash */ + readonly FRONTEND_BASE_URL: string } } } diff --git a/client/next.config.mjs b/client/next.config.mjs index 930a25b28..e8d0756a8 100644 --- a/client/next.config.mjs +++ b/client/next.config.mjs @@ -1,12 +1,9 @@ const env = process.env.NEXT_CONFIG_ENV || "development" -const customBasePath = process.env.DEPLOYMENT_BASE_PATH - const generateStatic = env === "staging" || env === "production" /** @type {import('next').NextConfig} */ const nextConfig = { - basePath: customBasePath, webpack(config) { config.module.rules.push({ test: /\.svg$/i, diff --git a/client/src/app/layout.tsx b/client/src/app/layout.tsx index ae8bd9a39..a585cb911 100644 --- a/client/src/app/layout.tsx +++ b/client/src/app/layout.tsx @@ -18,6 +18,7 @@ export default function RootLayout({ }>) { return ( +
{children}
diff --git a/client/src/app/robots.ts b/client/src/app/robots.ts new file mode 100644 index 000000000..b883f7e0d --- /dev/null +++ b/client/src/app/robots.ts @@ -0,0 +1,22 @@ +import { MetadataRoute } from "next" + +const FRONTEND_URL = process.env.FRONTEND_BASE_URL + +export default function robots(): MetadataRoute.Robots { + if (process.env.NEXT_CONFIG_ENV !== "production" || !FRONTEND_URL) { + return { + rules: { + disallow: "*" + } + } + } + + return { + rules: { + userAgent: "*", + allow: "/", + disallow: ["/admin/", "/profile"] + }, + sitemap: `${FRONTEND_URL}/sitemap.xml` + } +} diff --git a/client/src/app/sitemap.ts b/client/src/app/sitemap.ts new file mode 100644 index 000000000..23af422a0 --- /dev/null +++ b/client/src/app/sitemap.ts @@ -0,0 +1,29 @@ +import { MetadataRoute } from "next" + +const FRONTEND_URL = process.env.FRONTEND_BASE_URL + +export default function sitemap(): MetadataRoute.Sitemap { + if (process.env.NEXT_CONFIG_ENV !== "production" || !FRONTEND_URL) return [] + + return [ + { + url: FRONTEND_URL, + priority: 1 + }, + { + url: `${FRONTEND_URL}/about`, + priority: 2 + }, + { + url: `${FRONTEND_URL}/contact`, + priority: 3 + }, + { + url: `${FRONTEND_URL}/events` + }, + { + url: `${FRONTEND_URL}/login`, + priority: 4 + } + ] +} diff --git a/client/tailwind.config.ts b/client/tailwind.config.ts index ca1f9624a..c7748dbba 100644 --- a/client/tailwind.config.ts +++ b/client/tailwind.config.ts @@ -1,8 +1,6 @@ import type { Config } from "tailwindcss" import defaultTheme from "tailwindcss/defaultTheme" -const basePath = process.env.DEPLOYMENT_BASE_PATH || "" - const config: Config = { content: [ "./src/pages/**/*.{js,ts,jsx,tsx,mdx}", @@ -12,10 +10,10 @@ const config: Config = { theme: { extend: { backgroundImage: { - "home-ski-image": `url('${basePath}/images/homeLandingBackground.png')`, - "home-about-image": `url('${basePath}/images/AboutBackgroundImage.png')`, - "mountain-background-image": `url('${basePath}/images/MountainBackgroundImage.png')`, - "book-lodge-image": `url('${basePath}/images/BookLodgeBackgroundImage.png')` + "home-ski-image": `url('/images/homeLandingBackground.png')`, + "home-about-image": `url('/images/AboutBackgroundImage.png')`, + "mountain-background-image": `url('/images/MountainBackgroundImage.png')`, + "book-lodge-image": `url('/images/BookLodgeBackgroundImage.png')` }, fontFamily: { sans: ["Inter var", ...defaultTheme.fontFamily.sans]