Skip to content

Commit 13dccf1

Browse files
committed
feat: alternative meta
1 parent f1bf062 commit 13dccf1

File tree

4 files changed

+29
-15
lines changed

4 files changed

+29
-15
lines changed

apps/docs/src/app/(home)/page.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { createMetadata } from '@/lib/metadata';
12
import { useTranslations } from 'next-intl';
23
import Link from 'next/link';
34

@@ -119,3 +120,9 @@ export default function HomePage() {
119120
</main>
120121
);
121122
}
123+
124+
export async function generateMetadata() {
125+
return createMetadata({
126+
pathname: '/',
127+
});
128+
}

apps/docs/src/app/layout.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NextIntlClientProvider, hasLocale } from 'next-intl';
1+
import { NextIntlClientProvider } from 'next-intl';
22
import './global.css';
33
import { Provider } from '@/app/provider';
44

@@ -11,7 +11,6 @@ import { getLangDir } from 'rtl-detect';
1111

1212
export async function generateMetadata() {
1313
const t = await getTranslations('meta');
14-
1514
return createMetadata({
1615
title: {
1716
template: `%s | ${t('title')}`,

apps/docs/src/lib/source.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as icons from '@/mdx/Icon';
77
import { loader } from 'fumadocs-core/source';
88
import { createMDXSource } from 'fumadocs-mdx';
99
import { createElement } from 'react';
10+
import { getDocUrl } from './utils';
1011

1112
// See https://fumadocs.dev//docs/headless/source-api for more info
1213
export const docs = loader({
@@ -18,14 +19,7 @@ export const docs = loader({
1819
return createElement(icons[icon as keyof typeof icons]);
1920
},
2021
url(slugs) {
21-
// remove \d\d- from slug
22-
const url = `/docs/${slugs
23-
.map((slug) => {
24-
return slug.replace(/^\d\d-/, '');
25-
})
26-
.join('/')}`;
27-
28-
return url;
22+
return getDocUrl(slugs);
2923
},
3024
// https://fumadocs.dev/docs/headless/source-api#page-tree-1
3125
pageTree: {

apps/docs/src/lib/utils.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,26 @@ export const parseDocId = (id: string) => {
124124
whereTag,
125125
};
126126
};
127-
128-
export function getDocUrl(slug: string[] | string | undefined) {
129-
if (typeof slug === 'string') {
130-
return `/docs/${slug}`;
127+
export function removeTrailingSlash(url: string) {
128+
return url.endsWith('/') ? url.slice(0, -1) : url;
129+
}
130+
export function removeLeadingSlash(url: string) {
131+
return url.startsWith('/') ? url.slice(1) : url;
132+
}
133+
export function getDocUrl(slugs: string[] | string | undefined) {
134+
if (!slugs || slugs === '/') {
135+
return '/docs';
136+
}
137+
if (typeof slugs === 'string') {
138+
return removeTrailingSlash(`/docs/${removeLeadingSlash(slugs)}`);
131139
}
132-
return `/docs/${(slug || []).join('/')}`;
140+
return removeTrailingSlash(
141+
`/docs/${(
142+
slugs.map((slug) => {
143+
return slug.replace(/^\d\d-/, '');
144+
})
145+
).join('/')}`,
146+
);
133147
}
134148

135149
export function getLearnUrl(slug: string[] | string | undefined) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy