fix(andreknie.de): close SEO review gaps
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React from 'react'
|
||||
import React, { useEffect } from 'react'
|
||||
import { Helmet } from 'react-helmet-async'
|
||||
import { absoluteUrl, BRAND_SUFFIX, DEFAULT_DESCRIPTION, DEFAULT_IMAGE, DEFAULT_TITLE, normalizeTitle } from './seo.js'
|
||||
|
||||
@@ -9,6 +9,10 @@ export default function SEOHead({ title, description, url, image, type = 'websit
|
||||
const canonicalUrl = absoluteUrl(url || '/', '/')
|
||||
const imageUrl = absoluteUrl(image, DEFAULT_IMAGE)
|
||||
|
||||
useEffect(() => {
|
||||
document.head.querySelectorAll('[data-seo-fallback]').forEach(node => node.remove())
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<Helmet>
|
||||
<title>{siteTitle}</title>
|
||||
|
||||
@@ -25,6 +25,25 @@ describe('SEOHead', () => {
|
||||
expect(document.head.querySelector('link[rel="canonical"]')?.getAttribute('href')).toBe('https://andreknie.de/artikel')
|
||||
})
|
||||
|
||||
it('replaces static fallback metadata instead of duplicating it', () => {
|
||||
document.head.insertAdjacentHTML('beforeend', `
|
||||
<title data-seo-fallback>Fallback</title>
|
||||
<meta data-seo-fallback name="description" content="Fallback description">
|
||||
<link data-seo-fallback rel="canonical" href="https://andreknie.de/">
|
||||
`)
|
||||
|
||||
render(
|
||||
<HelmetProvider>
|
||||
<SEOHead title="Artikel" description="Article description" url="/artikel" />
|
||||
</HelmetProvider>,
|
||||
)
|
||||
|
||||
expect(document.head.querySelectorAll('[data-seo-fallback]')).toHaveLength(0)
|
||||
expect(document.head.querySelectorAll('title')).toHaveLength(1)
|
||||
expect(document.head.querySelectorAll('meta[name="description"]')).toHaveLength(1)
|
||||
expect(document.head.querySelectorAll('link[rel="canonical"]')).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('normalizes relative and absolute image URLs', () => {
|
||||
const { rerender } = render(
|
||||
<HelmetProvider>
|
||||
|
||||
Reference in New Issue
Block a user