-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
gatsby-node.ts
104 lines (91 loc) Β· 2.68 KB
/
gatsby-node.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { config } from 'dotenv';
config();
import { CreatePagesArgs } from 'gatsby';
import path from 'node:path';
import {
AboutPageEntry,
AboutPageEntryMetaItem,
EpisodeEntry,
EpisodeEntryMetaItem,
HomePageEntry,
HomePageEntryMetaItem,
} from './bcms/types/ts';
import { Client } from '@thebcms/client';
import {
AboutPageContent,
EpisodePageContent,
HomePageContent,
NowPlayingPageContent,
} from './src/types';
const bcms = new Client(
process.env.BCMS_ORG_ID || '',
process.env.BCMS_INSTANCE_ID || '',
{
id: process.env.BCMS_API_KEY_ID || '',
secret: process.env.BCMS_API_KEY_SECRET || '',
},
{
injectSvg: true,
},
);
export const createPages = async ({
actions: { createPage },
}: CreatePagesArgs) => {
// HOME
const homeTemplate = path.resolve('./src/templates/home.tsx');
const homePageEntry = (await bcms.entry.getBySlug(
'home',
'home-page',
)) as HomePageEntry;
const homePageMeta = homePageEntry.meta.en as HomePageEntryMetaItem;
const episodes = await bcms.entry.getAll('episode') as EpisodeEntry[];
const episodesMeta = episodes.map((episode) => episode.meta.en as EpisodeEntryMetaItem);
createPage({
path: `/`,
component: homeTemplate,
context: {
meta: homePageMeta,
episodes: episodesMeta,
bcms: bcms.getConfig(),
} as HomePageContent,
});
// ABOUT
const aboutTemplate = path.resolve('./src/templates/about.tsx');
const aboutPageEntry = (await bcms.entry.getBySlug(
'about-us',
'about-page',
)) as AboutPageEntry;
const aboutPageMeta = aboutPageEntry.meta.en as AboutPageEntryMetaItem;
createPage({
path: `/about`,
component: aboutTemplate,
context: {
meta: aboutPageMeta,
episodes: episodesMeta,
bcms: bcms.getConfig(),
} as AboutPageContent,
});
// NOW PLAYING
const nowPlayingTemplate = path.resolve('./src/templates/now-playing.tsx');
createPage({
path: `/now-playing`,
component: nowPlayingTemplate,
context: {
episodes: episodesMeta,
bcms: bcms.getConfig()
} as NowPlayingPageContent,
});
// EPISODE
const episodeTemplate = path.resolve('./src/templates/episode.tsx');
episodesMeta.forEach((episode) => {
createPage({
path: `/episode/${episode.slug}`,
component: episodeTemplate,
context: {
meta: episode,
episodes: episodesMeta,
bcms: bcms.getConfig(),
} as EpisodePageContent,
});
})
};