-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add SEO support with metadata, sitemap, and JSON-LD #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+273
−13
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
28da4b4
feat: add url and analytics config for SEO and tracking support
rsbh d5a8f31
feat: add root and per-page SEO metadata with auto-generated OG images
rsbh 0a9e134
feat: add sitemap, robots.txt, and lastModified frontmatter support
rsbh ea98c8d
feat: add JSON-LD structured data for WebSite and Article schemas
rsbh 326dc49
feat: add analytics support with use-analytics and Google Analytics p…
rsbh 2834b44
Revert "feat: add analytics support with use-analytics and Google Ana…
rsbh 29108ea
fix: address PR review comments for SEO metadata and sitemap
rsbh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { ImageResponse } from 'next/og' | ||
| import type { NextRequest } from 'next/server' | ||
| import { loadConfig } from '@/lib/config' | ||
|
|
||
| export async function GET(request: NextRequest) { | ||
| const { searchParams } = request.nextUrl | ||
| const title = searchParams.get('title') ?? loadConfig().title | ||
| const description = searchParams.get('description') ?? '' | ||
| const siteName = loadConfig().title | ||
|
|
||
| return new ImageResponse( | ||
| ( | ||
| <div | ||
| style={{ | ||
| height: '100%', | ||
| width: '100%', | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| justifyContent: 'center', | ||
| padding: '60px 80px', | ||
| backgroundColor: '#0a0a0a', | ||
| color: '#fafafa', | ||
| }} | ||
| > | ||
| <div | ||
| style={{ | ||
| fontSize: 24, | ||
| color: '#888', | ||
| marginBottom: 16, | ||
| }} | ||
| > | ||
| {siteName} | ||
| </div> | ||
| <div | ||
| style={{ | ||
| fontSize: 56, | ||
| fontWeight: 700, | ||
| lineHeight: 1.2, | ||
| marginBottom: 24, | ||
| }} | ||
| > | ||
| {title} | ||
| </div> | ||
| {description && ( | ||
| <div | ||
| style={{ | ||
| fontSize: 24, | ||
| color: '#999', | ||
| lineHeight: 1.4, | ||
| }} | ||
| > | ||
| {description} | ||
| </div> | ||
| )} | ||
| </div> | ||
| ), | ||
| { | ||
| width: 1200, | ||
| height: 630, | ||
| } | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import type { MetadataRoute } from 'next' | ||
| import { loadConfig } from '@/lib/config' | ||
|
|
||
| export default function robots(): MetadataRoute.Robots { | ||
| const config = loadConfig() | ||
| return { | ||
| rules: { userAgent: '*', allow: '/' }, | ||
| ...(config.url && { sitemap: `${config.url}/sitemap.xml` }), | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import type { MetadataRoute } from 'next' | ||
| import { loadConfig } from '@/lib/config' | ||
| import { source } from '@/lib/source' | ||
| import { loadApiSpecs } from '@/lib/openapi' | ||
| import { buildApiRoutes } from '@/lib/api-routes' | ||
|
|
||
| export default function sitemap(): MetadataRoute.Sitemap { | ||
| const config = loadConfig() | ||
| if (!config.url) return [] | ||
|
|
||
| const baseUrl = config.url.replace(/\/$/, '') | ||
|
|
||
| const docPages = source.getPages().map((page) => ({ | ||
| url: `${baseUrl}/${page.slugs.join('/')}`, | ||
| ...(page.data.lastModified && { lastModified: new Date(page.data.lastModified) }), | ||
| })) | ||
|
|
||
| const apiPages = config.api?.length | ||
| ? buildApiRoutes(loadApiSpecs(config.api)).map((route) => ({ | ||
| url: `${baseUrl}/apis/${route.slug.join('/')}`, | ||
| })) | ||
| : [] | ||
|
|
||
| return [ | ||
| { url: baseUrl }, | ||
| ...docPages, | ||
| ...apiPages, | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: raystack/chronicle
Length of output: 615
🏁 Script executed:
Repository: raystack/chronicle
Length of output: 3462
Use one normalized per-page absolute URL for both OpenGraph and JSON-LD.
On line 39-44,
openGraph.urlis inherited from parent metadata (site root), so doc pages publish the wrong OG URL. On line 72, manual string concatenation can produce malformed URLs (double slashes ifconfig.urlhas a trailing slash) and doesn't percent-encode slug segments.🔧 Proposed fix
export async function generateMetadata( { params }: PageProps, parent: ResolvingMetadata, ): Promise<Metadata> { const { slug } = await params const page = source.getPage(slug) if (!page) return {} const config = loadConfig() const data = page.data as PageData const parentMetadata = await parent + const pagePath = (slug ?? []).map(encodeURIComponent).join('/') + const pageUrl = + config.url + ? new URL(pagePath, config.url.endsWith('/') ? config.url : `${config.url}/`).toString() + : undefined const metadata: Metadata = { title: data.title, description: data.description, } @@ if (config.url) { const ogParams = new URLSearchParams({ title: data.title }) if (data.description) ogParams.set('description', data.description) metadata.openGraph = { ...parentMetadata.openGraph, title: data.title, description: data.description, + ...(pageUrl && { url: pageUrl }), images: [{ url: `/og?${ogParams.toString()}`, width: 1200, height: 630 }], } @@ export default async function DocsPage({ params }: PageProps) { const { slug } = await params const config = loadConfig() @@ - const pageUrl = config.url ? `${config.url}/${(slug ?? []).join('/')}` : undefined + const pagePath = (slug ?? []).map(encodeURIComponent).join('/') + const pageUrl = + config.url + ? new URL(pagePath, config.url.endsWith('/') ? config.url : `${config.url}/`).toString() + : undefined🤖 Prompt for AI Agents