-
Notifications
You must be signed in to change notification settings - Fork 0
/
SeoHead.astro
42 lines (36 loc) · 1.19 KB
/
SeoHead.astro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
---
import DynamicTag from './DynamicTag.astro';
import { getLocale } from '@lib/i18n';
import { getOpenSearchName, getOpenSearchPathname } from '@lib/search';
import type { PageUrl } from '@lib/seo';
import type { Tag } from '@lib/datocms/types';
interface Props {
pageUrls: PageUrl[];
tags: Tag[];
}
const { pageUrls, tags } = Astro.props;
const locale = getLocale();
const metaTags = tags.filter(tag => tag.tag !== 'title');
const titleTag = tags.find(tag => tag.tag === 'title');
---
{ titleTag && (
<title>{titleTag.content}</title>
)}
{
metaTags.map(tag => (
// @ts-expect-error
<DynamicTag as={tag.tag} { ...tag.attributes } />
))
}
{ pageUrls.map((pageUrl: PageUrl) => (
pageUrl.locale === locale
? <>
<link rel="canonical" href={ new URL(pageUrl.pathname, Astro.site) } />
<meta property="og:url" content={ new URL(pageUrl.pathname, Astro.site) } />
</>
: <link rel="alternate" href={ new URL(pageUrl.pathname, Astro.site) } hreflang={ pageUrl.locale } />
)) }
<link rel="sitemap" href="/sitemap-index.xml" />
<link rel="search" type="application/opensearchdescription+xml"
title={ getOpenSearchName(locale) }
href={ getOpenSearchPathname(locale) } />