Skip to content

Commit

Permalink
add robots and sitemap generation (#665)
Browse files Browse the repository at this point in the history
* add robots and sitemap generation

* add link for icon

* fix typo in tailwind config
  • Loading branch information
choden-dev authored Jul 21, 2024
1 parent f9e0568 commit 2b5654a
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 11 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy-client-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions client/environment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions client/next.config.mjs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
1 change: 1 addition & 0 deletions client/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default function RootLayout({
}>) {
return (
<html lang="en">
<link rel="icon" href="/favicon.ico" sizes="any" />
<body className={inter.className}>
<AppNavbar />
<div className="pt-[51px]">{children}</div>
Expand Down
22 changes: 22 additions & 0 deletions client/src/app/robots.ts
Original file line number Diff line number Diff line change
@@ -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`
}
}
29 changes: 29 additions & 0 deletions client/src/app/sitemap.ts
Original file line number Diff line number Diff line change
@@ -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
}
]
}
10 changes: 4 additions & 6 deletions client/tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -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}",
Expand All @@ -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]
Expand Down

0 comments on commit 2b5654a

Please sign in to comment.