Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions e2e/english-journey.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { expect, type Page } from '@playwright/test'
import { SITE_NAME } from '~/constants/branding'
import { COOKIE_LOCALE_BANNER_DISMISSED_KEY } from '~/constants/cookie'
import { HTTP_STATUS } from '~/constants/http'
import { ALL_CATEGORY_SLUG, MEMES_PER_PAGE } from '~/constants/meme'
import { PREMIUM_PLAN_PRICING } from '~/constants/plan'
import { MONTHS_IN_YEAR } from '~/constants/time'
import { getLocaleDisplayName } from '~/helpers/locale'
import { formatCentsToEuros } from '~/helpers/number'
import { buildPageTitle } from '~/helpers/page-title'
import { m } from '~/paraglide/messages'
import { baseLocale, cookieName, type Locale } from '~/paraglide/runtime'
import {
Expand Down Expand Up @@ -294,7 +294,7 @@ test.describe('the English journey', () => {
const englishUrl = buildE2eUrl(englishPage.pathname, E2E_ENGLISH_LOCALE)
const frenchUrl = buildE2eUrl(englishPage.pathname, baseLocale)

await expect(page).toHaveTitle(`${SITE_NAME} - ${englishPage.title}`)
await expect(page).toHaveTitle(buildPageTitle(englishPage.title))
await expect
.poll(() => {
return readLocaleMetadata(page)
Expand Down
2 changes: 1 addition & 1 deletion messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
"error_premium_required": "This feature requires Premium",
"error_rate_limited": "Too many requests, please try again in a few minutes",
"error_not_found_description": "Looks like you've ventured into the unknown digital realm.",
"error_not_found_title": "Petit Meme - Page not found",
"error_not_found_title": "Page not found",
"error_root_description": "Oops! The site encountered an unexpected problem.",
"error_search_timeout": "The search could not be completed. Check your internet connection and try again.",
"error_sign_out": "An error occurred while signing out",
Expand Down
2 changes: 1 addition & 1 deletion messages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
"error_premium_required": "Cette fonctionnalité demande Premium",
"error_rate_limited": "Trop de requêtes, réessaie dans quelques minutes",
"error_not_found_description": "On dirait que vous vous êtes aventuré dans le domaine inconnu du numérique.",
"error_not_found_title": "Petit Meme - Page introuvable",
"error_not_found_title": "Page introuvable",
"error_root_description": "Oups ! Le site a rencontré un problème inattendu.",
"error_search_timeout": "La recherche n'a pas pu aboutir. Vérifiez votre connexion internet et réessayez.",
"error_sign_out": "Une erreur est survenue lors de la déconnexion",
Expand Down
3 changes: 2 additions & 1 deletion src/components/app/not-found.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Link } from '@tanstack/react-router'
import { buttonVariants } from '~/components/ui/button-variants'
import { buildPageTitle } from '~/helpers/page-title'
import { m } from '~/paraglide/messages'

export const NotFound = () => {
return (
<div className="flex items-center px-4 py-12 sm:px-6 md:px-8 lg:px-12 xl:px-16">
<title>{m.error_not_found_title()}</title>
<title>{buildPageTitle(m.error_not_found_title())}</title>
<meta name="robots" content="noindex,nofollow" />
<div className="w-full space-y-6 text-center">
<div className="space-y-3">
Expand Down
2 changes: 2 additions & 0 deletions src/constants/branding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ export const LOGO_PATH = '/images/petit-meme-logo.png'

export const SITE_NAME = 'Petit Meme'

export const ADMIN_SITE_NAME = `Admin ${SITE_NAME}`

export const SITE_ALTERNATE_NAME = 'Petit Mème'

export const PRODUCTION_SITE_URL = 'https://www.petit-meme.io'
5 changes: 5 additions & 0 deletions src/helpers/page-title.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { SITE_NAME } from '~/constants/branding'

export const buildPageTitle = (title: string, siteName = SITE_NAME) => {
return `${title} | ${siteName}`
}
18 changes: 17 additions & 1 deletion src/lib/seo/__tests__/meta.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { afterEach, describe, expect, it } from 'vitest'
import { PUBLISHED_MEME_FAKE } from '~/constants/__tests__/meme.fakes'
import type { MemeWithCategories, MemeWithVideo } from '~/constants/meme'
import { buildMemeSeo, buildSeo } from '~/lib/seo/meta'
import { buildAdminPageHead, buildMemeSeo, buildSeo } from '~/lib/seo/meta'
import { buildOgImage } from '~/lib/seo/url'
import { getLocale, type Locale, overwriteGetLocale } from '~/paraglide/runtime'

Expand Down Expand Up @@ -158,4 +158,20 @@ describe('the public page tags', () => {
expect(readMeta(meta, 'twitter:title')).toBe('Pricing')
expect(readMeta(meta, 'og:site_name')).toBe('Petit Meme')
})

it('should lead the page title with what the page holds, the site name last', () => {
const { meta } = buildSeo({ title: 'Mister V - On s’en bat les couilles' })

expect(meta[0]).toStrictEqual({
title: 'Mister V - On s’en bat les couilles | Petit Meme'
})
})
})

describe('the administration tags', () => {
it('should lead the page title with the page, then the administration name', () => {
expect(buildAdminPageHead('Catégories')).toStrictEqual({
meta: [{ title: 'Catégories | Admin Petit Meme' }]
})
})
})
15 changes: 4 additions & 11 deletions src/lib/seo/meta.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { AnyRouteMatch } from '@tanstack/react-router'
import { SITE_NAME } from '~/constants/branding'
import { ADMIN_SITE_NAME, SITE_NAME } from '~/constants/branding'
import type { MemeWithCategories, MemeWithVideo } from '~/constants/meme'
import { OG_IMAGE_HEIGHT, OG_IMAGE_WIDTH } from '~/constants/og'
import { MemeStatus } from '~/db/generated/prisma/enums'
import { buildPageTitle } from '~/helpers/page-title'
import { buildMemePathname } from '~/helpers/pathname'
import {
buildMemeOgImageUrl,
Expand All @@ -24,12 +25,6 @@ const OG_LOCALE_MAP = {
en: 'en_US'
} as const satisfies Record<Locale, string>

const ADMIN_SITE_NAME = `Admin ${SITE_NAME}`

export const buildPageTitle = (title: string, siteName = SITE_NAME) => {
return `${siteName} - ${title}`
}

export const NOINDEX_NOFOLLOW_META = {
name: 'robots',
content: 'noindex,nofollow'
Expand Down Expand Up @@ -78,9 +73,7 @@ export const buildSeo = ({
ogType = 'website'
}: SeoParams): SeoResult => {
const locale = getLocale()
const titlePrefixed = isAdmin
? buildPageTitle(title, ADMIN_SITE_NAME)
: buildPageTitle(title)
const pageTitle = buildPageTitle(title, isAdmin ? ADMIN_SITE_NAME : SITE_NAME)

const canonicalBase = canonicalPathname ?? pathname
const canonicalUrl = buildUrl(canonicalBase, locale)
Expand All @@ -89,7 +82,7 @@ export const buildSeo = ({
})

const meta = [
{ title: titlePrefixed },
{ title: pageTitle },
...(keywords ? [{ name: 'keywords', content: keywords }] : []),
{ name: 'author', content: 'Victor de la Fouchardière' },
{ name: 'twitter:title', content: title },
Expand Down
2 changes: 1 addition & 1 deletion src/routes/_public__root/memes/$memeId.studio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
useCloseStudio,
usePlaceMemePageBelowStudio
} from '~/components/studio/use-studio-history'
import { buildPageTitle } from '~/helpers/page-title'
import { toStudioMeme } from '~/helpers/studio-meme'
import { buildPageTitle } from '~/lib/seo/meta'
import { m } from '~/paraglide/messages'
import { getMemeQueryOpts } from '~/queries/meme'
import { getPremiumSubscriptionQueryOpts } from '~/queries/subscription'
Expand Down
4 changes: 4 additions & 0 deletions src/routes/_public__root/memes/-components/meme-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const memeRouteApi = getRouteApi('/_public__root/memes/$memeId')

const LONG_DATE_OPTIONS: Intl.DateTimeFormatOptions = { dateStyle: 'long' }

const CRAWLER_WORD_BREAK = ' '

type WatchedMeme = Awaited<ReturnType<typeof getMeme>>

type MemeMetaProps = {
Expand Down Expand Up @@ -128,6 +130,7 @@ const MemeDetails = ({ meme }: MemeDetailsProps) => {
{meme.categories.map(({ category }) => {
return (
<li key={category.id}>
{CRAWLER_WORD_BREAK}
<Link
to="/memes/category/$slug"
params={{ slug: category.slug }}
Expand All @@ -146,6 +149,7 @@ const MemeDetails = ({ meme }: MemeDetailsProps) => {
{keywords.map((keyword) => {
return (
<li key={keyword}>
{CRAWLER_WORD_BREAK}
<Link
to="/memes/category/$slug"
params={{ slug: ALL_CATEGORY_SLUG }}
Expand Down
113 changes: 113 additions & 0 deletions src/routes/_public__root/memes/-lib/__tests__/meme-json-ld.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, expect, it } from 'vitest'
import { PUBLISHED_MEME_FAKE as MEME } from '~/constants/__tests__/meme.fakes'
import type { MemeWithCategories } from '~/constants/meme'

const BUNNY_ID = MEME.video.bunnyId
const CRAWLER_STREAM_URL = `https://cdn-test.petit-meme.io/bcdn_token=HS256-token&token_path=%2F${BUNNY_ID}%2F&expires=4102444800/${BUNNY_ID}/playlist.m3u8`
Expand Down Expand Up @@ -52,3 +53,115 @@ describe('video structured data', () => {
})
})
})

type MemeCategoryLink = MemeWithCategories['categories'][number]

type LinkCategoryParams = {
categoryId: string
slug: string
title: string
linkedAt: string
}

const linkCategory = ({
categoryId,
slug,
title,
linkedAt
}: LinkCategoryParams): MemeCategoryLink => {
const createdAt = new Date('2025-01-01T00:00:00Z')

return {
memeId: MEME.id,
categoryId,
createdAt: new Date(linkedAt),
category: {
id: categoryId,
title,
slug,
keywords: [],
family: null,
emoji: null,
createdAt,
updatedAt: createdAt
}
}
}

const ANGRY = linkCategory({
categoryId: 'category-b',
slug: 'enerve',
title: 'Énervé',
linkedAt: '2026-01-01T00:00:00Z'
})
const SOUND = linkCategory({
categoryId: 'category-a',
slug: 'son',
title: 'Son',
linkedAt: '2026-02-01T00:00:00Z'
})
const SOUND_LINKED_WITH_ANGRY = { ...SOUND, createdAt: ANGRY.createdAt }

const HOME_CRUMB = {
'@type': 'ListItem',
position: 1,
name: 'Accueil',
item: 'https://www.petit-meme.io/'
}
const MEME_CRUMB = { '@type': 'ListItem', position: 3, name: 'Meme title' }

describe('meme breadcrumb structured data', () => {
it('should send a Meme without a Category through the whole library', async () => {
const { buildMemeBreadcrumbNode } = await importMemeJsonLd()

expect(buildMemeBreadcrumbNode(MEME)).toStrictEqual({
'@type': 'BreadcrumbList',
itemListElement: [
HOME_CRUMB,
{
'@type': 'ListItem',
position: 2,
name: 'Tous les mèmes',
item: 'https://www.petit-meme.io/memes/category/all'
},
MEME_CRUMB
]
})
})

it('should lead with the Category linked first, whatever order the links arrive in', async () => {
const { buildMemeBreadcrumbNode } = await importMemeJsonLd()

expect(
buildMemeBreadcrumbNode({ ...MEME, categories: [SOUND, ANGRY] })
).toStrictEqual({
'@type': 'BreadcrumbList',
itemListElement: [
HOME_CRUMB,
{
'@type': 'ListItem',
position: 2,
name: 'Énervé',
item: 'https://www.petit-meme.io/memes/category/enerve'
},
MEME_CRUMB
]
})
})

it('should break a tie between Categories linked together by their id', async () => {
const { buildMemeBreadcrumbNode } = await importMemeJsonLd()

expect(
buildMemeBreadcrumbNode({
...MEME,
categories: [ANGRY, SOUND_LINKED_WITH_ANGRY]
}).itemListElement
).toContainEqual({
'@type': 'ListItem',
position: 2,
name: 'Son',
item: 'https://www.petit-meme.io/memes/category/son'
})
})
})
33 changes: 28 additions & 5 deletions src/routes/_public__root/memes/-lib/meme-json-ld.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import type { InteractionCounter, VideoObject } from 'schema-dts'
import type {
BreadcrumbList,
InteractionCounter,
VideoObject
} from 'schema-dts'
import { createIsomorphicFn } from '@tanstack/react-start'
import { HLS_MIME_TYPE } from '~/constants/bunny'
import type { MemeWithCategories, MemeWithVideo } from '~/constants/meme'
Expand Down Expand Up @@ -75,17 +79,36 @@ export const buildVideoNode = (
}
}

type MemeCategoryLink = MemeWithCategories['categories'][number]

const findFirstLinkedCategory = (links: readonly MemeCategoryLink[]) => {
const [firstLink] = links.toSorted((first, second) => {
return (
first.createdAt.getTime() - second.createdAt.getTime() ||
first.categoryId.localeCompare(second.categoryId)
)
})

return firstLink?.category
}

export const buildMemeBreadcrumbNode = (
meme: Pick<MemeWithCategories, 'id' | 'title' | 'categories'>
): BreadcrumbList => {
return buildBreadcrumbNode([
buildCategoryCrumb(findFirstLinkedCategory(meme.categories)),
{ name: meme.title, pathname: buildMemePathname(meme.id) }
])
}

export const getMemeJsonLd = createIsomorphicFn()
.server(
async (meme: MemeWithVideo & Pick<MemeWithCategories, 'categories'>) => {
const crawlerStreamUrl = await getCrawlerStreamUrl(meme.video.bunnyId)

return serializeJsonLdGraph([
buildVideoNode(meme, crawlerStreamUrl),
buildBreadcrumbNode([
buildCategoryCrumb(meme.categories[0]?.category),
{ name: meme.title, pathname: buildMemePathname(meme.id) }
])
buildMemeBreadcrumbNode(meme)
])
}
)
Expand Down
5 changes: 2 additions & 3 deletions src/routes/admin/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { z } from 'zod'
import { createFileRoute } from '@tanstack/react-router'
import { buildAdminPageHead } from '~/lib/seo/meta'
import { listAdminRecentActivityQueryOpts } from '~/queries/admin/activity'
import { listAdminRecentAuditQueryOpts } from '~/queries/admin/dashboard'
import { DashboardPage } from '~/routes/admin/-components/dashboard/dashboard-page'
Expand All @@ -26,8 +27,6 @@ export const Route = createFileRoute('/admin/')({
])
},
head: () => {
return {
meta: [{ title: 'Dashboard — Admin' }]
}
return buildAdminPageHead('Dashboard')
}
})
5 changes: 2 additions & 3 deletions src/routes/admin/services.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { createFileRoute } from '@tanstack/react-router'
import { buildAdminPageHead } from '~/lib/seo/meta'
import { ServicesPage } from './-components/services/services-page'

export const Route = createFileRoute('/admin/services')({
component: ServicesPage,
head: () => {
return {
meta: [{ title: 'Services — Admin' }]
}
return buildAdminPageHead('Services')
}
})
2 changes: 1 addition & 1 deletion src/routes/offline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
VIEWPORT_CONTENT,
WEB_APP_THEME_COLOR
} from '~/constants/pwa'
import { buildPageTitle } from '~/lib/seo/meta'
import { buildPageTitle } from '~/helpers/page-title'
import { m } from '~/paraglide/messages'
import {
baseLocale,
Expand Down
Loading