-
Notifications
You must be signed in to change notification settings - Fork 2
/
generateRedirects.ts
54 lines (46 loc) · 1.77 KB
/
generateRedirects.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
/**
* This script generates Netlify redirects for some relevant links. It is run as part of the post-build
* step in `npm run build` (more specifically, `npm run redirects`).
*/
import { writeFileSync } from 'fs';
import { clubConfig, sponsorshipConfig, recruitmentConfig, redirectsConfig } from '../src/config';
// Redirects have format: '/path' + '\t' + 'targetURL'
const redirects = [
// socials
`/facebook\t${clubConfig.socials.facebook}`,
`/instagram\t${clubConfig.socials.instagram}`,
`/github\t${clubConfig.socials.github}`,
`/medium\t${clubConfig.socials.medium}`,
`/linkedin\t${clubConfig.socials.linkedin}`,
`/buttondown\t${clubConfig.socials.buttondown}`,
`/youtube\t${clubConfig.socials.youtube}`,
// google workplace (gsuite)
`/mail\thttps://mail.ubclaunchpad.com`,
`/calendar\thttp://calendar.ubclaunchpad.com`,
// sponsorship package
`/sponsorship\t${sponsorshipConfig.packageURL}`,
];
// applications
if (recruitmentConfig.applicationsOpen) {
recruitmentConfig.positions.forEach((p) => {
redirects.push(`/join/${p.name.toLowerCase()}\t${p.rolePageURL}`);
});
}
// custom redirects
redirectsConfig.forEach((r) => {
redirects.push(`${r.path}\t${r.target}`);
});
// write to Netlify `_redirects`, as well as a `redirects.txt` that we can access
console.log('generated redirects', redirects);
writeFileSync('./dist/_redirects', redirects.join('\n'));
writeFileSync('./dist/redirects.txt', `#
# redirects.txt
#
# This file lists all currently active redirects for https://ubclaunchpad.com - on the left of each
# row is the path that gets redirected, and on the right is the destination.
#
# For example, the first entry indicates that 'https://ubclaunchpad.com/facebook' will redirect to
# '${clubConfig.socials.facebook}'.
#
${redirects.join('\n')}
`);