Skip to content

Commit

Permalink
Append country flag?
Browse files Browse the repository at this point in the history
  • Loading branch information
milesoc committed Jun 18, 2024
1 parent 21937e1 commit 849fa6e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/MangaDex/MangaDexInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ export interface RelationshipAttributes {
createdAt: Date;
updatedAt: Date;
version: number;
originalLanguage: OriginalLanguage;
}

export enum RelationshipType {
Expand Down
31 changes: 29 additions & 2 deletions src/MangaDex/MangaDexParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ export const parseMangaList = async (object: MangaItem[], source: any, thumbnail
for (const manga of object) {
const mangaId = manga.id
const mangaDetails = manga.attributes
const title = source.decodeHTMLEntity(mangaDetails.title.en ?? mangaDetails.altTitles.map(x => Object.values(x).find((v) => v !== undefined)).find((t) => t !== undefined))

const countryFlag = getCountryFlag(mangaDetails.originalLanguage)

const title = countryFlag + ' ' + source.decodeHTMLEntity(mangaDetails.title.en ?? mangaDetails.altTitles.map(x => Object.values(x).find((v) => v !== undefined)).find((t) => t !== undefined))
const coverFileName = manga.relationships.filter((x) => x.type == 'cover_art').map((x) => x.attributes?.fileName)[0]
const image = coverFileName ? `${source.COVER_BASE_URL}/${mangaId}/${coverFileName}${MDImageQuality.getEnding(thumbnailSelectorState)}` : 'https://mangadex.org/_nuxt/img/cover-placeholder.d12c3c5.jpg'
const subtitle = `${mangaDetails.lastVolume ? `Vol. ${mangaDetails.lastVolume}` : ''} ${mangaDetails.lastChapter ? `Ch. ${mangaDetails.lastChapter}` : ''}`
Expand Down Expand Up @@ -42,8 +45,10 @@ export const parseChapterListToManga = async (chapters: ChapterItem[], source: a
const mangaDetails = mangaRelationship.attributes

if (mangaDetails === undefined) continue

const countryFlag = getCountryFlag(mangaDetails.originalLanguage)

const title = source.decodeHTMLEntity(mangaDetails.title.en ?? mangaDetails.altTitles.map(x => Object.values(x).find((v) => v !== undefined)).find((t) => t !== undefined))
const title = countryFlag + ' ' + source.decodeHTMLEntity(mangaDetails.title.en ?? mangaDetails.altTitles.map(x => Object.values(x).find((v) => v !== undefined)).find((t) => t !== undefined))
const image = 'https://mangadex.org/_nuxt/img/cover-placeholder.d12c3c5.jpg'
const subtitle = `${mangaDetails.lastVolume ? `Vol. ${mangaDetails.lastVolume}` : ''} ${mangaDetails.lastChapter ? `Ch. ${mangaDetails.lastChapter}` : ''}`

Expand Down Expand Up @@ -83,3 +88,25 @@ export const addFileNamesToManga = async (manga: PartialSourceManga[], covers: C

return manga
}

export const getCountryFlag = (language: string): string => {
const countryMap: { [key: string]: string } = {
"en": "US",
"ja": "JP",
"ko": "KR",
"zh": "CN",
// Add more mappings as needed
};

const countryCode = countryMap[language.substring(0, 2).toLowerCase()]

if (countryCode === undefined) {
return ''
}

const codePoints = Array.from(countryCode, char =>
0x1F1E6 - 65 + char.charCodeAt(0)
)

return String.fromCodePoint(...codePoints)
}

0 comments on commit 849fa6e

Please sign in to comment.