feat(web): open every external link in a new tab, derived from the URL (MITHOME-124)
General rule: links to another host open in a new tab with rel="noopener noreferrer"; internal paths, mailto: and tel: stay in the same tab. Behaviour was inconsistent before — the home Webmail button opened in the same tab while the other webmail links did not, and the CTA and header relied on a manual "external" switch. src/lib/external-link.ts decides from the URL (externalLinkProps for JSX, openExternalLinksInNewTab for CMS-provided HTML in About paragraphs, legal pages and the GDPR label). All link sites use it; the manual "external" CTA checkbox and NavigationItem flag are removed so the rule cannot be bypassed. Rule documented in architecture.md and CLAUDE.md; staging smoke SMOKE-07 checks every external homepage link. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
183b304687
commit
ca4d447d73
@@ -4,6 +4,7 @@ import { siteConfig } from '@/config/site'
|
||||
import Link from 'next/link'
|
||||
import type { NavigationItem } from '@/types/site'
|
||||
import type { Locale } from '@/lib/i18n'
|
||||
import { externalLinkProps } from '@/lib/external-link'
|
||||
|
||||
type FooterServiceItem = { id: string; title: string; icon: string }
|
||||
|
||||
@@ -97,6 +98,7 @@ export default function Footer({ nav, legalLinks, homeHref, description, contact
|
||||
<li key={item.href}>
|
||||
<a
|
||||
href={item.href}
|
||||
{...externalLinkProps(item.href)}
|
||||
className="group flex items-center gap-2 text-sm transition-all duration-200"
|
||||
style={{ color: 'var(--color-foreground-muted)' }}
|
||||
onMouseEnter={(e) => {
|
||||
@@ -165,6 +167,7 @@ export default function Footer({ nav, legalLinks, homeHref, description, contact
|
||||
<a
|
||||
key={link.href}
|
||||
href={link.href}
|
||||
{...externalLinkProps(link.href)}
|
||||
className="text-sm transition-all duration-200 link-underline relative"
|
||||
style={{ color: 'var(--color-foreground-muted)' }}
|
||||
onMouseEnter={(e) => {
|
||||
|
||||
@@ -168,4 +168,18 @@ describe('Header', () => {
|
||||
const mobileMenu = container.querySelector('.md\\:hidden.overflow-hidden')
|
||||
expect(mobileMenu).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
// MITHOME-124: every external link opens in a new tab, derived from the URL.
|
||||
it('should open external nav links in a new tab and keep internal ones in place', () => {
|
||||
const nav = [...getMainNavigation('hu'), { label: 'Webmail', href: 'https://mail.mozdit.hu' }]
|
||||
render(<Header {...headerProps} nav={nav} />)
|
||||
|
||||
for (const link of screen.getAllByRole('link', { name: /Webmail/ })) {
|
||||
expect(link).toHaveAttribute('target', '_blank')
|
||||
expect(link).toHaveAttribute('rel', 'noopener noreferrer')
|
||||
}
|
||||
for (const link of screen.getAllByRole('link', { name: 'Rólunk' })) {
|
||||
expect(link).not.toHaveAttribute('target')
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -6,6 +6,7 @@ import { ThemeToggle } from './ThemeProvider'
|
||||
import Link from 'next/link'
|
||||
import Image from 'next/image'
|
||||
import type { NavigationItem } from '@/types/site'
|
||||
import { externalLinkProps, isExternalHref } from '@/lib/external-link'
|
||||
|
||||
type HeaderProps = {
|
||||
nav: NavigationItem[]
|
||||
@@ -74,8 +75,7 @@ export default function Header({ nav, homeHref, a11y }: HeaderProps) {
|
||||
<a
|
||||
key={item.href}
|
||||
href={item.href}
|
||||
target={item.external ? '_blank' : undefined}
|
||||
rel={item.external ? 'noopener noreferrer' : undefined}
|
||||
{...externalLinkProps(item.href)}
|
||||
className={`relative px-4 py-2 rounded-lg text-sm font-medium transition-all duration-200 ${
|
||||
item.primary
|
||||
? 'btn btn-primary text-white'
|
||||
@@ -93,7 +93,7 @@ export default function Header({ nav, homeHref, a11y }: HeaderProps) {
|
||||
)}
|
||||
<span className="relative z-10">
|
||||
{item.label}
|
||||
{item.external && (
|
||||
{isExternalHref(item.href) && (
|
||||
<svg className="inline-block w-3 h-3 ml-1 -mt-0.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14" />
|
||||
</svg>
|
||||
@@ -161,8 +161,7 @@ export default function Header({ nav, homeHref, a11y }: HeaderProps) {
|
||||
<a
|
||||
key={item.href}
|
||||
href={item.href}
|
||||
target={item.external ? '_blank' : undefined}
|
||||
rel={item.external ? 'noopener noreferrer' : undefined}
|
||||
{...externalLinkProps(item.href)}
|
||||
onClick={() => setIsMenuOpen(false)}
|
||||
className={`block px-4 py-3 rounded-lg text-base font-medium transition-all duration-200 ${
|
||||
item.primary ? 'btn btn-primary text-white mt-2' : ''
|
||||
@@ -189,7 +188,7 @@ export default function Header({ nav, homeHref, a11y }: HeaderProps) {
|
||||
>
|
||||
<span className="flex items-center justify-between">
|
||||
{item.label}
|
||||
{item.external && (
|
||||
{isExternalHref(item.href) && (
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14" />
|
||||
</svg>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { localePath, type Locale } from '@/lib/i18n'
|
||||
import type { getAboutContent } from '@/lib/payload-content'
|
||||
import { openExternalLinksInNewTab } from '@/lib/external-link'
|
||||
|
||||
type AboutViewProps = {
|
||||
content: Awaited<ReturnType<typeof getAboutContent>>
|
||||
@@ -55,7 +56,7 @@ export default function AboutView({ content: pageContent, locale }: AboutViewPro
|
||||
{pageContent.story.paragraphs.map((paragraph, index) => (
|
||||
<p
|
||||
key={index}
|
||||
dangerouslySetInnerHTML={{ __html: paragraph }}
|
||||
dangerouslySetInnerHTML={{ __html: openExternalLinksInNewTab(paragraph) }}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
@@ -4,6 +4,7 @@ import { useState } from 'react'
|
||||
import { siteConfig } from '@/config/site'
|
||||
import { localePath, type Locale } from '@/lib/i18n'
|
||||
import type { getContactContent } from '@/lib/payload-content'
|
||||
import { externalLinkProps, openExternalLinksInNewTab } from '@/lib/external-link'
|
||||
|
||||
type ContactViewProps = {
|
||||
content: Awaited<ReturnType<typeof getContactContent>>
|
||||
@@ -237,7 +238,7 @@ export default function ContactView({ content: pageContent, contactEmail, footer
|
||||
/>
|
||||
<span
|
||||
className="text-sm text-gray-700"
|
||||
dangerouslySetInnerHTML={{ __html: gdprLabel + ' *' }}
|
||||
dangerouslySetInnerHTML={{ __html: openExternalLinksInNewTab(gdprLabel) + ' *' }}
|
||||
/>
|
||||
</label>
|
||||
{errors.gdprConsent && <p className="mt-1 text-sm text-red-600">{errors.gdprConsent}</p>}
|
||||
@@ -303,8 +304,7 @@ export default function ContactView({ content: pageContent, contactEmail, footer
|
||||
// Szolgáltatások oldalon) — javítva a tényleges webmail
|
||||
// URL-re.
|
||||
href={webmailHref}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
{...externalLinkProps(webmailHref)}
|
||||
className="text-blue-600 hover:text-blue-700"
|
||||
>
|
||||
{pageContent.info.webmail.linkText}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import Image from 'next/image'
|
||||
import { localePath, type Locale } from '@/lib/i18n'
|
||||
import type { getHomeContent, PartnerView } from '@/lib/payload-content'
|
||||
import { externalLinkProps } from '@/lib/external-link'
|
||||
|
||||
type HomeViewProps = {
|
||||
content: Awaited<ReturnType<typeof getHomeContent>>
|
||||
@@ -69,8 +70,7 @@ export default function HomeView({ content: pageContent, partners, locale }: Hom
|
||||
>
|
||||
<a
|
||||
href={pageContent.hero.cta.primary.href}
|
||||
target={pageContent.hero.cta.primary.external ? '_blank' : undefined}
|
||||
rel={pageContent.hero.cta.primary.external ? 'noopener noreferrer' : undefined}
|
||||
{...externalLinkProps(pageContent.hero.cta.primary.href)}
|
||||
className="btn btn-primary text-lg px-8 py-4 group"
|
||||
>
|
||||
<svg
|
||||
@@ -86,6 +86,7 @@ export default function HomeView({ content: pageContent, partners, locale }: Hom
|
||||
{pageContent.hero.cta.secondary && (
|
||||
<a
|
||||
href={pageContent.hero.cta.secondary.href}
|
||||
{...externalLinkProps(pageContent.hero.cta.secondary.href)}
|
||||
className="btn btn-secondary text-lg px-8 py-4"
|
||||
>
|
||||
{pageContent.hero.cta.secondary.text}
|
||||
@@ -248,8 +249,7 @@ export default function HomeView({ content: pageContent, partners, locale }: Hom
|
||||
<a
|
||||
key={partner.name}
|
||||
href={partner.url}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
{...externalLinkProps(partner.url)}
|
||||
className="group flex flex-col items-center gap-3 opacity-80 hover:opacity-100 transition-opacity duration-200"
|
||||
title={partner.name}
|
||||
>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { Locale } from '@/lib/i18n'
|
||||
import type { getLegalPage } from '@/lib/payload-content'
|
||||
import { openExternalLinksInNewTab } from '@/lib/external-link'
|
||||
|
||||
type LegalPageViewProps = {
|
||||
page: NonNullable<Awaited<ReturnType<typeof getLegalPage>>>
|
||||
@@ -45,11 +46,13 @@ export default function LegalPageView({ page, locale }: LegalPageViewProps) {
|
||||
style={{ color: 'var(--color-foreground-muted)' }}
|
||||
dangerouslySetInnerHTML={{
|
||||
// Ehelyett a valódi alkalmazásban javasolt egy Markdown parser, de az egyszerűség kedvéért a sima sortöréseket lekezeljük
|
||||
__html: section.content
|
||||
.replace(/\n\n/g, '</p><p class="mb-4">')
|
||||
.replace(/• \*\*(.*?)\*\*/g, '<br/>• <strong>$1</strong>')
|
||||
.replace(/^/, '<p class="mb-4">')
|
||||
.replace(/$/, '</p>')
|
||||
__html: openExternalLinksInNewTab(
|
||||
section.content
|
||||
.replace(/\n\n/g, '</p><p class="mb-4">')
|
||||
.replace(/• \*\*(.*?)\*\*/g, '<br/>• <strong>$1</strong>')
|
||||
.replace(/^/, '<p class="mb-4">')
|
||||
.replace(/$/, '</p>'),
|
||||
)
|
||||
}}
|
||||
/>
|
||||
</section>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { localePath, type Locale } from '@/lib/i18n'
|
||||
import type { getHomeContent, getServicesContent } from '@/lib/payload-content'
|
||||
import { externalLinkProps } from '@/lib/external-link'
|
||||
|
||||
type ServicesViewProps = {
|
||||
content: Awaited<ReturnType<typeof getServicesContent>>
|
||||
@@ -143,8 +144,7 @@ export default function ServicesView({ content: pageContent, homeServices, featu
|
||||
// target="_blank"-kal a "Webmail belépés" gombhoz — javítva a
|
||||
// tényleges webmail URL-re.
|
||||
href={webmailHref}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
{...externalLinkProps(webmailHref)}
|
||||
className="inline-block border-2 border-white text-white hover:bg-white hover:text-gray-900 font-medium px-8 py-3 rounded-md transition-colors"
|
||||
>
|
||||
{pageContent.cta.secondaryButton}
|
||||
|
||||
Reference in New Issue
Block a user