This repository has been archived by the owner on Dec 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
upd8.js
2411 lines (2198 loc) · 112 KB
/
upd8.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
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
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// HEY N8RDS!
//
// This is one of the 8ACKEND FILES. It's not used anywhere on the actual site
// you are pro8a8ly using right now.
//
// Specifically, this one does all the actual work of the music wiki. The
// process looks something like this:
//
// 1. Crawl the music directories. Well, not so much "crawl" as "look inside
// the folders for each al8um, and read the metadata file descri8ing that
// al8um and the tracks within."
//
// 2. Read that metadata. I'm writing this 8efore actually doing any of the
// code, and I've gotta admit I have no idea what file format they're
// going to 8e in. May8e JSON, 8ut more likely some weird custom format
// which will 8e a lot easier to edit.
//
// 3. Generate the page files! They're just static index.html files, and are
// what gh-pages (or wherever this is hosted) will show to clients.
// Hopefully pretty minimalistic HTML, 8ut like, shrug. They'll reference
// CSS (and maaaaaaaay8e JS) files, hard-coded somewhere near the root.
//
// 4. Print an awesome message which says the process is done. This is the
// most important step.
//
// Oh yeah, like. Just run this through some relatively recent version of
// node.js and you'll 8e fine. ...Within the project root. O8viously.
// HEY FUTURE ME!!!!!!!! Don't forget to implement artist pages! Those are,
// like, the coolest idea you've had yet, so DO NOT FORGET. (Remem8er, link
// from track listings, etc!) --- Thanks, past me. To futurerer me: an al8um
// listing page (a list of all the al8ums)! Make sure to sort these 8y date -
// we'll need a new field for al8ums.
// ^^^^^^^^ DID THAT! 8ut also, artist images. Pro8a8ly stolen from the fandom
// wiki (I found half those images anywayz).
// TRACK ART CREDITS. This is a must.
// 2020-08-23
// ATTENTION ALL 8*TCHES AND OTHER GENDER TRUCKERS: AS IT TURNS OUT, THIS CODE
// ****SUCKS****. I DON'T THINK ANYTHING WILL EVER REDEEM IT, 8UT THAT DOESN'T
// MEAN WE CAN'T TAKE SOME ACTION TO MAKE WRITING IT A LITTLE LESS TERRI8LE.
// We're gonna start defining STRUCTURES to make things suck less!!!!!!!!
// No classes 8ecause those are a huge pain and like, pro8a8ly 8ad performance
// or whatever -- just some standard structures that should 8e followed
// wherever reasona8le. Only one I need today is the contri8 one 8ut let's put
// any new general-purpose structures here too, ok?
//
// Contri8ution: {who, what, date, thing}. D8 and thing are the new fields.
//
// Use these wisely, which is to say all the time and instead of whatever
// terri8le new pseudo structure you're trying to invent!!!!!!!!
'use strict';
const fs = require('fs');
const path = require('path');
const util = require('util');
// I made this dependency myself! A long, long time ago. It is pro8a8ly my
// most useful li8rary ever. I'm not sure 8esides me actually uses it, though.
const fixWS = require('fix-whitespace');
// Wait nevermind, I forgot a8out why-do-kids-love-the-taste-of-cinnamon-toast-
// crunch. THAT is my 8est li8rary.
// The require function just returns whatever the module exports, so there's
// no reason you can't wrap it in some decorator right out of the 8ox. Which is
// exactly what we do here.
const mkdirp = util.promisify(require('mkdirp'));
// This is the dum8est name for a function possi8le. Like, SURE, fine, may8e
// the UNIX people had some valid reason to go with the weird truncated
// lowercased convention they did. 8ut Node didn't have to ALSO use that
// convention! Would it have 8een so hard to just name the function something
// like fs.readDirectory???????? No, it wouldn't have 8een.
const readdir = util.promisify(fs.readdir);
// 8ut okay, like, look at me. DOING THE SAME THING. See, *I* could have named
// my promisified function differently, and yet I did not. I literally cannot
// explain why. We are all used to following in the 8ad decisions of our
// ancestors, and never never never never never never never consider that hey,
// may8e we don't need to make the exact same decisions they did. Even when
// we're perfectly aware th8t's exactly what we're doing! Programmers,
// including me, are all pretty stupid.
// 8ut I mean, come on. Look. Node decided to use readFile, instead of like,
// what, cat? Why couldn't they rename readdir too???????? As Johannes Kepler
// once so elegantly put it: "Shrug."
const readFile = util.promisify(fs.readFile);
const writeFile = util.promisify(fs.writeFile);
const access = util.promisify(fs.access);
const {
cacheOneArg,
decorateTime,
joinNoOxford,
progressPromiseAll,
queue,
s,
splitArray,
th
} = require('./upd8-util');
const C = require('./common');
// This can 8e changed if you want to output to some other directory. Just make
// sure static files are copied into it too! (Which, ahem. Might 8e a todo.)
// const C.SITE_DIRECTORY = '';
const SITE_TITLE = 'Homestuck Music Wiki';
const SITE_ABOUT = fixWS`
<p>Welcome to my fan-made Homestuck music wiki!</p>
<p><a href="https://www.homestuck.com/">Homestuck</a> has always been an incredible creative collaboration, and especially beloved by the community and critical in that collaboration is the webcomic and world's humongous soundtrack, comprising well over 500 tracks by dozens of musicians and artists. This wiki aims to be an interesting and useful resource for anyone interested in that music, as well as an archive for all things related.</p>
<p>Pertaining to the history of this site: it was originally made as a remake of Homestuck's official <a href="https://homestuck.bandcamp.com/">Bandcamp</a>, which saw its content particularly reduced on <a href="https://twitter.com/hamesatron/status/1187842783618297856">10/25/19</a>. This site aims to be a more reliable resource and reference: track art (conspicuously missing from the Bandcamp) is archived here, solo albums (among other missing albums, like [[album:Squiddles!]]) are all indexed in the one place, and URLs will always stay consistent. And of course, also included are links for listening on Bandcamp and other services.</p>
<p>The code for this website is open source (GPL-3.0), and can be explored or forked <a href="https://github.com/hsmusic/hsmusic.github.io/">here</a>. I don't actively keep track of issues or PRs raised there; if you want to get in touch with feature requests or comments on the code, my contact info is <a href="feedback/index.html">here</a>!</p>
<p><i>Resource & Author Credits</i></p>
<ul>
<li>Florrie: that's me! I programmed most of the site, and put the whole thing together. <a href="feedback/index.html">Say hi</a>!</li>
<li><a href="https://homestuck.bandcamp.com/">Homestuck's Bandcamp</a>, the official host of Homestuck's music: I got almost all the official album listings and basic track info from here.</li>
<li>GiovanH's <a href="https://my.pcloud.com/publink/show?code=kZdJQ8kZNyIwh0Hn1ime6Ty7L2J87BE3E2ak">complete track art archive</a>: track art! A million thanks for putting this together and sharing this with me. (Prior to this, I used the <a href="https://web.archive.org/web/20190720035022/https://homestuck.bandcamp.com/music">Web Archive</a> to gather track art.)</li>
<li><a href="https://homestuck.net/music/references.html">NSND</a>: leitmotifs! Thanks to this site in combination with credits on the bandcamp and artists' own commentary, this wiki is a rather comprehensive resource for leitmotifs and other track references.</li>
<li><a href="https://www.bgreco.net/hsflash.html">bgreco.net (HQ Audio Flashes)</a>: thumbnail captures for the individual Flash animations! There were a couple captures missing that I took myself, but most Flash thumbnails are from here.</a></li>
<li>The <a href="https://homestuck-and-mspa-music.fandom.com/wiki/Homestuck_and_MSPA_Music_Wiki">Homestuck and MSPA Music Wiki</a> on Fandom: the inspiration for this wiki! I've wanted to make a more complete and explorable wiki ever since seeing it. The Fandom wiki has also been a very handy reference in putting this together, so much thanks to everyone who's worked on it!</li>
<li><a href="https://carrd.co/">carrd.co</a>: I stole your icons.svg file. It is mine now. :tobyfox_dog_sunglasses:</li>
<li>All organizers and contributors of the <a href="https://sollay-b.tumblr.com/post/188094230423/hello-a-couple-of-years-ago-allyssinian">Homestuck Vol. 5 Anthology</a> - community-made track art for [[album:Homestuck Vol. 5]]! All of this art is <i>excellent</i>. Each track credits its respective cover artist.</li>
<li>Likewise for the <a href="https://hsfanmusic.skaia.net/post/619761136023257089/unofficialmspafans-we-are-proud-to-announce-the">Beyond Canon Track Art Anthology</a> as well as <a href="https://alterniaart.tumblr.com/">Alternia/Bound</a>!</li>
<li>All comments on the site: I appreciate all feedback a lot! People have shared a ton of ideas and suggestions with me, and I <i>cannot</i> emphasize enough how motivating it is to share a project with like-minded folx interested in making it better with you.</li>
</ul>
<p><i>Feature Acknowledgements</i></p>
<ul>
<li><b>Thank you,</b> GiovanH, for linking me to a resource for higher quality cover art, and bringing to my attention the fact that clicking a cover art on Bandcamp to zoom in will often reveal a higher quality image.</li>
<li>cosmogonicalAuthor, for a variety of feature requests and comments! In particular: improving way the track list on author pages is sorted; expanding the introduction; expanding the introduction message to the website; and linking bonus art for Homestuck Vol. 5 - plus a few other good suggestions I haven't gotten to yet. Thanks!</li>
<li>Monckat, for suggesting the album Strife 2 before I'd begun adding fandom-created albums and unofficial releases to this wiki, and for working with an emailer to reupload the original cover art for [[track:the-thirteenth-hour]].</li>
<li>Kidpen, for suggesting the "Flashes that feature this track" feature.</li>
<li>an emailer, for suggesting the "Random track" feature.</li>
<li>foreverFlumoxed, for pointing out that [[flash:338]] contains reference to [[JOHN DO THE WINDY THING]] (this reminded me to add all the unreleased Flash tracks to the Unreleased Tracks album!), for recommending the restructure to [[album:Unreleased Tracks]], and for going to the massive effort of checking every track page and pointing out a bunch of missing cover arts and title typos!</li>
<li>Makin, for various initial help in data collection (especially commentary) and lifting the site off the ground by pinning it to the top of the /r/homestuck subreddit for a while, and for linking me the independent release of <a href="https://jamesdever.bandcamp.com/album/sburb">Sburb</a>.</li>
<li>an emailer, for sending a crop of the YT thumbnail art for [[After the Sun]] (plus the SoundCloud link for that track), for reporting the "Random" buttons being broken, and for linking a bunch of resources and various official uploads of tracks and albums.</li>
<li>Thanks for pointing out typos, errors in reference lists, and out of date details: cookiefonster, foreverFlummoxed, and an emailer.</li>
</ul>
`;
const SITE_CHANGELOG = fs.readFileSync('changelog.html').toString().trim(); // fight me bro
const SITE_FEEDBACK = fixWS`
<p><strong>Feature requests? Noticed any errors?</strong> Please let me know! I appreciate feedback a lot, and always want to make this site better.</p>
<p>The best place to talk about this site is on its <a href="https://forum.homestuck.xyz/viewtopic.php?f=7&t=151">HomestuckXYZ forum thread</a>.</p>
<p>Or, if forums aren't really the thing for you, I've got an email too: towerofnix at gmail dot beans. (You know the domain.)</p>
<p>I used to have a Twitter account, but Twitter is bad and poofing from it was probably my greatest decision.</p>
<p>Thank you for sharing your feedback!</p>
`;
const SITE_JS_DISABLED = fixWS`
<p>Sorry, that link won't work unless you're running a web browser that supports relatively modern JavaScript.</p>
<p>Please press the back button to get where you were, or <a href="index.html">head back to the index</a>.</p>
`;
// Might ena8le this later... we'll see! Eventually. May8e.
const ENABLE_ARTIST_AVATARS = false;
const ARTIST_AVATAR_DIRECTORY = 'artist-avatar';
const ALBUM_DATA_FILE = 'album.txt'; // /album/*/$.txt
const ARTIST_DATA_FILE = 'artists.txt'; // /$.txt
const FLASH_DATA_FILE = 'flashes.txt'; // /$.txt
const CSS_FILE = 'site.css';
// Shared varia8les! These are more efficient to access than a shared varia8le
// (or at least I h8pe so), and are easier to pass across functions than a
// 8unch of specific arguments.
//
// Upd8: Okay yeah these aren't actually any different. Still cleaner than
// passing around a data object containing all this, though.
let albumData;
let allTracks;
let flashData;
let artistNames;
let artistData;
let officialAlbumData;
let fandomAlbumData;
let justEverythingMan; // tracks, albums, flashes -- don't forget to upd8 getHrefOfAnythingMan!
let justEverythingSortedByArtDateMan;
// Note there isn't a 'find track data files' function. I plan on including the
// data for all tracks within an al8um collected in the single metadata file
// for that al8um. Otherwise there'll just 8e way too many files, and I'd also
// have to worry a8out linking track files to al8um files (which would contain
// only the track listing, not track data itself), and dealing with errors of
// missing track files (or track files which are not linked to al8ums). All a
// 8unch of stuff that's a pain to deal with for no apparent 8enefit.
async function findAlbumDataFiles() {
// Promises suck. This could pro8a8ly 8e written with async/await and an
// ordinary for loop, 8ut I'm using promises 8ecause they let all the
// folders get read simultaneously.
// ...Actually screw it, let's use async/await AND promises.
/*
return readdir(C.ALBUM_DIRECTORY)
.then(albums => Promise.all(albums
.map(album => readdir(path.join(C.ALBUM_DIRECTORY, album))
.then(files => files.includes(ALBUM_DATA_FILE) ? path.join(C.ALBUM_DIRECTORY, album, ALBUM_DATA_FILE) : null))))
.then(paths => paths.filter(Boolean));
*/
const albums = await readdir(C.ALBUM_DIRECTORY);
const paths = await progressPromiseAll(`Searching for album files.`, albums.map(async album => {
// Argua8ly terri8le/am8iguous varia8le naming. Too 8ad!
const albumDirectory = path.join(C.ALBUM_DIRECTORY, album);
const files = await readdir(albumDirectory);
if (files.includes(ALBUM_DATA_FILE)) {
return path.join(albumDirectory, ALBUM_DATA_FILE);
}
// The old code returns null if the data file isn't present, 8ut that's
// not actually necessary. We just need some falsey value, and the
// implied undefined when you don't explicitly return anything works.
}));
return paths.filter(Boolean);
}
function* getSections(lines) {
// ::::)
const isSeparatorLine = line => /^-{8,}$/.test(line);
yield* splitArray(lines, isSeparatorLine);
}
function getBasicField(lines, name) {
const line = lines.find(line => line.startsWith(name + ':'));
return line && line.slice(name.length + 1).trim();
};
function getListField(lines, name) {
let startIndex = lines.findIndex(line => line.startsWith(name + ':'));
// If callers want to default to an empty array, they should stick
// "|| []" after the call.
if (startIndex === -1) {
return null;
}
// We increment startIndex 8ecause we don't want to include the
// "heading" line (e.g. "URLs:") in the actual data.
startIndex++;
let endIndex = lines.findIndex((line, index) => index >= startIndex && !line.startsWith('- '));
if (endIndex === -1) {
endIndex = lines.length;
}
if (endIndex === startIndex) {
// If there is no list that comes after the heading line, treat the
// heading line itself as the comma-separ8ted array value, using
// the 8asic field function to do that. (It's l8 and my 8rain is
// sleepy. Please excuse any unhelpful comments I may write, or may
// have already written, in this st8. Thanks!)
const value = getBasicField(lines, name);
return value && value.split(',').map(val => val.trim());
}
const listLines = lines.slice(startIndex, endIndex);
return listLines.map(line => line.slice(2));
};
function getContributionField(section, name) {
let contributors = getListField(section, name);
if (!contributors) {
return null;
}
if (contributors.length === 1 && contributors[0].startsWith('<i>')) {
const arr = [];
arr.textContent = contributors[0];
return arr;
}
contributors = contributors.map(contrib => {
// 8asically, the format is "Who (What)", or just "Who". 8e sure to
// keep in mind that "what" doesn't necessarily have a value!
const match = contrib.match(/^(.*?)( \((.*)\))?$/);
if (!match) {
return contrib;
}
const who = match[1];
const what = match[3] || null;
return {who, what};
});
const badContributor = contributors.find(val => typeof val === 'string');
if (badContributor) {
return {error: `An entry has an incorrectly formatted contributor, "${badContributor}".`};
}
if (contributors.length === 1 && contributors[0].who === 'none') {
return null;
}
return contributors;
};
function getMultilineField(lines, name) {
// All this code is 8asically the same as the getListText - just with a
// different line prefix (four spaces instead of a dash and a space).
let startIndex = lines.findIndex(line => line.startsWith(name + ':'));
if (startIndex === -1) {
return null;
}
startIndex++;
let endIndex = lines.findIndex((line, index) => index >= startIndex && !line.startsWith(' '));
if (endIndex === -1) {
endIndex = lines.length;
}
// If there aren't any content lines, don't return anything!
if (endIndex === startIndex) {
return null;
}
// We also join the lines instead of returning an array.
const listLines = lines.slice(startIndex, endIndex);
return listLines.map(line => line.slice(4)).join('\n');
};
function transformInline(text) {
return text.replace(/\[\[(album:|artist:|flash:|track:)?(.+?)\]\]/g, (match, category, ref, offset) => {
if (category === 'album:') {
const album = getLinkedAlbum(ref);
if (album) {
return fixWS`
<a href="${C.ALBUM_DIRECTORY}/${album.directory}/index.html" style="${getThemeString(album)}">${album.name}</a>
`;
} else {
console.warn(`\x1b[33mThe linked album ${match} does not exist!\x1b[0m`);
return ref;
}
} else if (category === 'artist:') {
const artist = getLinkedArtist(ref);
if (artist) {
return `<a href="${C.ARTIST_DIRECTORY}/${C.getArtistDirectory(artist.name)}/index.html">${artist.name}</a>`;
} else {
console.warn(`\x1b[33mThe linked artist ${artist} does not exist!\x1b[0m`);
return ref;
}
} else if (category === 'flash:') {
const flash = getLinkedFlash(ref);
if (flash) {
let name = flash.name;
const nextCharacter = text[offset + 1];
const lastCharacter = name[name.length - 1];
if (
![' ', '\n'].includes(nextCharacter) &&
lastCharacter === '.'
) {
name = name.slice(0, -1);
}
return getFlashLinkHTML(flash, name);
} else {
console.warn(`\x1b[33mThe linked flash ${match} does not exist!\x1b[0m`);
return ref;
}
} else if (category === 'track:') {
const track = getLinkedTrack(ref);
if (track) {
return fixWS`
<a href="${C.TRACK_DIRECTORY}/${track.directory}/index.html" style="${getThemeString(track)}">${track.name}</a>
`;
} else {
console.warn(`\x1b[33mThe linked track ${match} does not exist!\x1b[0m`);
return ref;
}
} else {
const track = getLinkedTrack(ref);
if (track) {
let name = ref.match(/(.*):/);
if (name) {
name = name[1];
} else {
name = track.name;
}
return fixWS`
<a href="${C.TRACK_DIRECTORY}/${track.directory}/index.html" style="${getThemeString(track)}">${name}</a>
`;
} else {
console.warn(`\x1b[33mThe linked track ${match} does not exist!\x1b[0m`);
return ref;
}
}
});
}
function transformMultiline(text, treatAsDocument=false) {
// Heck yes, HTML magics.
text = transformInline(text);
if (treatAsDocument) {
return text;
}
const outLines = [];
let inList = false;
for (let line of text.split(/\r|\n|\r\n/)) {
line = line.replace(/<img src="(.*?)">/g, '<a href="$1">$&</a>');
if (line.startsWith('- ')) {
if (!inList) {
outLines.push('<ul>');
inList = true;
}
outLines.push(` <li>${line.slice(1).trim()}</li>`);
} else {
if (inList) {
outLines.push('</ul>');
inList = false;
}
outLines.push(`<p>${line}</p>`);
}
}
return outLines.join('\n');
};
function getCommentaryField(lines) {
const text = getMultilineField(lines, 'Commentary');
if (text) {
const lines = text.split('\n');
if (!lines[0].replace(/<\/b>/g, '').includes(':</i>')) {
return {error: `An entry is missing commentary citation: "${lines[0].slice(0, 40)}..."`};
}
return text;
} else {
return null;
}
};
async function processAlbumDataFile(file) {
let contents;
try {
contents = await readFile(file, 'utf-8');
} catch (error) {
// This function can return "error o8jects," which are really just
// ordinary o8jects with an error message attached. I'm not 8othering
// with error codes here or anywhere in this function; while this would
// normally 8e 8ad coding practice, it doesn't really matter here,
// 8ecause this isn't an API getting consumed 8y other services (e.g.
// translaction functions). If we return an error, the caller will just
// print the attached message in the output summary.
return {error: `Could not read ${file} (${error.code}).`};
}
// We're pro8a8ly supposed to, like, search for a header somewhere in the
// al8um contents, to make sure it's trying to 8e the intended structure
// and is a valid utf-8 (or at least ASCII) file. 8ut like, whatever.
// We'll just return more specific errors if it's missing necessary data
// fields.
const contentLines = contents.split('\n');
// In this line of code I defeat the purpose of using a generator in the
// first place. Sorry!!!!!!!!
const sections = Array.from(getSections(contentLines));
const albumSection = sections[0];
const album = {};
album.name = getBasicField(albumSection, 'Album');
album.artists = getContributionField(albumSection, 'Artists') || getContributionField(albumSection, 'Artist');
album.date = getBasicField(albumSection, 'Date');
album.artDate = getBasicField(albumSection, 'Art Date') || album.date;
album.coverArtDate = getBasicField(albumSection, 'Cover Art Date') || album.artDate;
album.coverArtists = getContributionField(albumSection, 'Cover Art');
album.hasTrackArt = (getBasicField(albumSection, 'Has Track Art') !== 'no');
album.trackCoverArtists = getContributionField(albumSection, 'Track Art');
album.commentary = getCommentaryField(albumSection);
album.urls = (getListField(albumSection, 'URLs') || []).filter(Boolean);
album.directory = getBasicField(albumSection, 'Directory');
const canon = getBasicField(albumSection, 'Canon');
album.isCanon = canon === 'Canon' || !canon;
album.isBeyond = canon === 'Beyond';
album.isOfficial = album.isCanon || album.isBeyond;
album.isFanon = canon === 'Fanon';
if (album.artists && album.artists.error) {
return {error: `${album.artists.error} (in ${album.name})`};
}
if (album.coverArtists && album.coverArtists.error) {
return {error: `${album.coverArtists.error} (in ${album.name})`};
}
if (album.commentary && album.commentary.error) {
return {error: `${album.commentary.error} (in ${album.name})`};
}
if (album.trackCoverArtists && album.trackCoverArtists.error) {
return {error: `${album.trackCoverArtists.error} (in ${album.name})`};
}
if (!album.coverArtists) {
return {error: `The album "${album.name}" is missing the "Cover Art" field.`};
}
album.color = getBasicField(albumSection, 'FG') || '#0088ff';
if (!album.name) {
return {error: 'Expected "Album" (name) field!'};
}
if (!album.date) {
return {error: 'Expected "Date" field!'};
}
if (isNaN(Date.parse(album.date))) {
return {error: `Invalid Date field: "${album.date}"`};
}
album.date = new Date(album.date);
album.artDate = new Date(album.artDate);
album.coverArtDate = new Date(album.coverArtDate);
if (isNaN(Date.parse(album.artDate))) {
return {error: `Invalid Art Date field: "${album.date}"`};
}
if (isNaN(Date.parse(album.coverArtDate))) {
return {error: `Invalid Cover Art Date field: "${album.date}"`};
}
if (!album.directory) {
album.directory = C.getKebabCase(album.name);
}
album.tracks = [];
// will be overwritten if a group section is found!
album.usesGroups = false;
let group = '';
let groupColor = album.color;
for (const section of sections.slice(1)) {
// Just skip empty sections. Sometimes I paste a 8unch of dividers,
// and this lets the empty sections doing that creates (temporarily)
// exist without raising an error.
if (!section.filter(Boolean).length) {
continue;
}
const groupName = getBasicField(section, 'Group');
if (groupName) {
group = groupName;
groupColor = getBasicField(section, 'FG');
album.usesGroups = true;
continue;
}
const track = {};
track.name = getBasicField(section, 'Track');
track.commentary = getCommentaryField(section);
track.lyrics = getMultilineField(section, 'Lyrics');
track.originalDate = getBasicField(section, 'Original Date');
track.artDate = getBasicField(section, 'Art Date') || track.originalDate || album.artDate;
track.references = getListField(section, 'References') || [];
track.artists = getContributionField(section, 'Artists') || getContributionField(section, 'Artist');
track.coverArtists = getContributionField(section, 'Track Art');
track.contributors = getContributionField(section, 'Contributors') || [];
track.directory = getBasicField(section, 'Directory');
if (!track.name) {
return {error: 'A track section is missing the "Track" (name) field (in ${album.name)}.'};
}
let durationString = getBasicField(section, 'Duration') || '0:00';
track.duration = getDurationInSeconds(durationString);
if (track.contributors.error) {
return {error: `${track.contributors.error} (in ${track.name}, ${album.name})`};
}
if (track.commentary && track.commentary.error) {
return {error: `${track.commentary.error} (in ${track.name}, ${album.name})`};
}
if (!track.artists) {
// If an al8um has an artist specified (usually 8ecause it's a solo
// al8um), let tracks inherit that artist. We won't display the
// "8y <artist>" string on the al8um listing.
if (album.artists) {
track.artists = album.artists;
} else {
return {error: `The track "${track.name}" is missing the "Artist" field (in ${album.name}).`};
}
}
if (!track.coverArtists) {
if (getBasicField(section, 'Track Art') !== 'none' && album.hasTrackArt) {
if (album.trackCoverArtists) {
track.coverArtists = album.trackCoverArtists;
} else {
return {error: `The track "${track.name}" is missing the "Track Art" field (in ${album.name}).`};
}
}
}
if (track.coverArtists && track.coverArtists.length && track.coverArtists[0] === 'none') {
track.coverArtists = null;
}
if (!track.directory) {
track.directory = C.getKebabCase(track.name);
}
if (track.originalDate) {
if (isNaN(Date.parse(track.originalDate))) {
return {error: `The track "${track.name}"'s has an invalid "Original Date" field: "${track.originalDate}"`};
}
track.date = new Date(track.originalDate);
} else {
track.date = album.date;
}
track.artDate = new Date(track.artDate);
const hasURLs = getBasicField(section, 'Has URLs') !== 'no';
track.urls = hasURLs && (getListField(section, 'URLs') || []).filter(Boolean);
if (hasURLs && !track.urls.length) {
return {error: `The track "${track.name}" should have at least one URL specified.`};
}
// 8ack-reference the al8um o8ject! This is very useful for when
// we're outputting the track pages.
track.album = album;
track.group = group;
if (group) {
track.color = groupColor;
} else {
track.color = album.color;
}
/*
album.tracks.push({
name: trackName,
artists: trackArtists,
coverArtists: trackCoverArtists,
contributors: trackContributors,
duration: trackDuration,
commentary: trackCommentary,
lyrics: trackLyrics,
references,
date,
artDate: artDateValue,
directory: trackDirectory,
urls: trackURLs,
isCanon: album.isCanon,
isBeyond: album.isBeyond,
isOfficial: album.isOfficial,
isFanon: album.isFanon,
group,
theme: group ? groupTheme : albumTheme,
album
});
*/
album.tracks.push(track);
}
return album;
}
async function processArtistDataFile(file) {
let contents;
try {
contents = await readFile(file, 'utf-8');
} catch (error) {
return {error: `Could not read ${file} (${error.code}).`};
}
const contentLines = contents.split('\n');
const sections = Array.from(getSections(contentLines));
return sections.map(section => {
const name = getBasicField(section, 'Artist');
const urls = (getListField(section, 'URLs') || []).filter(Boolean);
const alias = getBasicField(section, 'Alias');
if (!name) {
return {error: 'Expected "Artist" (name) field!'};
}
return {name, urls, alias};
});
}
async function processFlashDataFile(file) {
let contents;
try {
contents = await readFile(file, 'utf-8');
} catch (error) {
return {error: `Could not read ${file} (${error.code}).`};
}
const contentLines = contents.split('\n');
const sections = Array.from(getSections(contentLines));
let act, color;
return sections.map(section => {
if (getBasicField(section, 'ACT')) {
act = getBasicField(section, 'ACT');
color = getBasicField(section, 'FG');
return {act8r8k: true, act, color};
}
const name = getBasicField(section, 'Flash');
let page = getBasicField(section, 'Page');
let directory = getBasicField(section, 'Directory');
let date = getBasicField(section, 'Date');
const jiff = getBasicField(section, 'Jiff');
const tracks = getListField(section, 'Tracks') || [];
const contributors = getContributionField(section, 'Contributors') || [];
const urls = (getListField(section, 'URLs') || []).filter(Boolean);
if (!name) {
return {error: 'Expected "Flash" (name) field!'};
}
if (!page && !directory) {
return {error: 'Expected "Page" or "Directory" field!'};
}
if (!directory) {
directory = page;
}
if (!date) {
return {error: 'Expected "Date" field!'};
}
if (isNaN(Date.parse(date))) {
return {error: `Invalid Date field: "${date}"`};
}
date = new Date(date);
return {name, page, directory, date, contributors, tracks, urls, act, color, jiff};
});
}
function getDateString({ date }) {
/*
const pad = val => val.toString().padStart(2, '0');
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
*/
const months = [
'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'
]
return `${date.getDate()} ${months[date.getMonth()]} ${date.getFullYear()}`
}
function getDurationString(secTotal) {
if (secTotal === 0) {
return '_:__'
}
let hour = Math.floor(secTotal / 3600)
let min = Math.floor((secTotal - hour * 3600) / 60)
let sec = Math.floor(secTotal - hour * 3600 - min * 60)
const pad = val => val.toString().padStart(2, '0')
if (hour > 0) {
return `${hour}:${pad(min)}:${pad(sec)}`
} else {
return `${min}:${pad(sec)}`
}
}
function getDurationInSeconds(string) {
const parts = string.split(':').map(n => parseInt(n))
if (parts.length === 3) {
return parts[0] * 3600 + parts[1] * 60 + parts[2]
} else if (parts.length === 2) {
return parts[0] * 60 + parts[1]
} else {
return 0
}
}
function getTotalDuration(tracks) {
return tracks.reduce((duration, track) => duration + track.duration, 0);
}
function stringifyAlbumData() {
return JSON.stringify(albumData, (key, value) => {
if (['album', 'commentary'].includes(key)) {
return undefined;
}
return value;
}, 1);
}
function stringifyFlashData() {
return JSON.stringify(flashData, (key, value) => {
if (['act', 'commentary'].includes(key)) {
return undefined;
}
return value;
}, 1);
}
function stringifyArtistData() {
return JSON.stringify(artistData, null, 1);
}
// 8asic function for writing any site page. Handles all the 8asename,
// directory, and site-template shenanigans!
async function writePage(directoryParts, titleOrHead, body) {
const directory = path.join(C.SITE_DIRECTORY, ...directoryParts);
const file = path.join(directory, 'index.html');
let targetPath = directoryParts.join('/');
if (directoryParts.length) {
targetPath += '/';
}
const target = `https://hsmusic.wiki/${targetPath}`;
await mkdirp(directory);
await writeFile(file, fixWS`
<!DOCTYPE html>
<html>
<head>
<title>Moved to hsmusic.wiki</title>
<meta charset="utf-8">
<meta http-equiv="refresh" content="0;url=${target}">
<link rel="canonical" href="${target}">
<link rel="stylesheet" href="static/site-basic.css">
</head>
<body>
<main>
<h1>Moved to hsmusic.wiki</h1>
<p>This page has been moved to <a href="${target}">${target}</a>.</p>
</main>
</body>
</html>
`);
}
function writeMiscellaneousPages() {
return progressPromiseAll('Writing miscellaneous pages.', [
writePage([], fixWS`
<title>${SITE_TITLE}</title>
<meta name="description" content="Expansive resource for anyone interested in fan- and official music alike; an archive for all things related.">
`, fixWS`
<body id="top-index">
<div id="content">
<h1>${SITE_TITLE}</h1>
<div id="intro-menu">
<p>Explore the site!</p>
<a href="${C.LISTING_DIRECTORY}/index.html">Listings</a>
<a href="${C.FLASH_DIRECTORY}/index.html">Flashes & Games</a>
<a href="${C.ABOUT_DIRECTORY}/index.html">About & Credits</a>
<a href="${C.FEEDBACK_DIRECTORY}/index.html">Feedback & Suggestions</a>
<a href="${C.CHANGELOG_DIRECTORY}/index.html">Changelog</a>
<p>...or choose an album:</p>
</div>
<h2>Beyond Canon</h2>
<h3>The future of Homestuck music, today.<br>Albums by the Homestuck^2 Music Team. 2020+.</h2>
<div class="grid-listing">
${albumData.filter(album => album.isBeyond).reverse().map(album => fixWS`
<a class="grid-item" href="${C.ALBUM_DIRECTORY}/${album.directory}/index.html" style="${getThemeString(album)}">
<img src="${getAlbumCover(album)}" alt="cover art">
<span>${album.name}</span>
</a>
`).join('\n')}
</div>
<h2>Fandom</h2>
<h3>A look into Homestuck's world of music and art created—and organized—by fans.<br>The beginning of time, through the end.</h3>
<div class="grid-listing">
${albumData.filter(album => album.isFanon).reverse().map(album => fixWS`
<a class="grid-item" href="${C.ALBUM_DIRECTORY}/${album.directory}/index.html" style="${getThemeString(album)}">
<img src="${getAlbumCover(album)}" alt="cover art">
<span>${album.name}</span>
</a>
`).join('\n')}
<a class="grid-item" href="${C.FEEDBACK_DIRECTORY}/index.html" style="--fg-color: #ffffff">...and more to be added at your request</a>
</div>
<h2>Official</h2>
<h3>The original discography: a replica of the Homestuck Bandcamp prior to the enmergening.<br>Albums organized by What Pumpkin. 2009–2019.</h3>
<div class="grid-listing">
${albumData.filter(album => album.isCanon).reverse().map(album => fixWS`
<a class="grid-item" href="${C.ALBUM_DIRECTORY}/${album.directory}/index.html" style="${getThemeString(album)}">
<img src="${getAlbumCover(album)}" alt="cover art">
<span>${album.name}</span>
</a>
`).join('\n')}
</div>
</div>
</body>
`),
writePage([C.FLASH_DIRECTORY], `Flashes & Games`, fixWS`
<body id="top-index">
<div id="content">
<h1>Flashes & Games</h1>
<div id="intro-menu">
<a href="index.html">Home</a>
<a href="${C.LISTING_DIRECTORY}/index.html">Listings</a>
<a href="${C.ABOUT_DIRECTORY}/index.html">About & Credits</a>
<a href="${C.FEEDBACK_DIRECTORY}/index.html">Feedback & Suggestions</a>
<a href="${C.CHANGELOG_DIRECTORY}/index.html">Changelog</a>
</div>
<div class="long-content">
<p>Also check out:</p>
<ul>
<li>Bambosh's <a href="https://www.youtube.com/watch?v=AEIOQN3YmNc">[S]Homestuck - All flashes</a>: an excellently polished compilation of all Flash animations in Homestuck.</li>
<li>bgreco.net's <a href="https://www.bgreco.net/hsflash.html">Homestuck HQ Audio Flashes</a>: an index of all HS Flash animations with Bandcamp-quality audio built in. (Also the source for many thumbnails below!)</li>
</ul>
</div>
<div class="grid-listing">
${flashData.map(flash => flash.act8r8k ? fixWS`
<h2 style="${getThemeString(flash)}"><a href="${C.FLASH_DIRECTORY}/${getFlashDirectory(flashData.find(f => !f.act8r8k && f.act === flash.act))}/index.html">${flash.act}</a></h2>
` : fixWS`
<a class="grid-item" href="${C.FLASH_DIRECTORY}/${getFlashDirectory(flash)}/index.html" style="${getThemeString(flash)}">
<img src="${getFlashCover(flash)}" alt="cover art">
<span>${flash.name}</span>
</a>
`).join('\n')}
</div>
</div>
</body>
`),
writePage([C.ABOUT_DIRECTORY], 'About & Credits', fixWS`
<body>
<div id="content">
<div class="long-content">
<h1>${SITE_TITLE}</h1>
<p><a href="index.html">(Home)</a></p>
${transformMultiline(SITE_ABOUT, true)}
</div>
</div>
</body>
`),
writePage([C.CHANGELOG_DIRECTORY], `Changelog`, fixWS`
<body>
<div id="content">
<div class="long-content">
<h1>Changelog</h1>
<p><a href="index.html">(Home)</a></p>
${transformMultiline(SITE_CHANGELOG, true)}
</div>
</div>
</body>
`),
writePage([C.FEEDBACK_DIRECTORY], 'Feedback & Suggestions!', fixWS`
<body>
<div id="content">
<div class="long-content">
<h1>Feedback & Suggestions!</h1>
<p><a href="index.html">(Home)</a></p>
${SITE_FEEDBACK}
</div>
</div>
</body>
`),
writePage([C.JS_DISABLED_DIRECTORY], 'JavaScript Disabled', fixWS`
<body>
<div id="content">
<h1>JavaScript Disabled (or out of date)</h1>
${SITE_JS_DISABLED}
</div>
</body>
`),
writeFile('data.js', fixWS`
// Yo, this file is gener8ted. Don't mess around with it!
window.albumData = ${stringifyAlbumData()};
window.flashData = ${stringifyFlashData()};
window.artistData = ${stringifyArtistData()};
`)
]);
}
// This function title is my gr8test work of art.
// (The 8ehavior... well, um. Don't tell anyone, 8ut it's even 8etter.)
function writeIndexAndTrackPagesForAlbum(album) {
return [
() => writeAlbumPage(album),
...album.tracks.map(track => () => writeTrackPage(track))
];
}
async function writeAlbumPage(album) {
const trackToListItem = track => fixWS`
<li style="${getThemeString(track)}">
(${getDurationString(track.duration)})
<a href="${C.TRACK_DIRECTORY}/${track.directory}/index.html">${track.name}</a>
${track.artists !== album.artists && fixWS`
<span class="by">by ${getArtistString(track.artists)}</span>