From f5dc4778f91751e2d77d9308fdeaaf4d2db75506 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 21 Nov 2024 06:37:11 +0100 Subject: [PATCH] Add anime identifiers --- _cms.ts | 105 ++++++++++++++++++++++++++++++++++++++------ _includes/anime.tsx | 71 +++++++++++++++++++++++++++++- _includes/game.tsx | 14 +++++- _utils/anime.ts | 24 +++++++++- _utils/game.ts | 15 +++---- _utils/review.ts | 10 +++++ 6 files changed, 212 insertions(+), 27 deletions(-) diff --git a/_cms.ts b/_cms.ts index e29b5d7..c5dce81 100644 --- a/_cms.ts +++ b/_cms.ts @@ -181,7 +181,7 @@ cms.collection( name: "identifiers", type: "choose-list", label: "Identifiers", - description: "Details that unequivocabily and globally identify the game. Shouldn't be edited manually.", + description: "Details that unequivocabily and globally identify the game. Edit manually at your own risk.", fields: [ { name: "steam", @@ -193,22 +193,30 @@ cms.collection( name: "appid", type: "text", label: "AppID", - description: "The AppID that the game has on Steam. Usually ends with a 0. Can be obtained from the store page link, after the /app/ segment.", - }, - { - name: "name", - type: "text", - label: "Name", - description: "The title of the game, as it appears on Steam." + description: "The AppID that the game has on Steam. Usually ends with a 0. Can be obtained from the store page link after the /app/ segment.", }, { name: "synced_on", type: "date", label: "Last sync", - description: "The date of the last sync." + description: "The date of the last sync via `deno task import-steam`." } ] - } + }, + { + name: "wikidata", + type: "object", + label: "Wikidata", + description: "The game, stored as a Wikidata item.", + fields: [ + { + name: "q", + type: "number", + label: "Wikidata identifier", + description: "The ID that the item has on Wikidata. The number following the `Q`.", + }, + ] + }, ] }, { @@ -316,15 +324,84 @@ cms.collection( label: "Mastered on", description: "The date on which you've achieved mastery of the anime.", }, - /* { name: "identifiers", type: "choose-list", label: "Identifiers", - description: "Details that unequivocabily and globally identify the anime. Shouldn't be edited manually.", - fields: [] + description: "Details that unequivocabily and globally identify the anime. Edit manually at your own risk.", + fields: [ + { + name: "mal", + type: "object", + label: "MyAnimeList", + description: "The anime, as it is stored on MyAnimeList.", + fields: [ + { + name: "id", + type: "text", + label: "MAL ID", + description: "The anime ID that the anime has on MyAnimeList. Can be obtained from the anime page link after the `/anime/` segment.", + }, + ] + }, + { + name: "anidb", + type: "object", + label: "AniDB", + description: "The anime, as it is stored on AniDB.", + fields: [ + { + name: "aid", + type: "text", + label: "AID", + description: "The anime ID that the anime has on AniDB. Can be obtained from the anime page link, after the `/anime/` segment, or from the `aid` query parameter.", + }, + ] + }, + { + name: "annid", + type: "object", + label: "Anime News Network", + description: "The anime, as it is stored on Anime News Network.", + fields: [ + { + name: "id", + type: "text", + label: "ANN ID", + description: "The anime ID that the anime has on AniDB. Can be obtained from the anime page link from the `id` query parameter.", + }, + ] + }, + { + name: "anilist", + type: "object", + label: "Anilist", + description: "The anime, as it is stored on Anilist.", + fields: [ + { + name: "id", + type: "text", + label: "Anilist ID", + description: "The anime ID that the anime has on Anilist. Can be obtained from the anime page link after the `/anime/` segment.", + }, + ] + }, + { + name: "wikidata", + type: "object", + label: "Wikidata", + description: "The anime, stored as a Wikidata item.", + fields: [ + { + name: "q", + type: "text", + label: "Wikidata identifier", + description: "The ID that the item has on Wikidata. The number following the `Q`.", + }, + ] + }, + ] }, - */ { name: "content", type: "markdown", diff --git a/_includes/anime.tsx b/_includes/anime.tsx index cc11d94..b58d012 100644 --- a/_includes/anime.tsx +++ b/_includes/anime.tsx @@ -1,5 +1,5 @@ import {formatDateIso} from "../_utils/date.ts" -import {AnimeData, AnimeProgress, animeProgressToClassName, animeProgressToIconDef, animeProgressToTitle} from "../_utils/anime.ts" +import {AnimeData, AnimeIdentifier, AnimeProgress, animeProgressToClassName, animeProgressToIconDef, animeProgressToTitle} from "../_utils/anime.ts" import {ReviewInfo} from "../_components/ReviewInfo.tsx" @@ -102,6 +102,73 @@ export default function(data: AnimeData, helpers: Lume.Helpers) { ) : null + const milestonesSeparator = ((data.identifiers?.length ?? 0) > 0) ?
: null + + const identifiersRows = data.identifiers?.map((identifier: AnimeIdentifier, index: number) => { + switch(identifier.type) { + case "wikidata": + return ( +  Wikidata} + > + + Q{identifier.q} + + + ) + case "anidb": + return ( +  AniDB} + > + + {identifier.aid} + + + ) + case "mal": + return ( +  MyAnimeList} + > + + {identifier.id} + + + ) + case "ann": + return ( +  Anime News Network} + > + + {identifier.id} + + + ) + case "anilist": + return ( +  Anilist} + > + + {identifier.id} + + + ) + } + }) + return (
} > {data.children} diff --git a/_includes/game.tsx b/_includes/game.tsx index af5e1e8..055a3ad 100644 --- a/_includes/game.tsx +++ b/_includes/game.tsx @@ -119,6 +119,18 @@ export default function(data: GameData, helpers: Lume.Helpers) { const identifiersRows = data.identifiers?.map((identifier: GameIdentifier, index: number) => { switch(identifier.type) { + case "wikidata": + return ( +  Wikidata} + > + + Q{identifier.q} + + + ) case "steam": return (  Steam} > - {identifier.name ?? identifier.appid} + {identifier.appid} ) diff --git a/_utils/anime.ts b/_utils/anime.ts index 581766b..940bf26 100644 --- a/_utils/anime.ts +++ b/_utils/anime.ts @@ -1,4 +1,26 @@ -import { ReviewData } from "./review.ts"; +import { ReviewData, ReviewIdentifier, ReviewWikidataIdentifier } from "./review.ts"; + +export interface AnimeAnidbIdentifier extends ReviewIdentifier { + type: "anidb"; + aid: string; +} + +export interface AnimeMalIdentifier extends ReviewIdentifier { + type: "mal"; + id: string; +} + +export interface AnimeAnnIdentifier extends ReviewIdentifier { + type: "ann"; + id: string; +} + +export interface AnimeAnilistIdentifier extends ReviewIdentifier { + type: "anilist"; + id: string; +} + +export type AnimeIdentifier = ReviewWikidataIdentifier | AnimeAnidbIdentifier | AnimeMalIdentifier | AnimeAnnIdentifier | AnimeAnilistIdentifier; export interface AnimeData extends ReviewData { name_original: string; diff --git a/_utils/game.ts b/_utils/game.ts index 9f3d930..7ca59b6 100644 --- a/_utils/game.ts +++ b/_utils/game.ts @@ -1,17 +1,12 @@ -import { ReviewData } from "./review.ts"; +import { ReviewData, ReviewIdentifier, ReviewWikidataIdentifier } from "./review.ts"; -export interface GameBaseIdentifier { - type: string; +export interface GameSteamIdentifier extends ReviewIdentifier { + type: "steam"; + appid: string; synced_on?: string; } -export interface GameSteamIdentifier extends GameBaseIdentifier { - type: "steam"; - appid: string; - name?: string; -} - -export type GameIdentifier = GameSteamIdentifier; +export type GameIdentifier = ReviewWikidataIdentifier | GameSteamIdentifier; export interface GameData extends ReviewData { active?: boolean; diff --git a/_utils/review.ts b/_utils/review.ts index 1449623..cf8dedc 100644 --- a/_utils/review.ts +++ b/_utils/review.ts @@ -2,6 +2,16 @@ import {Rating} from "./rating.ts" import {GlobalData} from "./site.ts" +export interface ReviewIdentifier { + type: string; +} + +export interface ReviewWikidataIdentifier extends ReviewIdentifier { + type: "wikidata", + q: string, +} + + export interface ReviewData extends GlobalData { name?: string, name_sort?: string,