Skip to content

Commit

Permalink
Fixup! Generate metadata for 404 pages.
Browse files Browse the repository at this point in the history
  • Loading branch information
sherakama committed Nov 26, 2024
1 parent 9c4c8a9 commit 2f11357
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
23 changes: 22 additions & 1 deletion app/(storyblok)/[[...slug]]/not-found.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import { components as Components } from '@/components/StoryblokProvider';
import { resolveRelations } from '@/utilities/resolveRelations';
import { ComponentNotFound } from '@/components/Storyblok/ComponentNotFound';
import { getStoryDataCached } from '@/utilities/data/getStoryData';
import { getConfigBlokCached } from '@/utilities/data/getConfigBlok';
import { getSlugPrefix } from '@/utilities/getSlugPrefix';
import { getPageMetadata } from '@/utilities/getPageMetadata';
import { Metadata } from 'next';

// Storyblok bridge options.
const bridgeOptions = {
Expand All @@ -30,11 +34,28 @@ storyblokInit({
},
});

/**
* Generate the SEO metadata for the page.
*/
export async function generateMetadata(): Promise<Metadata> {

const slugPrefix = getSlugPrefix();
const prefixedSlug = slugPrefix + '/page-not-found';
const config = await getConfigBlokCached();

// Get the story data.
const { data: { story } } = await getStoryDataCached({ path: prefixedSlug });

// Generate the metadata.
const meta = getPageMetadata({ story, sbConfig: config, slug: prefixedSlug });
return meta;
}

/**
* Get the story data from the Storyblok API through the cache.
*/
export default async function PageNotFound() {
const { data } = await getStoryDataCached({ path: 'momentum/page-not-found'});
const { data } = await getStoryDataCached({ path: 'momentum/page-not-found' });

if (data === 404) {
return (
Expand Down
23 changes: 23 additions & 0 deletions app/not-found.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import { components as Components } from '@/components/StoryblokProvider';
import { resolveRelations } from '@/utilities/resolveRelations';
import { ComponentNotFound } from '@/components/Storyblok/ComponentNotFound';
import { isProduction } from '@/utilities/getActiveEnv';
import { getSlugPrefix } from '@/utilities/getSlugPrefix';
import { Metadata } from 'next';
import { getStoryDataCached } from '@/utilities/data/getStoryData';
import { getConfigBlokCached } from '@/utilities/data/getConfigBlok';
import { getPageMetadata } from '@/utilities/getPageMetadata';

// Storyblok bridge options.
const bridgeOptions = {
Expand Down Expand Up @@ -58,6 +63,24 @@ async function getStoryData(slug = 'momentum/page-not-found') {
}
};

/**
* Generate the SEO metadata for the page.
*/
export async function generateMetadata(): Promise<Metadata> {

const slugPrefix = getSlugPrefix();
const prefixedSlug = slugPrefix + '/page-not-found';
const config = await getConfigBlokCached();


// Get the story data.
const { data: { story } } = await getStoryDataCached({ path: prefixedSlug });

// Generate the metadata.
const meta = getPageMetadata({ story, sbConfig: config, slug: prefixedSlug });
return meta;
}

export default async function PageNotFound() {
const { data } = await getStoryData();

Expand Down
2 changes: 1 addition & 1 deletion utilities/data/getConfigBlok.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const getConfigBlok = async () => {

// Get the global configuration.
const { data: { story: config } } = await storyblokApi.get(
'cdn/stories/tour/global-components/configuration/site-configuration',
'cdn/stories/momentum/global-components/configuration/site-configuration',
{
version: isProd ? 'published' : 'draft',
token: process.env.STORYBLOK_ACCESS_TOKEN,
Expand Down

0 comments on commit 2f11357

Please sign in to comment.