-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathprerender-urls.js
173 lines (168 loc) · 6.12 KB
/
prerender-urls.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
module.exports = async function () {
let urlArray = [
{
url: '/',
title: '1tuner',
subtitle: 'listen to radio, podcasts and create playlists',
description: 'Listen to radio, podcasts and create playlists.',
logo: 'https://1tuner.com/assets/icons/icon-512x512.png',
jsonld: {
'@context': 'https://schema.org',
'@type': 'WebApplication',
name: '1tuner',
url: 'https://1tuner.com',
image: 'https://1tuner.com/assets/icons/icon-512x512.png',
thumbnailUrl: 'https://1tuner.com/assets/icons/icon-192x192.png',
operatingSystem: 'All',
applicationCategory: 'Entertainment',
aggregateRating: {
'@type': 'AggregateRating',
ratingValue: '5',
ratingCount: '1',
},
offers: {
'@type': 'Offer',
price: '0',
priceCurrency: 'EUR',
},
sameAs: ['https://twitter.com/1tuner', 'https://bsky.app/profile/1tuner.com', 'https://github.com/robinbakker/1tuner'],
author: {
'@type': 'Person',
name: 'Robin Bakker',
url: 'https://robinbakker.nl',
sameAs: [
'https://twitter.com/robinbakker',
'https://mastodon.social/@robinbakker',
'https://bsky.app/profile/robinbakker.nl',
'https://github.com/robinbakker',
],
},
},
},
{
url: '/about',
title: 'About 1tuner',
subtitle: 'one web app to listen to audio streams',
description: 'Listen to radio, podcasts and create playlists.',
logo: 'https://1tuner.com/assets/icons/icon-512x512.png',
},
{
url: '/podcasts',
title: 'Podcasts',
subtitle: '1tuner | listen to podcasts',
description: 'Listen to radio, podcasts and create playlists.',
logo: 'https://1tuner.com/assets/icons/icon-512x512.png',
},
{
url: '/playlists',
title: 'Playlists',
subtitle: '1tuner | take control',
description: 'Listen to radio, podcasts and create playlists.',
logo: 'https://1tuner.com/assets/icons/icon-512x512.png',
},
{
url: '/playlist-edit',
title: 'Add a playlist',
subtitle: '1tuner | take control',
description: 'Listen to radio, podcasts and create playlists.',
logo: 'https://1tuner.com/assets/icons/icon-512x512.png',
},
{
url: '/settings',
title: 'Settings',
subtitle: '1tuner | one web app to listen to audio streams',
description: 'Listen to radio, podcasts and create playlists.',
logo: 'https://1tuner.com/assets/icons/icon-512x512.png',
},
];
await fetch('https://raw.githubusercontent.com/robinbakker/1tuner/master/assets/data/stations.json', {
method: 'get',
})
.then((resp) => resp.json())
.then(function (items) {
urlArray.push({
url: '/radio-stations',
title: 'Radio stations',
subtitle: '1tuner | listen to the radio',
description: 'Listen to radio, podcasts and create playlists.',
logo: 'https://1tuner.com/assets/icons/icon-512x512.png',
data: items,
});
for (let item in items) {
urlArray.push({
url: '/radio-station/' + item,
title: items[item].name,
subtitle: 'Radio station | 1tuner',
description: 'Listen now to ' + items[item].name + ' at 1tuner.com',
logo: items[item].logosource,
data: items[item],
});
}
});
// OK this feels stupid
const slugify = function (text) {
const a = 'àáâäæãåāăąçćčđďèéêëēėęěğǵḧîïíīįìłḿñńǹňôöòóœøōõőṕŕřßśšşșťțûüùúūǘůűųẃẍÿýžźż·/_,:;';
const b = 'aaaaaaaaaacccddeeeeeeeegghiiiiiilmnnnnoooooooooprrsssssttuuuuuuuuuwxyyzzz------';
const p = new RegExp(a.split('').join('|'), 'g');
return text
.toString()
.toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(p, (c) => b.charAt(a.indexOf(c))) // Replace special characters
.replace(/&/g, '-and-') // Replace & with 'and'
.replace(/[^\w\-]+/g, '') // Remove all non-word characters
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
};
let podcastDataUrl = 'https://raw.githubusercontent.com/robinbakker/1tuner/master/assets/data/podcasts.json';
// FIXME: move this to a better place... :/
require('dotenv').config();
if (process.env.FIREBASE_LOGIN_URL && process.env.FIREBASE_LOGIN_URL !== 'https://example.com') {
const firebaseAuth = await fetch(process.env.FIREBASE_LOGIN_URL, {
body: JSON.stringify({
email: process.env.FIREBASE_USER_EMAIL,
password: process.env.FIREBASE_USER_PASSWORD,
returnSecureToken: true,
}),
method: 'POST',
});
const firebaseAuthResult = await firebaseAuth.json();
const firebaseAuthToken = firebaseAuthResult.idToken;
podcastDataUrl = `${process.env.FIREBASE_URL}/podcasts.json?auth=${firebaseAuthToken}`;
}
try {
await fetch(podcastDataUrl, {
method: 'get',
})
.then((resp) => resp.json())
.then(function (data) {
let keyArray = Object.keys(data);
keyArray.reverse();
let newDataArray = [];
for (let i = 0; i < 500; i++) {
let pc = data[keyArray[i]];
if (!pc || !pc.feedUrl || !pc.title) {
console.log('podcast data error', pc);
continue;
}
if (pc.feedUrl.indexOf('https://feeds.megaphone.fm/fullsend') !== -1) {
// DMCA Takedown Request
continue;
}
urlArray.push({
url: '/podcast/' + slugify(pc.title) + '/' + Buffer.from(pc.feedUrl).toString('base64'),
title: pc.title,
subtitle: 'Podcast | 1tuner',
description: 'Listen now to ' + pc.title + ' at 1tuner.com',
logo: pc.logo,
data: pc,
});
newDataArray.push(pc);
}
});
} catch (error) {
console.log('fetch podcast data error', error);
}
return urlArray;
};