Skip to content

Commit

Permalink
fix(pubu): cannot get books info
Browse files Browse the repository at this point in the history
  • Loading branch information
YuerLee committed Oct 15, 2023
1 parent 14c053c commit 0e34d35
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions src/stores/pubu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,31 +106,34 @@ function _getBooks($: CheerioAPI, base: string) {
// 價格列表包(部分書籍有一般版與下載版兩種價格)
const $priceList = $(elem).find('.info-price').children('div');

const id = $(elem).find('.cover').children('a').prop('data-ecga');

let book: Book = {
// id: $(elem).children('.caption').children('.price-info').children('meta[itemprop=identifier]').prop('content'),
thumbnail: $(elem).find('.cover').children('img').prop('data-src'),
title: $(elem).find('.cover').children('img').prop('title'),
link: new URL($(elem).children('div').children('a').prop('href') ?? '', base).toString(),
id,
thumbnail: $(elem).find('.cover').children('a').children('img').prop('data-src'),
title: $(elem).find('.cover').children('a').children('img').prop('title'),
link: id ? new URL(`ebook/${id}`, base).toString() : '',
priceCurrency: 'TWD',
price: parseFloat($priceList.eq(0).children('span').text().replace('NT$', '')) || -1,
authors: $(elem)
.find('.info-others')
.children('a')
.eq(1)
.text()
.trim()
.split(/, |,|、|,|//g)
.map((author) => {
// 特別分工的作者,改變格式
const authorSplit = author.split(':');

if (authorSplit.length > 1) {
author = `${authorSplit[1]}${authorSplit[0]})`;
}

return author;
}),
publisher: $(elem).find('.info-others').children('a').eq(0).text(),
authors: [
...$(elem)
.find('.info-others')
.children('a.author')
.text()
.trim()
.split(/, |,|、|,|//g)
.map((author) => {
// 特別分工的作者,改變格式
const authorSplit = author.split(':');

if (authorSplit.length > 1) {
author = `${authorSplit[1]}${authorSplit[0]})`;
}

return author;
}),
].flat(Infinity),
publisher: $(elem).find('.info-others').children('a:not(.author)').text().trim(),
};
// 有多種價格,則為下載版
if ($priceList.length > 1) {
Expand Down

0 comments on commit 0e34d35

Please sign in to comment.