Skip to content

Commit

Permalink
Hyperlinks for staff in the Mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Koopzington committed Sep 12, 2024
1 parent 07e694c commit f5ac1ec
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 2024-09-12
- Staff in the Mapper is now directly linked for more convenience

## 2024-09-11
- Added a RegEx switch for the title and name filters
- Updated dependencies
Expand Down
43 changes: 33 additions & 10 deletions src/Tools/Mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ class Mapper implements Tool {
const startDate = [alEntry.start_date_y, alEntry.start_date_m, alEntry.start_date_d].filter(Boolean).join('-')
this.curYearRegex = new RegExp(alEntry.start_date_y)
this.curStaffRegex = []
let staff: string[] = []
let staff: Staff[] = []
alEntry.authors.forEach((author) => {
// Remove superfluous spaces, just in case
author.name_last = author.name_last !== null ? author.name_last.trim() : null
Expand All @@ -629,10 +629,12 @@ class Mapper implements Tool {
regName = regName.replaceAll(/uu?/g, 'uu?').replaceAll(/ou?/g, 'ou?')

this.curStaffRegex.push(new RegExp('(' + regName + ')|(' + regName.split(' ').reverse().join(' ') + ')', 'gi'))
if (author.role !== null) {
name += ' (' + author.role + ')'
}
staff.push(name)

staff.push({
id: author.id,
name: name,
role: author.role
})
});

let mediacard = this.getCard(
Expand Down Expand Up @@ -696,14 +698,18 @@ class Mapper implements Tool {
}

private readonly getSuggestionCard = (suggestion: MapperSuggestion) => {
let authors: Array<string> = []
let staff: Staff[] = []
suggestion.authors.forEach((author) => {
// If the last name is all uppercase, make it normal
let exp = author.name.split(' ')
if (exp.length > 1 && exp[0].split('').filter(a => a === a.toLowerCase()).length === 0) {
author.name = exp[0][0] + exp[0].substring(1).toLowerCase() + ' ' + exp[1]
}
authors.push(author.name + ' (' + author.type + ')')
staff.push({
id: author.author_id,
name: author.name,
role: author.type,
});
});
let title: string = suggestion.titles.shift()!
let nativeRegex: RegExp = this.japaneseRegex
Expand All @@ -726,7 +732,7 @@ class Mapper implements Tool {
suggestion.type,
suggestion.original_status,
suggestion.year,
authors,
staff,
suggestion.description,
suggestion.score,
suggestion.voters
Expand Down Expand Up @@ -781,7 +787,7 @@ class Mapper implements Tool {
type: string,
status: string,
release: string,
authors: string[] = [],
authors: Staff[] = [],
description: string | null = null,
score: number | null = null,
voters: string[] | null = null
Expand All @@ -792,7 +798,24 @@ class Mapper implements Tool {
mediacard.querySelector('.type')!.innerText = type
mediacard.querySelector('.status')!.innerHTML = status
mediacard.querySelector('.release')!.innerText = release
mediacard.querySelector('.author')!.innerHTML = authors.join('<br>\n')
let authorList: string[] = [];
authors.forEach((author) => {
// TODO: Maybe finde a better way to differentiate between AL and MU staff
let link = ''
if (score === null) {
link = 'https://anilist.co/staff/' + author.id
} else {
link = 'https://www.mangaupdates.com/authors.html?id=' + author.id
}

let label = author.name
if (author.role !== null) {
label += ' (' + author.role + ')'
}

authorList.push('<a href="' + link + '">' + label + '</a>')
});
mediacard.querySelector('.author')!.innerHTML = authorList.join('<br>\n')
mediacard.querySelector('.other-titles')!.innerHTML = '<span>' + otherTitles.join('</span><span>') + '</span>'
if (description !== "" && description !== null) {
mediacard.querySelector('.description')!.innerHTML = description
Expand Down
6 changes: 6 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ interface ALActivity {
}
}

interface Staff {
id: number
name: string
role: string
}

interface ALUserInfo {
id: number
name: string
Expand Down

0 comments on commit f5ac1ec

Please sign in to comment.