Skip to content

Commit

Permalink
feat(seo): add more jsonld
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonsaldan committed Dec 27, 2024
1 parent 982401c commit feba1f0
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down Expand Up @@ -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',
Expand All @@ -84,13 +85,23 @@ 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',
name: 'Nocturne Team',
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 = {
Expand All @@ -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',
Expand All @@ -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 = {
Expand Down Expand Up @@ -152,7 +169,7 @@ const jsonLdBreadcrumbList = {
],
}

export default function RootLayout({
export default async function RootLayout({
children,
}: Readonly<{
children: React.ReactNode
Expand Down
48 changes: 48 additions & 0 deletions src/app/lib/getLastModified.ts
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit feba1f0

Please sign in to comment.