Skip to content

Commit aca3ba9

Browse files
Added Metadata for dynamic pages and static pages (#1414)
* Added metadata in next js * pre-commit * updated jest config * fixed e2e * removed unused * make layout names look consistent * sonarcloud bugs * cr suggestion * bugs * bugs with unknown letter * Update code * Update code * optimised query and fixed e2e by mocking server * fixed e2e * fixed params * fixed bugs * Update code * Update code --------- Co-authored-by: Arkadii Yakovets <[email protected]>
1 parent f0ecf4d commit aca3ba9

File tree

32 files changed

+603
-3
lines changed

32 files changed

+603
-3
lines changed

.github/workflows/run-ci-cd.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ jobs:
259259
echo "NEXT_PUBLIC_IDX_URL=${{ secrets.VITE_IDX_URL }}" >> frontend/.env
260260
echo "NEXT_PUBLIC_RELEASE_VERSION=${{ github.event.release.tag_name }}" >> frontend/.env
261261
echo "NEXT_PUBLIC_SENTRY_DSN=${{ secrets.VITE_SENTRY_DSN }}" >> frontend/.env
262+
echo "NEXT_SERVER_CSRF_URL=${{ secrets.NEXT_SERVER_CSRF_URL }}" >> frontend/.env
263+
echo "NEXT_SERVER_GRAPHQL_URL=${{ secrets.NEXT_SERVER_GRAPHQL_URL }}" >> frontend/.env
262264
263265
- name: Build frontend image
264266
uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1
@@ -431,6 +433,8 @@ jobs:
431433
echo "NEXT_PUBLIC_IDX_URL=${{ secrets.VITE_IDX_URL }}" >> frontend/.env
432434
echo "NEXT_PUBLIC_RELEASE_VERSION=${{ github.event.release.tag_name }}" >> frontend/.env
433435
echo "NEXT_PUBLIC_SENTRY_DSN=${{ secrets.VITE_SENTRY_DSN }}" >> frontend/.env
436+
echo "NEXT_SERVER_CSRF_URL=${{ secrets.NEXT_SERVER_CSRF_URL }}" >> frontend/.env
437+
echo "NEXT_SERVER_GRAPHQL_URL=${{ secrets.NEXT_SERVER_GRAPHQL_URL }}" >> frontend/.env
434438
435439
- name: Build frontend image
436440
uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1

frontend/.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ NEXT_PUBLIC_GTM_PREVIEW=
88
NEXT_PUBLIC_IDX_URL=http://localhost:8000/idx/
99
NEXT_PUBLIC_RELEASE_VERSION=
1010
NEXT_PUBLIC_SENTRY_DSN=
11+
NEXT_SERVER_CSRF_URL=http://backend:8000/csrf/
12+
NEXT_SERVER_DISABLE_SSR=false
13+
NEXT_SERVER_GRAPHQL_URL=http://backend:8000/graphql/

frontend/jest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const config: Config = {
66
'src/**/*.{js,jsx,ts,tsx}',
77
'!src/**/*.d.ts',
88
'!src/api/**',
9-
'!src/app/layout.tsx',
9+
'!src/app/**/layout.tsx',
1010
'!src/components/**',
1111
'!src/hooks/**',
1212
'!src/instrumentation.ts',

frontend/playwright.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default defineConfig({
2626
trace: 'off',
2727
},
2828
webServer: {
29-
command: 'pnpm run build:turbo && pnpm run start',
29+
command: 'pnpm run build:turbo && NEXT_SERVER_DISABLE_SSR=true pnpm run start',
3030
timeout: 120_000,
3131
url: 'http://localhost:3000',
3232
},

frontend/src/app/about/layout.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Metadata } from 'next'
2+
import React from 'react'
3+
import { getStaticMetadata } from 'utils/metaconfig'
4+
5+
export const metadata: Metadata = getStaticMetadata('about', '/about')
6+
7+
export default function AboutLayout({ children }: { children: React.ReactNode }) {
8+
return children
9+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Metadata } from 'next'
2+
import React from 'react'
3+
import { apolloClient } from 'server/apolloClient'
4+
import { GET_CHAPTER_METADATA } from 'server/queries/chapterQueries'
5+
import { generateSeoMetadata } from 'utils/metaconfig'
6+
7+
export async function generateMetadata({
8+
params,
9+
}: {
10+
params: Promise<{ chapterKey: string }>
11+
}): Promise<Metadata> {
12+
const { chapterKey } = await params
13+
const { data } = await apolloClient.query({
14+
query: GET_CHAPTER_METADATA,
15+
variables: {
16+
key: chapterKey,
17+
},
18+
})
19+
const chapter = data?.chapter
20+
21+
return chapter
22+
? generateSeoMetadata({
23+
canonicalPath: `/chapters/${chapterKey}`,
24+
description: chapter.summary ?? `${chapter.name} chapter details`,
25+
keywords: ['owasp', 'security', 'chapter', chapterKey, chapter.name],
26+
title: chapter.name,
27+
})
28+
: null
29+
}
30+
31+
export default function ChapterDetailsLayout({
32+
children,
33+
}: Readonly<{ children: React.ReactNode }>) {
34+
return children
35+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Metadata } from 'next'
2+
import React from 'react'
3+
import { getStaticMetadata } from 'utils/metaconfig'
4+
5+
export const metadata: Metadata = getStaticMetadata('chapters', '/chapters')
6+
7+
export default function ChaptersLayout({ children }: { children: React.ReactNode }) {
8+
return children
9+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { Metadata } from 'next'
2+
import React from 'react'
3+
import { apolloClient } from 'server/apolloClient'
4+
import { GET_COMMITTEE_METADATA } from 'server/queries/committeeQueries'
5+
import { generateSeoMetadata } from 'utils/metaconfig'
6+
7+
export async function generateMetadata({
8+
params,
9+
}: {
10+
params: Promise<{ committeeKey: string }>
11+
}): Promise<Metadata> {
12+
const { committeeKey } = await params
13+
const { data } = await apolloClient.query({
14+
query: GET_COMMITTEE_METADATA,
15+
variables: {
16+
key: committeeKey,
17+
},
18+
})
19+
const committee = data?.committee
20+
21+
return committee
22+
? generateSeoMetadata({
23+
canonicalPath: `/committees/${committeeKey}`,
24+
description: committee.summary ?? `${committee.name} details`,
25+
keywords: ['owasp', 'security', 'committee', committeeKey, committee.name],
26+
title: committee.name,
27+
})
28+
: null
29+
}
30+
31+
export default function CommitteeDetailsLayout({
32+
children,
33+
}: Readonly<{
34+
children: React.ReactNode
35+
}>) {
36+
return children
37+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Metadata } from 'next'
2+
import React from 'react'
3+
import { getStaticMetadata } from 'utils/metaconfig'
4+
5+
export const metadata: Metadata = getStaticMetadata('committees', '/committees')
6+
7+
export default function CommitteesLayout({ children }: { children: React.ReactNode }) {
8+
return children
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import React from 'react'
2+
import { getStaticMetadata } from 'utils/metaconfig'
3+
4+
export const metadata = getStaticMetadata('contribute', '/contribute')
5+
6+
export default function ContributeLayout({ children }: { children: React.ReactNode }) {
7+
return children
8+
}

0 commit comments

Comments
 (0)