-
Notifications
You must be signed in to change notification settings - Fork 206
/
Copy pathcategories.js
299 lines (247 loc) · 7.88 KB
/
categories.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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
// Universal JS imports only
import shuffle from 'just-shuffle'
import { makeSlug } from './slug.js'
export function makeCategorySlug ( categoryName ) {
return makeSlug( categoryName )
}
// Maps iTunes Genres titles to Category IDs
const categoryMap = new Map([
[ 'Business', 2 ],
[ 'Entertainment', 5 ],
[ 'Finance', 2 ],
[ 'Music', 6 ],
[ 'Photo & Video', 7 ],
[ 'Productivity', 2 ],
[ 'Utilities', 12 ],
[ 'Graphics & Design', 7 ],
[ 'Developer Tools', 1 ],
// [ 'Name', 1 ],
// Needs work before apps can be assigned games category
// Games will be assigned to the "Games" category
// but need to be put into games kind/list
// so the solution may be to separate games from apps
// during app list build and then merge "Game from Apps"
// into the "Games" list
// but for now 'Games' genre is Entertainment
// [ 'Games', 100 ],
[ 'Games', 5 ],
])
// Maps App Store Genre to categort IDS
export function getCategoryIdForGenre ( genreName ) {
// If we don't have this genre mapped
// then return nothing
if ( !categoryMap.has(genreName) ) return null
// return this category id mapped to this genre
return categoryMap.get( genreName )
}
// Contains all types of properies to keep data consistent
export const categoryTemplate = {
label: null,
pluralLabel: null,
itemSuffixLabel: null,
icon: null,
requestLinks: null,
icon: '💻',
}
export const categories = {
'no-category': {
id: 0,
label: ''
},
// App lists
'developer-tools': {
id: 1,
...categoryTemplate,
label: 'Developer Tools',
pluralLabel: 'Developer Tools',
slug: 'developer-tools',
snakeSlug: 'developer_tools',
},
'productivity-tools': {
id: 2,
...categoryTemplate,
label: 'Productivity Tools',
pluralLabel: 'Productivity Tools',
slug: 'productivity-tools',
snakeSlug: 'productivity_tools',
},
'video-and-motion-tools': {
id: 3,
...categoryTemplate,
label: 'Video and Motion Tools',
pluralLabel: 'Video and Motion Tools',
slug: 'video-and-motion-tools',
snakeSlug: 'video_and_motion_tools',
},
'social-and-communication': {
id: 4,
...categoryTemplate,
label: 'Social and Communication',
pluralLabel: 'Social and Communication Apps',
slug: 'social-and-communication',
snakeSlug: 'social_and_communication',
},
'entertainment-and-media-apps': {
id: 5,
...categoryTemplate,
label: 'Entertainment and Media Apps',
pluralLabel: 'Entertainment and Media Apps',
slug: 'entertainment-and-media-apps',
snakeSlug: 'entertainment_and_media_apps',
},
'music-and-audio-tools': {
id: 6,
...categoryTemplate,
label: 'Music and Audio Tools',
pluralLabel: 'Music and Audio Tools',
slug: 'music-and-audio-tools',
snakeSlug: 'music_and_audio_tools',
},
'photo-and-graphic-tools': {
id: 7,
...categoryTemplate,
label: 'Photo and Graphic Tools',
pluralLabel: 'Photo and Graphic Tools',
slug: 'photo-and-graphic-tools',
snakeSlug: 'photo_and_graphic_tools',
},
'science-and-research-software': {
id: 8,
...categoryTemplate,
label: 'Science and Research Software',
pluralLabel: 'Science and Research Software',
slug: 'science-and-research-software',
snakeSlug: 'science_and_research_software',
},
'3d-and-architecture': {
id: 9,
...categoryTemplate,
label: '3D and Architecture',
pluralLabel: '3D and Architecture Applications',
slug: '3d-and-architecture',
snakeSlug: '3d_and_architecture',
},
'vpns-security-and-privacy': {
id: 10,
...categoryTemplate,
label: 'VPNs, Security, and Privacy',
pluralLabel: 'VPN, Security, and Privacy Applications',
slug: 'vpns-security-and-privacy',
snakeSlug: 'vpns_security_and_privacy',
},
'live-production-and-performance': {
id: 11,
...categoryTemplate,
label: 'Live Production and Performance',
pluralLabel: 'Live Production and Performance Software',
slug: 'live-production-and-performance',
snakeSlug: 'live_production_and_performance',
},
'system-tools': {
id: 12,
...categoryTemplate,
label: 'System Tools',
pluralLabel: 'System Tools',
slug: 'system-tools',
snakeSlug: 'system_tools',
},
// Special Lists
'games': {
id: 100,
...categoryTemplate,
label: 'Games',
pluralLabel: 'Games',
slug: 'games',
snakeSlug: 'games',
icon: '🎮',
requestLinks: [
{
href: 'https://forms.gle/29GWt85i1G1L7Ttj8',
label: 'Request a Game'
}
]
},
'homebrew': {
id: 101,
...categoryTemplate,
label: 'Homebrew',
pluralLabel: 'Homebrew Formulae',
itemSuffixLabel: 'via Homebrew',
slug: 'homebrew',
snakeSlug: 'homebrew',
icon: '🍺'
},
// Uncategorized
'uncategorized': {
id: 1000,
...categoryTemplate,
label: 'Uncategorized',
pluralLabel: 'Uncategorized Software',
slug: 'uncategorized',
snakeSlug: 'uncategorized',
},
}
// Maps categories to kinds and vice versa
const categoryToKind = {
...Object.fromEntries( Object.keys( categories ).map( key => [ key, key ] ) ),
'homebrew': 'formula',
'games': 'game',
}
// Respective directory for each category
export function getCategoryKindName ( categorySlug ) {
return categoryToKind[ categorySlug ]
}
export function getKindToCategorySlug ( kindSlug ) {
return Object.keys( categories ).find( key => categoryToKind[ key ] === kindSlug )
}
export const categoriesById = Object.fromEntries( Object.entries( categories ).map( ([ key, category ]) => [category.id, { ...category, key } ] ) )
export function getAppCategory (app) {
if (typeof app.category === 'undefined') {
console.log('app', app)
}
// If this category is not defined yet
// then add it
if ( !categories.hasOwnProperty( app.category.slug ) ) {
// console.log('app', app)
const customCategory = {
id: null,
...app.category,
}
categories[app.category.slug] = customCategory
console.log('Added new category', app.category.slug)
}
return categories[app.category.slug]
}
const categoryFilterPrefix = 'category_'
export function makeCategoryFilterFromListing ( listing ) {
return `${ categoryFilterPrefix }${ getAppCategory( listing ).snakeSlug }`
}
export function makeCategoryFilterFromCategorySlug ( categorySlug ) {
const category = categories[ categorySlug ]
return `${ categoryFilterPrefix }${ category.snakeSlug }`
}
export function findCategoryForTagsSet ( tags ) {
for ( const tag of tags ) {
const categoryIdForGenre = getCategoryIdForGenre( tag )
// Skip non-mapped genres
if ( categoryIdForGenre === null ) continue
// const foundCategory = categoriesById[ categoryIdForGenre ]
// category.label = foundCategory.label
// category.slug = foundCategory.slug
return categoriesById[ categoryIdForGenre ]
}
return null
}
const sampleListFormatter = new Intl.ListFormat( 'en', { style: 'long', type: 'unit' })
export function makeSummaryOfListings ({
list,
length = 25,
random = false,
suffix = ', etc...',
} = {}) {
const listToSample = random ? shuffle( list ) : list
const samples = listToSample
.slice(0, length)
.map( listing => listing.name )
return sampleListFormatter.format( samples ) + suffix
}