-
Notifications
You must be signed in to change notification settings - Fork 0
/
config-manager.js
207 lines (191 loc) · 4.92 KB
/
config-manager.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
Helper methods for managing config server-side
----------------------------------------------
*/
// Constants
const config = {
metadata: {
shortTitle: 'Mergist',
title: 'Mergist - Online PDF Merger',
author: 'John Goodliff',
authorUsername: 'jerboa88',
shortDescription: 'Mergist is an online tool to combine multiple PDF files into one',
description: 'Mergist is an online tool to combine multiple PDF files into one. Mergist has no ads, no file size limits, and your files never leave your device.',
ogImageUrl: 'images/og-image.png',
ogImageAltText: 'Mergist logo',
siteUrl: 'https://mergist.johng.io/',
githubUrl: 'https://github.com/jerboa88/mergist/',
homepageDomain: 'johng.io',
trackingId: 'G-TYRQSQ9QC3',
},
theme: {
light: {
'primary-header': '#F4511E', // MD Deep Orange 600
'primary': '#E64A19', // MD Deep Orange 700
'secondary-header': '#1976D2', // MD Blue 700
'secondary': '#1565C0', // MD Blue 800
'accent': '#673AB7', // MD Purple 500
'neutral': 'hsl(220 15% 10%)',
'info': '#0277BD', // MD Light Blue 800
'success': '#558B2F', // MD Light Green 800
'warning': '#FF6F00', // MD Amber 800
'error': '#C62828', // MD Red 800
'base-100': 'hsl(0 0% 100%)',
'base-200': 'hsl(0 0% 98%)',
'base-300': 'hsl(0 0% 96%)'
},
dark: {
'primary-header': '#FFC107', // MD Amber 500
'primary': '#FFCA28', // MD Amber 400
'secondary-header': '#E91E63', // MD Pink 500
'secondary': '#F06292', // MD Pink 300
'accent': '#26C6DA', // MD Cyan 400
'neutral': 'hsl(220 15% 10%)',
'info': '#4FC3F7', // MD Light Blue 300
'success': '#AED581', // MD Light Green 300
'warning': '#FFD54F', // MD Amber 300
'error': '#E57373', // MD Red 300
'base-100': 'hsl(220 18% 13%)',
'base-200': 'hsl(220 16% 11%)',
'base-300': 'hsl(220 15% 10%)'
},
},
// Image generation config to pass to gatsby-plugin-image-generator
ogImage: {
from: 'images/og-image.png',
to: [
{
path: 'images/og-image.png',
size: [1200, 630],
}
]
},
// We can generate the webmanifest config from this
icons: [
{
from: 'images/maskable-icon.svg',
to: [
{
path: 'icons/maskable-icon.png',
size: 512
}
],
options: {
optimize: true
}
},
{
from: 'images/icon.svg',
to: [
{
path: 'favicon.svg',
size: 1024
},
{
path: 'favicon-32x32.png',
size: 32
},
{
path: 'icons/icon-48x48.png',
size: 48
},
{
path: 'icons/icon-72x72.png',
size: 72
},
{
path: 'icons/icon-96x96.png',
size: 96
},
{
path: 'icons/icon-144x144.png',
size: 144
},
{
path: 'icons/icon-192x192.png',
size: 192
},
{
path: 'icons/icon-256x256.png',
size: 256
},
{
path: 'icons/icon-384x384.png',
size: 384
},
{
path: 'icons/icon-512x512.png',
size: 512
}
],
options: {
optimize: true
}
},
],
};
// Exports
// Class for loading and formatting configuration data
class ConfigManager {
// Return metadata for the site
getMetadata() {
return config.metadata;
}
// Return a a daisyUI theme given its name
getTheme(themeName) {
const theme = config.theme[themeName];
if (!theme) {
throw new Error(`Theme ${themeName} not found`);
}
const bgColor = theme['base-100'];
return {
...theme,
// Custom vars for header colors
'--ph': theme['primary-header'],
'--sh': theme['secondary-header'],
'primary-content': bgColor,
'secondary-content': bgColor,
'accent-content': bgColor,
'info-content': bgColor,
'success-content': bgColor,
'warning-content': bgColor,
'error-content': bgColor,
};
}
// Returns the OpenGraph image generation config
getOgImage() {
return config.ogImage;
}
// Returns the icon generation config
getIcons() {
return config.icons;
}
// Generate icon entries for the site's webmanifest using the provided icon generation config
getIconManifestEntries() {
// Flatten after mapping as we do not need to keep any info about how the icons are generated
return config.icons.flatMap(inputRule => {
return inputRule.to.map(outputRule => {
return {
src: outputRule.path,
sizes: `${outputRule.size}x${outputRule.size}`,
type: this.getMimeTypeFromPath(outputRule.path),
// If the icon name contains `maskable`, set the purpose property to `maskable`
purpose: outputRule.path.match(/maskable/) ? 'maskable' : 'any'
};
});
});
}
// Returns the mime type for the provided image path
getMimeTypeFromPath(path) {
if (path.endsWith('.svg')) {
return 'image/svg+xml';
} else {
const match = path.match(/\.(jpg|jpeg|png|webp|gif|avif|tif|tiff)$/i);
if (!match || match.length < 2) {
throw new Error(`Could not determine mime type for image path ${path}`);
}
return `image/${match[1]}`;
}
}
};
module.exports = ConfigManager;