SEO Metadata Configuration
Overview
The getSEOConfig
is a utility function for generating Search Engine Optimization (SEO) metadata. You get default metadata for all pages and optionally you can customize it with parameters.
This utility depends on the settings.js
file, located at @/settings
. Ensure this file contains the correct values.
File Location
/utils/seo.js
Function Signature
export const getSEOConfig = ({
title,
description,
keywords,
twitterProfile,
author,
canonicalRelativeURL
} = {}) => { ... }
Usage
In Root Layout
The Root Layout in the location app/layout.js
is exporting the Metadata object. This is used to apply default SEO configuration across the entire application:
import { getSEOConfig } from "@/utils/seo";
export const metadata = getSEOConfig();
In Specific Pages
To customize SEO configuration for specific pages, import and call the function with relevant parameters:
import { getSEOConfig } from "@/utils/seo";
export const metadata = getSEOConfig({
title: `getSEOConfig: A Flexible SEO Metadata Generator`,
description: "A comprehensive guide to using the getSEOConfig utility function, which generates SEO metadata for StartupBolt applications.",
canonicalRelativeURL: "/getseoconfig",
});
Parameters
You can provide custom values to metadata of specific pages with the help of parameters. The function accepts the following parameters:
title
(string): The title of the page. If not provided, defaults tosettings.APP.name
.description
(string): A brief description of the page content. If not provided, defaults tosettings.APP.description
.keywords
(array): An array of keywords relevant to the page content. If not provided, defaults tosettings.APP.keywords
.twitterProfile
(string): The Twitter profile associated with the page. If not provided, defaults tosettings.APP.twitterProfile
.author
(string): The author of the page content. If not provided, defaults tosettings.APP.author
.canonicalRelativeURL
(string): The relative URL for the canonical link. If not provided, defaults tosettings.APP.url
.
Notes
- The function uses default values from the
settings
object when specific parameters are not provided. - It generates a comprehensive set of metadata suitable for various SEO needs, including social media sharing (Open Graph, Twitter Cards).
- The function is designed to work with Next.js metadata API.
Example Output
The function generates an object containing various SEO-related properties similar to this (values will depend on settings.js
and provided parameters):
{
title: "Your App Name",
description: "Your app description",
metadataBase: URL,
alternates: { canonical: "https://yourapp.com" },
openGraph: { ... },
robots: { ... },
applicationName: "Your App Name",
appleWebApp: { ... },
keywords: [ ... ],
twitter: { ... },
authors: [{ name: "Author Name" }],
creator: "Author Name",
publisher: "Author Name"
}
Adjust the configuration in your settings
file and when calling the function to customize the SEO metadata for your specific needs.