common.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. // Okay, THIS stupid file is loaded 8y 8OTH the client and the static site
  2. // 8uilder.
  3. const C = {
  4. // This can 8e changed if you want to output to some other directory. It's
  5. // the one you'll upload online with rsync or whatever when you're pushing
  6. // an upd8, and also the one you'd compress if you wanted to make a 8ackup
  7. // of the whole dang site. Just keep in mind that the gener8ted result will
  8. // contain a couple symlinked directories, so if you're uploading, you're
  9. // pro8a8ly gonna want to resolve those yourself.
  10. SITE_DIRECTORY: 'site',
  11. // Data files for the site, including flash, artist, and al8um data.
  12. // There are also some HTML files here, which are read and em8edded as
  13. // content in a few gener8ted pages (e.g. the changelog).
  14. DATA_DIRECTORY: 'data',
  15. // Su8directory under data for al8um files.
  16. DATA_ALBUM_DIRECTORY: 'album',
  17. // Code that's common 8etween the 8uild code (i.e. upd8.js) and gener8ted
  18. // site code should 8e put here. Which, uh, only really means this one
  19. // file. 8ut rather than hard code it, anything in this directory can 8e
  20. // shared across 8oth ends of the code8ase.
  21. // (This gets symlinked into SITE_DIRECTORY.)
  22. COMMON_DIRECTORY: 'common',
  23. // Code that's used only in the static site! CSS, cilent JS, etc.
  24. // (This gets symlinked into SITE_DIRECTORY.)
  25. STATIC_DIRECTORY: 'static',
  26. // Static media will 8e referenced in the site here!
  27. // The contents are categorized 8y the constants 8elow.
  28. // (This gets symlinked into SITE_DIRECTORY.)
  29. MEDIA_DIRECTORY: 'media',
  30. // Contains a folder for each al8um, within which is the al8um cover art
  31. // as well as any track art. Structure itself looks somethin' like this:
  32. // * album-art/<album.directory>/cover.jpg
  33. // * album-art/<album.directory>/<track1.directory>.jpg
  34. // * album-art/<album.directory>/<track2.directory>.jpg
  35. MEDIA_ALBUM_ART_DIRECTORY: 'album-art',
  36. // Just one folder, with a single image for each flash, matching its output
  37. // directory like al8um and track art. (Just keep in mind the directory of
  38. // a flash is just its page num8er most of the time.)
  39. MEDIA_FLASH_ART_DIRECTORY: 'flash-art',
  40. // Miscellaneous stuff! This is pretty much only referenced in commentary
  41. // fields.
  42. MEDIA_MISC_DIRECOTRY: 'misc',
  43. // The folder you stick your random downloads in is called "Downloads",
  44. // yeah? (Unless you sort all your downloads into manual, organized
  45. // locations. Good for you.) It might just 8e me, 8ut I've always said "the
  46. // downloads folder." And yet here I say "the al8um directory!" It's like
  47. // we've gotten "Downloads" as a name so ingrained into our heads that we
  48. // use it like an adjective too, even though it doesn't make any
  49. // grammatical sense to do so. Anyway, also for contrast, note that this
  50. // folder is called "album" and not "albums". To 8e clear, that IS against
  51. // how I normally name folders - 8ut here, I'm doing it to match 8andcamp's
  52. // URL schema: "/album/genesis-frog" instead of "/albums/genesis-frog."
  53. // That seems to kind of 8e a standard for a lot of sites? 8ut only KIND OF.
  54. // Twitter has the weird schema of "/<user>/status/<id>" (not "statuses")...
  55. // 8ut it also has "/<user>/likes", so I really have no idea how people
  56. // decide to make their URL schemas consistent. Luckily I don't have to
  57. // worry a8out any of that, 8ecause I'm just stealing 8andcamp.
  58. //
  59. // Upd8 03/11/2020: Oh my god this was a pain to re-align (copying from
  60. // udp8.js over to shared.js).
  61. ALBUM_DIRECTORY: 'album',
  62. TRACK_DIRECTORY: 'track',
  63. ARTIST_DIRECTORY: 'artist',
  64. ARTIST_AVATAR_DIRECTORY: 'artist-avatar',
  65. TAG_DIRECTORY: 'tag',
  66. LISTING_DIRECTORY: 'list',
  67. ABOUT_DIRECTORY: 'about',
  68. FEEDBACK_DIRECTORY: 'feedback',
  69. CHANGELOG_DIRECTORY: 'changelog',
  70. DISCORD_DIRECTORY: 'discord',
  71. DONATE_DIRECTORY: 'donate',
  72. FLASH_DIRECTORY: 'flash',
  73. NEWS_DIRECTORY: 'news',
  74. GROUP_DIRECTORY: 'group',
  75. JS_DISABLED_DIRECTORY: 'js-disabled',
  76. UNRELEASED_TRACKS_DIRECTORY: 'unreleased-tracks',
  77. OFFICIAL_GROUP_DIRECTORY: 'official',
  78. FANDOM_GROUP_DIRECTORY: 'fandom',
  79. // This function was originally made to sort just al8um data, 8ut its exact
  80. // code works fine for sorting tracks too, so I made the varia8les and names
  81. // more general.
  82. sortByDate: data => {
  83. // Just to 8e clear: sort is a mutating function! I only return the array
  84. // 8ecause then you don't have to define it as a separate varia8le 8efore
  85. // passing it into this function.
  86. return data.sort((a, b) => a.date - b.date);
  87. },
  88. // Same details as the sortByDate, 8ut for covers~
  89. sortByArtDate: data => {
  90. return data.sort((a, b) => (a.coverArtDate || a.date) - (b.coverArtDate || b.date));
  91. },
  92. // This gets all the track o8jects defined in every al8um, and sorts them 8y
  93. // date released. Generally, albumData will pro8a8ly already 8e sorted 8efore
  94. // you pass it to this function, 8ut individual tracks can have their own
  95. // original release d8, distinct from the al8um's d8. I allowed that 8ecause
  96. // in Homestuck, the first four Vol.'s were com8ined into one al8um really
  97. // early in the history of the 8andcamp, and I still want to use that as the
  98. // al8um listing (not the original four al8um listings), 8ut if I only did
  99. // that, all the tracks would 8e sorted as though they were released at the
  100. // same time as the compilation al8um - i.e, after some other al8ums (including
  101. // Vol.'s 5 and 6!) were released. That would mess with chronological listings
  102. // including tracks from multiple al8ums, like artist pages. So, to fix that,
  103. // I gave tracks an Original Date field, defaulting to the release date of the
  104. // al8um if not specified. Pretty reasona8le, I think! Oh, and this feature can
  105. // 8e used for other projects too, like if you wanted to have an al8um listing
  106. // compiling a 8unch of songs with radically different & interspersed release
  107. // d8s, 8ut still keep the al8um listing in a specific order, since that isn't
  108. // sorted 8y date.
  109. getAllTracks: albumData => C.sortByDate(albumData.reduce((acc, album) => acc.concat(album.tracks), [])),
  110. getKebabCase: name => name.split(' ').join('-').replace(/&/g, 'and').replace(/[^a-zA-Z0-9\-]/g, '').replace(/-{2,}/g, '-').replace(/^-+|-+$/g, '').toLowerCase(),
  111. // Terri8le hack: since artists aren't really o8jects and don't have proper
  112. // "directories", we just reformat the artist's name.
  113. getArtistDirectory: artistName => C.getKebabCase(artistName),
  114. getArtistNumContributions: artist => (
  115. artist.tracks.asAny.length +
  116. artist.albums.asCoverArtist.length +
  117. artist.flashes.asContributor.length
  118. ),
  119. getArtistCommentary: (artist, {justEverythingMan}) => justEverythingMan.filter(thing => thing.commentary && thing.commentary.replace(/<\/?b>/g, '').includes('<i>' + artist.name + ':</i>'))
  120. };
  121. if (typeof module === 'object') {
  122. module.exports = C;
  123. } else if (typeof window === 'object') {
  124. window.C = C;
  125. }