Skip to content

Commit

Permalink
fix: cover images issue on wacvostfr crawler
Browse files Browse the repository at this point in the history
  • Loading branch information
AXeL-dev committed Sep 12, 2021
1 parent d1bb372 commit 1cd05ae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/app/crawlers/vostfr/wacvostfr.crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class WacVostfrCrawler extends LatestEpisodesCrawler {
},
cover: (text: string) => {
const title = this.filters.title(text);
return this.filters.concatUrl(`/imgs/animes/${slugify(title)}.jpg`);
return this.filters.concatUrl(`/imgs/animes/${slugify(title, '-')}.jpg`);
},
subtitles: (text: string) => {
const sub = text.trim().match(/(vostfr|vf)(?:.*)$/i);
Expand Down
8 changes: 6 additions & 2 deletions src/app/helpers/string.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,20 @@ function editDistance(s1: string, s2: string) {
return costs[s2.length];
}

export function slugify (text: string) {
export function slugify (text: string, specialCharsReplacement?: string) {
const a = 'àáäâãèéëêìíïîòóöôùúüûñçßÿœæŕśńṕẃǵǹḿǘẍźḧ&·/_,:;';
const b = 'aaaaaeeeeiiiioooouuuuncsyoarsnpwgnmuxzh-------';
const p = new RegExp(a.split('').join('|'), 'g');

const specialCharsReplacer = specialCharsReplacement ?
() => specialCharsReplacement :
(c: string) => b.charAt(a.indexOf(c));

return text
.toString() // Cast to string
.toLowerCase() // Convert to lowercase letters
.replace(/\s+/g, '-') // Replace spaces with -
.replace(p, c => b.charAt(a.indexOf(c))) // Replace special chars
.replace(p, specialCharsReplacer) // Replace special chars
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
Expand Down

0 comments on commit 1cd05ae

Please sign in to comment.