Skip to content

Commit

Permalink
docs: fix meta tag theme color (#3214)
Browse files Browse the repository at this point in the history
* fix: meta theme color

* set `content` value for `<meta name="theme-color">` based on background value for light and dark themes

---------

Co-authored-by: Dimitri POSTOLOV <dmytropostolov@gmail.com>
  • Loading branch information
SID12g and dimaMachina authored Jan 10, 2025
1 parent 855c06d commit e11dbe0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
7 changes: 7 additions & 0 deletions .changeset/tricky-donuts-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"nextra": minor
"nextra-theme-blog": minor
"nextra-theme-docs": minor
---

set `content` value for `<meta name="theme-color">` based on background value for light and dark themes
4 changes: 1 addition & 3 deletions docs/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { NextraLogo, VercelLogo } from '@components/icons'
import cn from 'clsx'
import type { Metadata, Viewport } from 'next'
import type { Metadata } from 'next'
import { Footer, Layout, Navbar } from 'nextra-theme-docs'
import { Banner, Head } from 'nextra/components'
import { getPageMap } from 'nextra/page-map'
import type { FC, ReactNode } from 'react'
import './globals.css'

export const viewport: Viewport = Head.viewport

export const metadata: Metadata = {
description: 'Make beautiful websites with Next.js & MDX.',
metadataBase: new URL('https://nextra.site'),
Expand Down
21 changes: 11 additions & 10 deletions packages/nextra/src/client/components/head.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type HeadProps = Partial<z.input<typeof headSchema>> & {
children?: ReactNode
}

const Head_: FC<HeadProps> = ({ children, ...props }) => {
export const Head: FC<HeadProps> = ({ children, ...props }) => {
const { data, error } = headSchema.safeParse(props)
if (error) {
throw fromZodError(error)
Expand Down Expand Up @@ -111,6 +111,16 @@ html {
<head>
{children}
<style>{style}</style>
<meta
name="theme-color"
media="(prefers-color-scheme: light)"
content={`rgb(${backgroundColor.light})`}
/>
<meta
name="theme-color"
media="(prefers-color-scheme: dark)"
content={`rgb(${backgroundColor.dark})`}
/>
{faviconGlyph && (
<link
rel="icon"
Expand All @@ -127,12 +137,3 @@ function makePrimaryColor(val: string): string {
const l = `calc(var(--nextra-primary-lightness) ${val})`
return `hsl(${h + s + l})`
}

export const Head = Object.assign(Head_, {
viewport: {
themeColor: [
{ media: '(prefers-color-scheme: light)', color: '#fff' },
{ media: '(prefers-color-scheme: dark)', color: '#111' }
]
}
})

0 comments on commit e11dbe0

Please # to comment.