-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseSearchableData.js
More file actions
424 lines (406 loc) · 12.3 KB
/
useSearchableData.js
File metadata and controls
424 lines (406 loc) · 12.3 KB
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
import { useEffect, useMemo, useState } from 'react';
import piml from 'piml';
const useSearchableData = () => {
const [items, setItems] = useState([]);
const [isLoading, setIsLoading] = useState(true);
const categories = useMemo(
() => [
'Book',
'Movie',
'Video',
'Game',
'Article',
'Music',
'Series',
'Food',
'Websites',
'Tools',
'Event',
],
[],
);
useEffect(() => {
const fetchData = async () => {
setIsLoading(true);
try {
const fetchLogPromises = categories.map(async (category) => {
const response = await fetch(
`/logs/${category.toLowerCase()}/${category.toLowerCase()}.piml`,
);
if (!response.ok) {
console.warn(
`Category PIML not found for ${category}: ${response.statusText}`,
);
return [];
}
const text = await response.text();
const data = piml.parse(text);
return data.logs || [];
});
const [postsRes, projectsRes, allLogsArrays, appsRes] =
await Promise.all([
fetch('/posts/posts.json'),
fetch('/projects/projects.piml'),
Promise.all(fetchLogPromises), // Await all log category fetches
fetch('/apps/apps.json'),
]);
const postsData = await postsRes.json();
const pimlProjectsText = await projectsRes.text();
const parsedPimlProjects = piml.parse(pimlProjectsText);
let projectListRaw = [];
if (
parsedPimlProjects.projects &&
Array.isArray(parsedPimlProjects.projects)
) {
projectListRaw = parsedPimlProjects.projects;
} else if (
parsedPimlProjects.item &&
Array.isArray(parsedPimlProjects.item)
) {
projectListRaw = parsedPimlProjects.item;
} else if (Array.isArray(parsedPimlProjects)) {
projectListRaw = parsedPimlProjects;
} else if (typeof parsedPimlProjects === 'object') {
projectListRaw =
Object.values(parsedPimlProjects).find((val) =>
Array.isArray(val),
) || [];
}
// Post-process project list to handle types and arrays (consistent with projectParser.js)
const projectsData = projectListRaw.map((project) => ({
...project,
size: project.size ? parseInt(project.size, 10) : 1,
pinned: String(project.pinned).toLowerCase() === 'true',
isActive: String(project.isActive).toLowerCase() === 'true',
technologies: project.technologies
? typeof project.technologies === 'string'
? project.technologies.split(',').map((t) => t.trim())
: project.technologies
: [],
}));
const appsData = await appsRes.json();
const combinedLogs = allLogsArrays.flat(); // Flatten the array of arrays from logs
// Process Apps
const allApps = Object.values(appsData)
.flatMap((category) => category.apps)
.map((app) => ({
...app,
type: 'app',
path: app.to,
}));
// Process Posts
const allPosts = postsData.flatMap((item) =>
item.series
? item.series.posts.map((p) => ({
...p,
type: 'post',
title: `${item.title}: ${p.title}`,
path: `/blog/series/${item.slug}/${p.slug}`,
}))
: { ...item, type: 'post', path: `/blog/${item.slug}` },
);
// Process Projects
const allProjects = projectsData.map((p) => ({
...p,
type: 'project',
path: `/projects/${p.slug}`,
}));
// Process Logs
const allLogs = combinedLogs.map((l) => ({
...l,
type: 'log',
path: `/logs/${l.category.toLowerCase()}/${l.slug}`,
}));
// Define static routes and custom commands
const staticRoutes = [
{ title: 'Home', slug: '/', type: 'page', path: '/' },
{ title: 'Blog', slug: '/blog', type: 'page', path: '/blog' },
{
title: 'Projects',
slug: '/projects',
type: 'page',
path: '/projects',
},
{ title: 'About Me', slug: '/about', type: 'page', path: '/about' },
{ title: 'Logs', slug: '/logs', type: 'page', path: '/logs' },
{
title: 'Fezzilla Roadmap',
slug: '/roadmap',
type: 'page',
path: '/roadmap',
},
{
title: 'Timeline',
slug: '/timeline',
type: 'page',
path: '/timeline',
},
{
title: 'Settings',
slug: '/settings',
type: 'page',
path: '/settings',
},
{
title: 'Stories',
slug: '/stories',
type: 'page',
path: '/stories',
},
{ title: 'Glossary', slug: '/vocab', type: 'page', path: '/vocab' },
{ title: 'Apps', slug: '/apps', type: 'page', path: '/apps' },
{ title: 'Random', slug: '/random', type: 'page', path: '/random' },
];
const customCommands = [
{
title: 'Toggle Syntax Sprite (Buddy)',
type: 'command',
commandId: 'toggleSyntaxSprite',
},
{
title: 'Switch Visual Theme',
type: 'command',
commandId: 'switchTheme',
},
{
title: 'View Source on GitHub',
type: 'command',
commandId: 'viewSource',
},
{
title: 'Navigate to a Random Post',
type: 'command',
commandId: 'randomPost',
},
{
title: 'Toggle Reduced Motion',
type: 'command',
commandId: 'toggleAnimations',
},
{
title: 'Reset Sidebar State',
type: 'command',
commandId: 'resetSidebarState',
},
{
title: 'Send Email',
type: 'command',
commandId: 'sendEmailFezcode',
},
{
title: 'Open GitHub Profile',
type: 'command',
commandId: 'openGitHub',
},
{
title: 'Open Twitter Profile',
type: 'command',
commandId: 'openTwitter',
},
{
title: 'Open LinkedIn Profile',
type: 'command',
commandId: 'openLinkedIn',
},
{ title: 'Scroll to Top', type: 'command', commandId: 'scrollToTop' },
{
title: 'Scroll to Bottom',
type: 'command',
commandId: 'scrollToBottom',
},
{
title: 'Show Site Stats',
type: 'command',
commandId: 'showSiteStats',
},
{ title: 'Show Version', type: 'command', commandId: 'showVersion' },
{
title: 'Go to Latest Post',
type: 'command',
commandId: 'latestPost',
},
{
title: 'Go to Latest Log',
type: 'command',
commandId: 'latestLog',
},
{
title: 'Show Current Time',
type: 'command',
commandId: 'showTime',
},
{
title: 'Toggle Digital Rain',
type: 'command',
commandId: 'digitalRain',
},
{ title: 'Generate Art', type: 'command', commandId: 'generateArt' },
{
title: 'Leet Speak Transformer',
type: 'command',
commandId: 'leetTransformer',
},
{
title: 'Show Quick Stopwatch',
type: 'command',
commandId: 'stopwatch',
},
{
title: 'Show User/Browser Information',
type: 'command',
commandId: 'showOSInfo',
},
{
title: 'Copy Current URL',
type: 'command',
commandId: 'copyCurrentURL',
},
{
title: 'Clear Local Storage',
type: 'command',
commandId: 'clearLocalStorage',
},
{ title: 'Reload Page', type: 'command', commandId: 'reloadPage' },
{
title: 'Go to Random App',
type: 'command',
commandId: 'randomApp',
},
{
title: 'Toggle Full Screen',
type: 'command',
commandId: 'toggleFullScreen',
},
{
title: 'Create Issue for This Page',
type: 'command',
commandId: 'openGitHubIssue',
},
{ title: 'Her Daim', type: 'command', commandId: 'herDaim' },
{
title: 'Do a Barrel Roll',
type: 'command',
commandId: 'doBarrelRoll',
},
{
title: 'Toggle Invert Colors',
type: 'command',
commandId: 'toggleInvertColors',
},
{ title: 'Party Mode', type: 'command', commandId: 'partyMode' },
{
title: 'Toggle Retro Mode',
type: 'command',
commandId: 'toggleRetroMode',
},
{
title: 'Toggle Mirror Mode',
type: 'command',
commandId: 'toggleMirrorMode',
},
{
title: 'Toggle Noir Mode',
type: 'command',
commandId: 'toggleNoirMode',
},
{
title: 'Toggle Terminal Mode',
type: 'command',
commandId: 'toggleTerminalMode',
},
{
title: 'Toggle Blueprint Mode',
type: 'command',
commandId: 'toggleBlueprintMode',
},
{
title: 'Toggle Sepia Mode',
type: 'command',
commandId: 'toggleSepiaMode',
},
{
title: 'Toggle Vaporwave Mode',
type: 'command',
commandId: 'toggleVaporwaveMode',
},
{
title: 'Toggle Cyberpunk Mode',
type: 'command',
commandId: 'toggleCyberpunkMode',
},
{
title: 'Toggle Game Boy Mode',
type: 'command',
commandId: 'toggleGameboyMode',
},
{
title: 'Toggle Comic Book Mode',
type: 'command',
commandId: 'toggleComicMode',
},
{
title: 'Toggle Sketchbook Mode',
type: 'command',
commandId: 'toggleSketchbookMode',
},
{
title: 'Toggle Hellenic Mode',
type: 'command',
commandId: 'toggleHellenicMode',
},
{
title: 'Toggle Dystopian Glitch Mode',
type: 'command',
commandId: 'toggleGlitchMode',
},
{
title: 'Toggle Garden Mode',
type: 'command',
commandId: 'toggleGardenMode',
},
{
title: 'Toggle Autumn Mode',
type: 'command',
commandId: 'toggleAutumnMode',
},
{
title: 'Toggle Rain Mode',
type: 'command',
commandId: 'toggleRainMode',
},
{
title: 'Toggle Fallout Overlay',
type: 'command',
commandId: 'toggleFalloutMode',
},
{
title: 'Switch Fallout Overlay Color (Amber/Green)',
type: 'command',
commandId: 'switchFalloutVariant',
},
{
title: 'Previous Page',
type: 'command',
commandId: 'previousPage',
},
{ title: 'Next Page', type: 'command', commandId: 'nextPage' },
];
setItems([
...staticRoutes,
...customCommands,
...allPosts,
...allProjects,
...allLogs,
...allApps,
]);
} catch (error) {
console.error('Failed to fetch search data:', error);
} finally {
setIsLoading(false);
}
};
fetchData();
}, [categories]);
return { items, isLoading };
};
export default useSearchableData;