-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
60 lines (53 loc) · 1.9 KB
/
main.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
import {
parseSermonFromSanityResponse,
convertSermonToEpisode,
} from "./sermon";
import { createXml, writeEpisodesToFile } from "./rss/rss";
import { ccmSanityClient, sanitySermonQuery } from "./ccm_sanity_client";
import { RemoveAndRecreateDirectory, writeToFile } from "./fileFunctions";
import {
NetlifyRedirect,
netlifyRedirectFilename,
NetlifyRedirectToString,
} from "./netlifyRedirects";
import londonLivingRssConfig from "./config/londonliving.rssConfig.json";
import LondonLivingData from "./config/londonLiving.episodes.json";
import ccmSermonsRssConfig from "./config/sermons.rssConfig.json";
// Setup publish directory
const publishDirectory = "./public";
RemoveAndRecreateDirectory(publishDirectory);
// Set up and write netlify redirects
const netlifyRedirects: NetlifyRedirect[] = [
{ from: "/", to: "/sermons.xml", status: 200 },
{ from: "/londonliving", to: "/londonliving.xml", status: 200 },
];
writeToFile(
netlifyRedirects.map(NetlifyRedirectToString).join("\n"),
publishDirectory,
netlifyRedirectFilename
);
// Create London Living RSS
const londonLivingXml = createXml(
LondonLivingData,
new Date(),
londonLivingRssConfig
);
writeToFile(londonLivingXml, publishDirectory, "londonliving.xml");
// Create sermons RSS from Sanity
ccmSanityClient
.fetch(sanitySermonQuery)
.then((result) => result.filter((obj:any) => obj.url !== undefined).map(parseSermonFromSanityResponse))
.then((sermons) => sermons.map(convertSermonToEpisode))
.then((episodes) =>
writeEpisodesToFile(
ccmSermonsRssConfig,
episodes,
publishDirectory,
"sermons.xml"
)
)
.catch((error) => {
console.log("There was an error fetching the sermon data from sanity");
console.log(error)
process.exit(1); // Exit with non zero error code to indicate this should not be published.
});