From feba1f008daaae40c40eb4efef234fda254245e4 Mon Sep 17 00:00:00 2001 From: Brandon Saldan <26472557+brandonsaldan@users.noreply.github.com> Date: Thu, 26 Dec 2024 22:26:53 -0500 Subject: [PATCH] feat(seo): add more jsonld --- src/app/layout.tsx | 21 +++++++++++++-- src/app/lib/getLastModified.ts | 48 ++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 src/app/lib/getLastModified.ts diff --git a/src/app/layout.tsx b/src/app/layout.tsx index ca87f11..401e2e8 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1,6 +1,7 @@ import GoogleAnalytics from '@/components/google-analytics' import '@/styles/tailwind.css' import type { Metadata } from 'next' +import { getLatestCommitDate } from './lib/getLastModified' export const metadata: Metadata = { title: { @@ -72,7 +73,7 @@ const jsonLdSoftware = { name: 'Nocturne', description: 'When Spotify ended support, we created a new beginning. Join our growing community of users giving their Car Thing a second life with our free, open source solution.', - applicationCategory: 'Multimedia', + applicationCategory: ['Multimedia', 'MusicPlayer'], operatingSystem: 'Cross-platform', softwareVersion: '2.1.2', downloadUrl: 'https://github.com/usenocturne/nocturne-image/releases/latest', @@ -84,6 +85,7 @@ const jsonLdSoftware = { 'https://wikipedia.org/wiki/Nocturne_(software)', 'https://www.wikidata.org/wiki/Q131441227', 'https://github.com/usenocturne', + 'https://discord.gg/GTP9AawHPt', ], author: { '@type': 'Organization', @@ -91,6 +93,15 @@ const jsonLdSoftware = { url: 'https://usenocturne.com/', }, license: 'https://opensource.org/licenses/MIT', + datePublished: '2024-09-22', + dateModified: await getLatestCommitDate(), + keywords: [ + 'Car Thing', + 'Spotify', + 'Music Player', + 'Open Source', + 'Car Entertainment', + ], } const jsonLdOrganization = { @@ -99,6 +110,7 @@ const jsonLdOrganization = { name: 'Nocturne', url: 'https://usenocturne.com', logo: 'https://usenocturne.com/images/logo.png', + foundingDate: '2024-09-22', sameAs: [ 'https://wikipedia.org/wiki/Nocturne_(software)', 'https://www.wikidata.org/wiki/Q131441227', @@ -110,6 +122,11 @@ const jsonLdOrganization = { contactType: 'support', url: 'https://discord.gg/GTP9AawHPt', }, + knowsAbout: [ + 'Spotify Car Thing', + 'Open Source Software', + 'Car Entertainment Systems', + ], } const jsonLdWebSite = { @@ -152,7 +169,7 @@ const jsonLdBreadcrumbList = { ], } -export default function RootLayout({ +export default async function RootLayout({ children, }: Readonly<{ children: React.ReactNode diff --git a/src/app/lib/getLastModified.ts b/src/app/lib/getLastModified.ts new file mode 100644 index 0000000..2393ca3 --- /dev/null +++ b/src/app/lib/getLastModified.ts @@ -0,0 +1,48 @@ +const REPOS = ['usenocturne/nocturne-ui', 'usenocturne/nocturne-image'] + +export async function getLatestCommitDate() { + try { + const dates = await Promise.all( + REPOS.map(async (repo) => { + const response = await fetch( + `https://api.github.com/repos/${repo}/commits/main`, + { + next: { revalidate: 3600 }, + headers: { + Accept: 'application/vnd.github.v3+json', + ...(process.env.GITHUB_TOKEN && { + Authorization: `Bearer ${process.env.GITHUB_TOKEN}`, + }), + }, + }, + ) + + if (!response.ok) { + console.error(`Failed to fetch ${repo}:`, response.statusText) + return null + } + + const data = await response.json() + return new Date(data.commit.committer.date) + }), + ) + + const validDates = dates.filter((date): date is Date => date !== null) + if (validDates.length === 0) { + return new Date().toISOString().split('T')[0] + } + + const latestTimestamp = Math.max( + ...validDates.map((date) => date.getTime()), + ) + const latestDate = new Date(latestTimestamp) + + const formattedDate = latestDate.toISOString().split('T')[0] + console.log('Formatted date for Schema.org:', formattedDate) + return formattedDate + } catch (error) { + console.error('Error fetching commit dates:', error) + const today = new Date().toISOString().split('T')[0] + return today + } +}