diff --git a/.gitignore b/.gitignore index cd64728..59a0ed4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ .env node_modules static_assets -host_info.json +favourites_info.json *.js package-lock.json build \ No newline at end of file diff --git a/README.md b/README.md index 9a741d3..7132732 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,9 @@ Make sure to set a master password! See `.env.example`. Enter in the master pass # Tips ## Adding media -Add it to the relevant static directory (`/static_assets/anime_assets`, `/static_assets/manga_assets`, or `/static_assets/music_assets`), and create an entry for it in `host_info.json`. See `host_info.json.example` for an example. +Add it to the relevant static directory (`/static_assets/anime_assets`, `/static_assets/manga_assets`, or `/static_assets/music_assets`), and just rerun `npm run build`. + +To mark it as a favourite, create an entry for it in `favourites_info.json`. See `favourites_info.json.example` for an example. ## Hosting Multiple TOR Hidden Services If you are running multiple TOR hidden services, you will need to modify the [.torrc file](https://stackoverflow.com/questions/14321214/how-to-run-multiple-tor-processes-at-once-with-different-exit-ips#18895491). diff --git a/build.ts b/build.ts index 80f228f..aece329 100644 --- a/build.ts +++ b/build.ts @@ -2,17 +2,20 @@ import * as path from 'path'; import { readdirSync } from 'fs'; import { Renderer } from './ryuji.js'; import { Builder } from './saki.js'; -import _host_info from './host_info.json'; +import _favourites_info from './favourites_info.json'; //todo: music? -interface Listing { - name: string; - type: "anime" | "manga" | "music"; +interface FavouritesInfo { favourites: { listing: boolean; //whether to mark entire listing as favourite chapters: string[]; //favourite chapters - }; //marked as not optional here, but in the actual host_info.json file, it is optional + }; +} + +interface Listing extends FavouritesInfo { + name: string; + type: "anime" | "manga" | "music"; } interface DirectoryVars { @@ -37,20 +40,27 @@ interface MangaVars { prev_chapter?: string | boolean; } -const listings: Listing[] = _host_info.listings.map( - (listing: any) => - //add empty "favourites" if not present in the json - listing.favourites ? listing : { - ...listing, - favourites: { - listing: false, - chapters: [] - } - } -).filter( - (listing: any): listing is Listing => - typeof listing.name === "string" && (listing?.type === "anime" || listing?.type === "manga" || listing?.type === "music") -); +const favourites_info: Record = _favourites_info; + +let listings: Listing[] = []; + +//add listings from static_assets/anime_assets +for (let listing_type of ["anime", "manga", "music"]) { + listings.push(...readdirSync(path.join(__dirname, `/static_assets/${listing_type}_assets`)).map( + (listing_name: string) => + ({ + name: listing_name, + type: listing_type, + favourites: { + listing: favourites_info[listing_name] ? favourites_info[listing_name].favourites.listing : false, + chapters: favourites_info[listing_name] ? favourites_info[listing_name].favourites.chapters : [], + } + }) + ).filter( + (listing: any): listing is Listing => + typeof listing.name === "string" && (listing?.type === "anime" || listing?.type === "manga" || listing?.type === "music") + )); +} let renderer: Renderer = new Renderer("templates", "components"); let builder: Builder = new Builder("/build"); diff --git a/favourites_info.json.example b/favourites_info.json.example new file mode 100644 index 0000000..0b982aa --- /dev/null +++ b/favourites_info.json.example @@ -0,0 +1,31 @@ +{ + "senpai-wa-otokonoko": { + "favourites": { + "listing": true, + "chapters": [ + "c001", + "c099" + ] + } + } + "bocchi-the-boulder": { + "favourites": { + "listing": true, + "chapters": [] + } + }, + "not-buna": { + "favourites": { + "listing": false, + "chapters": [ + "aira" + ] + } + }, + "arizona-philips": { + "favourites": { + "listing": true, + "chapters": [] + } + } +} \ No newline at end of file diff --git a/host_info.json.example b/host_info.json.example deleted file mode 100644 index c8ebb26..0000000 --- a/host_info.json.example +++ /dev/null @@ -1,44 +0,0 @@ -{ - "listings": [ - { - "name": "senpai-wa-otokonoko", - "type": "manga", - "favourites": { - "listing": true, - "chapters": ["c001"] - } - }, - { - "name": "shiitake-simulation", - "type": "manga" - }, - { - "name": "bocchi-the-boulder", - "type": "anime", - "favourites": { - "listing": true, - "chapters": [] - } - }, - { - "name": "yoroshiku", - "type": "music" - }, - { - "name": "not-buna", - "type": "music", - "favourites": { - "listing": false, - "chapters": ["aira"] - } - }, - { - "name": "arizona-philips", - "type": "music", - "favourites": { - "listing": true, - "chapters": [] - } - } - ] -} \ No newline at end of file diff --git a/ryuji.ts b/ryuji.ts index 4e1e035..83d8861 100644 --- a/ryuji.ts +++ b/ryuji.ts @@ -89,10 +89,10 @@ export class Renderer { if (recursion_layer > 5) throw Error("Components more than 5 layers deep, components may be referencing each other in infinite loop."); if (typeof exp_parts[1] !== "string") throw Error("`component:` statement missing component file name afterwards"); let file_name: string = exp_parts[1]; - if (!file_name.includes(".")) { - file_name += this.file_extension; - } - rendered += this.render_template(Renderer.concat_path(this.components_dir, file_name), vars, recursion_layer+1); + if (!file_name.includes(".")) { + file_name += this.file_extension; + } + rendered += this.render_template(Renderer.concat_path(this.components_dir, file_name), vars, recursion_layer+1); } else if (exp_parts[0] === "for") { if (for_loops[for_loops.length-1]?.index === index) { //for loop already exists, just continue and do nothing diff --git a/templates/player.html b/templates/player.html index dc2d7b7..a793d7f 100644 --- a/templates/player.html +++ b/templates/player.html @@ -7,7 +7,6 @@