From e34d0f0d2f31ad6a475708d86484b0a3c16c66de Mon Sep 17 00:00:00 2001 From: Huyen Nguyen <25715018+huyenltnguyen@users.noreply.github.com> Date: Wed, 16 Sep 2026 20:42:57 +0700 Subject: [PATCH 1/3] feat: add seo.config.ts --- files/framework/astro-lite/astro.config.mjs | 2 ++ files/framework/astro-lite/src/seo.config.ts | 31 +++++++++++++++++++ files/framework/astro-react/astro.config.mjs | 2 ++ files/framework/astro-react/src/seo.config.ts | 31 +++++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 files/framework/astro-lite/src/seo.config.ts create mode 100644 files/framework/astro-react/src/seo.config.ts diff --git a/files/framework/astro-lite/astro.config.mjs b/files/framework/astro-lite/astro.config.mjs index 16acd6e..ffdf8f4 100644 --- a/files/framework/astro-lite/astro.config.mjs +++ b/files/framework/astro-lite/astro.config.mjs @@ -2,9 +2,11 @@ import { defineConfig, fontProviders } from "astro/config"; import react from "@astrojs/react"; +import { seoConfig } from "./src/seo.config.ts"; // https://astro.build/config export default defineConfig({ + site: seoConfig.siteUrl, integrations: [react()], fonts: [ { diff --git a/files/framework/astro-lite/src/seo.config.ts b/files/framework/astro-lite/src/seo.config.ts new file mode 100644 index 0000000..6286a71 --- /dev/null +++ b/files/framework/astro-lite/src/seo.config.ts @@ -0,0 +1,31 @@ +export const seoConfig = { + /** The deployed URL of your site, e.g. "https://www.my-course.com" */ + siteUrl: undefined, + /** The display name of your site, e.g. "My Course Name" */ + siteName: "", + /** + * Comma-separated keywords describing your site's content. + * e.g. "freeCodeCamp, JavaScript, web development, beginner" + */ + keywords: "freeCodeCamp", + + // freeCodeCamp constants — do not change + /** Shared OG/Twitter preview image */ + ogImage: + "https://cdn.freecodecamp.org/platform/universal/fcc_meta_1920X1080-indigo.png", + ogImageWidth: "1920", + ogImageHeight: "1080", + ogType: "website", + /** freeCodeCamp Twitter account */ + twitterHandle: "@freecodecamp", + twitterCard: "summary_large_image", + /** freeCodeCamp Facebook page, used for article:publisher */ + articlePublisher: "https://www.facebook.com/freecodecamp", + referrer: "no-referrer-when-downgrade", + /** Organization details used in JSON-LD structured data */ + publisherName: "freeCodeCamp.org", + publisherLogoUrl: + "https://cdn.freecodecamp.org/platform/universal/fcc_primary.svg", + publisherLogoWidth: "2100", + publisherLogoHeight: "240", +}; diff --git a/files/framework/astro-react/astro.config.mjs b/files/framework/astro-react/astro.config.mjs index 1b60baa..f100a97 100644 --- a/files/framework/astro-react/astro.config.mjs +++ b/files/framework/astro-react/astro.config.mjs @@ -2,9 +2,11 @@ import { defineConfig, fontProviders } from 'astro/config'; import react from '@astrojs/react'; +import { seoConfig } from './src/seo.config.ts'; // https://astro.build/config export default defineConfig({ + site: seoConfig.siteUrl, integrations: [react()], fonts: [ { diff --git a/files/framework/astro-react/src/seo.config.ts b/files/framework/astro-react/src/seo.config.ts new file mode 100644 index 0000000..6286a71 --- /dev/null +++ b/files/framework/astro-react/src/seo.config.ts @@ -0,0 +1,31 @@ +export const seoConfig = { + /** The deployed URL of your site, e.g. "https://www.my-course.com" */ + siteUrl: undefined, + /** The display name of your site, e.g. "My Course Name" */ + siteName: "", + /** + * Comma-separated keywords describing your site's content. + * e.g. "freeCodeCamp, JavaScript, web development, beginner" + */ + keywords: "freeCodeCamp", + + // freeCodeCamp constants — do not change + /** Shared OG/Twitter preview image */ + ogImage: + "https://cdn.freecodecamp.org/platform/universal/fcc_meta_1920X1080-indigo.png", + ogImageWidth: "1920", + ogImageHeight: "1080", + ogType: "website", + /** freeCodeCamp Twitter account */ + twitterHandle: "@freecodecamp", + twitterCard: "summary_large_image", + /** freeCodeCamp Facebook page, used for article:publisher */ + articlePublisher: "https://www.facebook.com/freecodecamp", + referrer: "no-referrer-when-downgrade", + /** Organization details used in JSON-LD structured data */ + publisherName: "freeCodeCamp.org", + publisherLogoUrl: + "https://cdn.freecodecamp.org/platform/universal/fcc_primary.svg", + publisherLogoWidth: "2100", + publisherLogoHeight: "240", +}; From a88edf7e133359831a5cdc56dea79f765d01998b Mon Sep 17 00:00:00 2001 From: Huyen Nguyen <25715018+huyenltnguyen@users.noreply.github.com> Date: Wed, 16 Sep 2026 21:45:08 +0700 Subject: [PATCH 2/3] feat: build json-ld --- files/framework/astro-lite/astro.config.mjs | 2 - .../astro-lite/src/layouts/layout.astro | 66 ++++++++++++++++++- files/framework/astro-lite/src/seo.config.ts | 2 +- files/framework/astro-react/astro.config.mjs | 3 - .../astro-react/src/layouts/layout.astro | 66 ++++++++++++++++++- files/framework/astro-react/src/seo.config.ts | 2 +- 6 files changed, 132 insertions(+), 9 deletions(-) diff --git a/files/framework/astro-lite/astro.config.mjs b/files/framework/astro-lite/astro.config.mjs index ffdf8f4..16acd6e 100644 --- a/files/framework/astro-lite/astro.config.mjs +++ b/files/framework/astro-lite/astro.config.mjs @@ -2,11 +2,9 @@ import { defineConfig, fontProviders } from "astro/config"; import react from "@astrojs/react"; -import { seoConfig } from "./src/seo.config.ts"; // https://astro.build/config export default defineConfig({ - site: seoConfig.siteUrl, integrations: [react()], fonts: [ { diff --git a/files/framework/astro-lite/src/layouts/layout.astro b/files/framework/astro-lite/src/layouts/layout.astro index 908814e..ba5cb65 100644 --- a/files/framework/astro-lite/src/layouts/layout.astro +++ b/files/framework/astro-lite/src/layouts/layout.astro @@ -3,13 +3,48 @@ import '../global.css'; import { ClientRouter } from 'astro:transitions'; import { Font } from 'astro:assets'; import { Nav } from '../components/nav'; +import { seoConfig } from '../seo.config'; type Props = { title: string; brand: string; + description?: string; + keywords?: string; }; -const { title, brand } = Astro.props; +const { title, brand, description, keywords } = Astro.props; + +const pageKeywords = keywords ?? seoConfig.keywords; + +const jsonLd = seoConfig.siteUrl && seoConfig.siteName && description + ? JSON.stringify({ + '@context': 'https://schema.org', + '@type': 'WebSite', + publisher: { + '@type': 'Organization', + name: seoConfig.publisherName, + url: seoConfig.siteUrl, + logo: { + '@type': 'ImageObject', + url: seoConfig.publisherLogoUrl, + width: Number(seoConfig.publisherLogoWidth), + height: Number(seoConfig.publisherLogoHeight), + }, + }, + image: { + '@type': 'ImageObject', + url: seoConfig.ogImage, + width: Number(seoConfig.ogImageWidth), + height: Number(seoConfig.ogImageHeight), + }, + url: seoConfig.siteUrl, + mainEntityOfPage: { + '@type': 'WebPage', + '@id': seoConfig.siteUrl, + }, + ...(description ? { description } : {}), + }) + : null; --- @@ -22,6 +57,35 @@ const { title, brand } = Astro.props;