-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
33 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import {MetadataRoute} from 'next'; | ||
import {routing, getPathname} from '@/i18n/routing'; | ||
|
||
type Href = Parameters<typeof getPathname>[0]['href']; | ||
type pathnames = typeof routing.pathnames; | ||
type AvailableRoutes = keyof pathnames; | ||
|
||
// Adapt this as necessary | ||
const host = 'https://jy95.github.io'; | ||
|
||
export default function sitemap(): MetadataRoute.Sitemap { | ||
const paths = Object.keys(routing.pathnames) as AvailableRoutes[]; | ||
return paths.map(getEntry); | ||
} | ||
|
||
function getEntry(href: Href): MetadataRoute.Sitemap[number] { | ||
return { | ||
url: getUrl(href, routing.defaultLocale), | ||
lastModified: new Date(), | ||
changeFrequency: "daily", | ||
alternates: { | ||
languages: Object.fromEntries( | ||
routing.locales.map((locale) => [locale, getUrl(href, locale)]) | ||
) | ||
} | ||
} | ||
} | ||
|
||
function getUrl(href: Href, locale: (typeof routing.locales)[number]) { | ||
const pathname = getPathname({locale, href}); | ||
return host + pathname; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters