Skip to content

Commit

Permalink
♻️ Update json-ld on toppage
Browse files Browse the repository at this point in the history
  • Loading branch information
paveg committed Apr 11, 2024
1 parent 7badd5d commit 518c6cc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/layouts/Layout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import '@fontsource-variable/m-plus-1-code';
import { getEntry } from 'astro:content';
import type { Article, WithContext } from 'schema-dts';
import type { Article, WebSite, WithContext } from 'schema-dts';
import GoogleAnalytics from '@/components/analytics/GoogleAnalytics.astro';
import Footer from '@/components/Footer.astro';
Expand All @@ -30,7 +30,7 @@ export type Props = {
path: string;
hreflang: keyof typeof ui | 'x-default';
}[];
jsonLdSchema?: WithContext<Article>;
jsonLdSchema?: WithContext<Article> | WebSite;
};
const { title, description, path, og, lang, hreflangs, jsonLdSchema } =
Expand Down
4 changes: 2 additions & 2 deletions src/lib/rich-results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const publisher = (site: URL | '', lang: keyof typeof ui): Organization => {
};
};

const website = (
export const WebsiteLd = (
meta: CollectionEntry<'site'>,
site: URL | '',
lang: keyof typeof ui,
Expand Down Expand Up @@ -79,6 +79,6 @@ export const ArticleLd = (
inLanguage: supportLangs,
author: [person(meta)],
publisher: publisher(site, lang),
isPartOf: website(meta, site, lang),
isPartOf: WebsiteLd(meta, site, lang),
};
};
4 changes: 2 additions & 2 deletions src/pages/blog/[...slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { BlogDate } from '@/components/markdown/blog-date';
import { BlogMeta } from '@/components/markdown/blog-meta';
import Image from '@/components/markdown/Image.astro';
import { Separator } from '@/components/ui/separator';
import { defaultLang, ui } from '@/i18n/ui';
import { ui } from '@/i18n/ui';
import { useTranslatedPath, useTranslations } from '@/i18n/utils';
import { getLangFromUrl } from '@/i18n/utils';
import Layout from '@/layouts/Layout.astro';
Expand Down Expand Up @@ -70,7 +70,7 @@ const defaultImagePath = '/first-place.jpg';
type: 'article',
}}
hreflangs={[
{ path: `${path}`, hreflang: defaultLang },
{ path: `${path}`, hreflang: globalLang },
{ path: `${path}`, hreflang: 'x-default' },
]}
jsonLdSchema={ArticleLd(meta, post, site, globalLang)}
Expand Down
6 changes: 6 additions & 0 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
---
import { getEntry } from 'astro:content';
import { defaultLang } from '@/i18n/ui';
import { getLangFromUrl, useTranslations } from '@/i18n/utils';
import Layout from '@/layouts/Layout.astro';
import { WebsiteLd } from '@/lib/rich-results';
const lang = getLangFromUrl(Astro.url);
const t = useTranslations(lang);
const site = Astro.site ?? '';
const meta = await getEntry('site', 'meta');
---

<Layout
Expand All @@ -19,6 +24,7 @@ const t = useTranslations(lang);
{ path: '/en', hreflang: 'en' },
{ path: '/en', hreflang: 'x-default' },
]}
jsonLdSchema={WebsiteLd(meta, site, lang)}
>
<main>
<h1>{t('main.title')}</h1>
Expand Down

0 comments on commit 518c6cc

Please sign in to comment.