-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfiguration.js
158 lines (154 loc) · 5.05 KB
/
configuration.js
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// BEWARE: Don't use JS module syntax yet, next.js will not compile
const { join } = require("path");
const generateConfiguration = (() => {
const configuration = {};
const defaultValues = {
linkColor: process.env.THEME_COLOR_LINK,
nameMark: process.env.NAME_MARK,
protocol: process.env.PROTOCOL,
domain: process.env.DOMAIN,
timeLocale: process.env.TIME_LOCALE,
timeFormat: process.env.TIME_FORMAT,
publicDirectory: process.env.FOLDER_PUBLIC
? join(process.cwd(), process.env.FOLDER_PUBLIC)
: null,
episodesDirectory: process.env.FOLDER_EPISODES
? join(process.cwd(), process.env.FOLDER_EPISODES)
: null,
pagesDirectory: process.env.FOLDER_PAGES
? join(process.cwd(), process.env.FOLDER_PAGES)
: null,
primaryColor: "green",
secondaryColor: "red",
tertiaryColor: "blue",
coverImage: process.env.COVER_IMAGE,
coverVideo: process.env.COVER_VIDEO,
backgroundColor: process.env.BACKGROUND_COLOR,
textColor: process.env.TEXT_COLOR,
attachmentColor: process.env.ATTACHMENT_COLOR,
storyTitle: process.env.STORY_TITLE,
publisher: process.env.PODCAST_PUBLISHER,
publisherLogo: process.env.PODCAST_PUBLISHER_LOGO,
posterPortrait: process.env.POSTER_PORTRAIT,
hamburger: process.env.HAMBURGER ? process.env.HAMBURGER.split(" ") : null,
ctaSubscribe: process.env.CTA_SUBSCRIBE,
ctaDescribe: process.env.CTA_DESCRIBE,
ctaInvite: process.env.CTA_INVITE,
crawling: process.env.CRAWLING,
};
const fallbackValues = {
linkColor: "#ff2a9d",
nameMark: "ACME",
locale: "en",
protocol: "http",
domain: "localhost",
format: "YYYY-MM-DD",
publicDirectory: join(process.cwd(), "tests/fixtures/public"),
episodesDirectory: join(process.cwd(), "tests/fixtures/episodes"),
pagesDirectory: join(process.cwd(), "tests/fixtures/pages"),
coverImage: "",
coverVideo: "",
backgroundColor: "#000",
textColor: "#fff",
attachmentColor: "red",
storyTitle: "Story Title",
publisher: "Publisher Name",
publisherLogo: "",
posterPortrait: "",
hamburger: ["imprint privacy"],
ctaSubscribe: "Subscribe",
ctaDescribe: "Available on these podcast providers",
ctaInvite: "Click to subscribe and never miss an episode!",
crawling: "noindex",
};
const socialMedia = {
email: {
name: "Email",
base: "mailto:",
handle: process.env.SOCIALMEDIA_EMAIL_HANDLE,
},
facebook: {
name: "Facebook",
base: "https://www.facebook.com/",
handle: process.env.SOCIALMEDIA_FACEBOOK_HANDLE,
},
github: {
name: "GitHub",
base: "https://github.com/",
handle: process.env.SOCIALMEDIA_GITHUB_HANDLE,
},
instagram: {
name: "Instagram",
base: "https://www.instagram.com/",
handle: process.env.SOCIALMEDIA_INSTAGRAM_HANDLE,
},
snapchat: {
name: "Snapchat",
base: "https://www.snapchat.com/add/",
handle: process.env.SOCIALMEDIA_SNAPCHAT_HANDLE,
},
twitter: {
name: "Twitter",
base: "https://www.twitter.com/",
handle: process.env.SOCIALMEDIA_TWITTER_HANDLE,
},
youtube: {
name: "Youtube",
base: "https://www.youtube.com/channel/",
handle: process.env.SOCIALMEDIA_YOUTUBE_HANDLE,
},
tiktok: {
name: "TikTok",
base: "https://www.tiktok.com/",
handle: process.env.SOCIALMEDIA_TIKTOK_HANDLE,
},
};
const podcasts = {
spotify: {
name: "Spotify",
show: process.env.PODCAST_AGGREGATOR_SPOTIFY_SHOW,
image: process.env.PODCAST_AGGREGATOR_SPOTIFY_IMAGE,
},
apple: {
name: "Apple",
show: process.env.PODCAST_AGGREGATOR_APPLE_SHOW,
image: process.env.PODCAST_AGGREGATOR_APPLE_IMAGE,
},
google: {
name: "Google",
show: process.env.PODCAST_AGGREGATOR_GOOGLE_SHOW,
image: process.env.PODCAST_AGGREGATOR_GOOGLE_IMAGE,
},
deezer: {
name: "Deezer",
show: process.env.PODCAST_AGGREGATOR_DEEZER_SHOW,
image: process.env.PODCAST_AGGREGATOR_DEEZER_IMAGE,
},
tunein: {
name: "TuneIn",
show: process.env.PODCAST_AGGREGATOR_TUNEIN_SHOW,
image: process.env.PODCAST_AGGREGATOR_TUNEIN_IMAGE,
},
};
configuration.socialmedia = {};
configuration.podcasts = {};
// Check whether a value is undefined and fall back to default values if so
for (const [key, value] of Object.entries(defaultValues)) {
const isConfKey = defaultValues[key];
isConfKey
? (configuration[key] = value)
: (configuration[key] = fallbackValues[key]);
}
// Check whether a value to be added is undefined and skip it if so
for (const [key, value] of Object.entries(socialMedia)) {
const isConfKey = socialMedia[key].handle;
isConfKey && (configuration.socialmedia[key] = value);
}
for (const [key, value] of Object.entries(podcasts)) {
const isConfShow = podcasts[key].show;
const isConfImage = podcasts[key].image;
isConfShow && isConfImage && (configuration.podcasts[key] = value);
}
return configuration;
})();
module.exports = generateConfiguration;