generated from act-now-coalition/act-now-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
routing.ts
45 lines (40 loc) · 1.28 KB
/
routing.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import type { Region } from "@actnowcoalition/actnow.js";
import { cms } from "src/cms";
/**
* The URL prefix for all location pages. This must match the directory used for
* your location pages under src/pages.
*
* @example
* LOCATION_PAGE_PREFIX = "us"
* Location pages defined in src/pages/us/[regionSlug]/index.tsx
* Location URL is /us/<regionSlug>
*/
const LOCATION_PAGE_PREFIX = "country";
/**
* Gets the slug for a region, used with LOCATION_PAGE_PREFIX to generate the
* full location page URL. This can be customized to change the URL structure
* of location pages.
*
* @param region The region to get a slug for.
* @returns The region slug.
*/
export function getRegionSlug(region: Region): string {
return region.parent ? `${region.parent.slug}-${region.slug}` : region.slug;
}
/**
* Returns the URL for a region, relative to the root of the site.
*
* @param region The region to get a slug for.
* @returns The region URL.
*/
export function getRegionRelativeUrl(region: Region): string {
return `/${LOCATION_PAGE_PREFIX}/${getRegionSlug(region)}`;
}
/**
* Returns the full URL for a region.
* @param region
* @returns The full region URL.
*/
export function getRegionUrl(region: Region): string {
return `${cms.settings.siteUrl}/${getRegionRelativeUrl(region)}`;
}