French website use same layout as English one YAY

This commit is contained in:
Michel Roux 2021-08-18 11:52:29 +02:00
parent 06f346d171
commit d147d65813
3 changed files with 28 additions and 84 deletions

View File

@ -4,14 +4,13 @@ type: docker
steps: steps:
- name: epub - name: epub
image: node:14.17.4 image: node
commands: commands:
- npm i - npm i
- ./node_modules/.bin/eslint *.js - ./node_modules/.bin/eslint *.js
- node livres_fr - node livres
- node livres_en
- name: pdf - name: pdf
image: linuxserver/calibre:v5.23.0-ls121 image: linuxserver/calibre
commands: commands:
- bash -x convert.sh - bash -x convert.sh
- bash -x upload.sh - bash -x upload.sh

View File

@ -3,24 +3,23 @@ const cheerio = require('cheerio')
const fetch = require('node-fetch') const fetch = require('node-fetch')
const epub = require('epub-gen') const epub = require('epub-gen')
const books = []
if (!fs.existsSync('output')) { if (!fs.existsSync('output')) {
fs.mkdirSync('output') fs.mkdirSync('output')
} }
const metadata = (volume) => ({ const metadata = (volume, title, author, tocTitle, description) => ({
title: `The Wandering Inn - Volume ${volume}`, title: `${title} - Volume ${volume}`,
author: ['Pirateaba'], author,
cover: 'https://i.pinimg.com/originals/0b/fd/cf/0bfdcfb42ba3ff0a22f4a7bc52928af4.png', cover: 'https://i.pinimg.com/originals/0b/fd/cf/0bfdcfb42ba3ff0a22f4a7bc52928af4.png',
output: `output/The Wandering Inn - Volume ${volume}.epub`, output: `output/${title} - Volume ${volume}.epub`,
version: 3, version: 3,
lang: 'en', lang: 'fr',
tocTitle,
appendChapterTitles: true, appendChapterTitles: true,
content: [], content: [],
links: [], links: [],
verbose: true, verbose: true,
description: 'A tale of a girl, an inn, and a world full of levels', description,
}) })
const fetchPage = async (url) => { const fetchPage = async (url) => {
@ -42,18 +41,23 @@ const fetchPage = async (url) => {
} }
} }
(async () => { const run = async (url, authors) => {
const response = await fetch('https://wanderinginn.com/table-of-contents/') const books = []
const response = await fetch(url)
const responseHtml = await response.text() const responseHtml = await response.text()
const html = cheerio.load(responseHtml) const html = cheerio.load(responseHtml)
const content = html('div.entry-content > p') const content = html('div.entry-content > p')
const title = html('#site-title > span > a').text()
const summary = html('h1.entry-title').text()
const description = html('#site-description').text()
let volume = 0; let volume = 0;
content.each((i, el) => { content.each((i, el) => {
if (i % 2 === 0) { if (i % 2 === 0) {
volume = html(el).text().replace(/Volume /, '').trim() volume = html(el).text().replace(/Volume /, '').trim()
books.push(metadata(volume)) if (volume === '') return
books.push(metadata(volume, title, authors, summary, description))
} else { } else {
html('a', el).each((i, el) => { html('a', el).each((i, el) => {
books[volume - 1].links.push(html(el).attr('href')) books[volume - 1].links.push(html(el).attr('href'))
@ -68,4 +72,13 @@ const fetchPage = async (url) => {
new epub(book) new epub(book)
}) })
})() }
run(
'https://aubergevagabonde.wordpress.com/sommaire/',
['Maroti', 'ElliVia', 'Pirateaba']
)
run(
'https://wanderinginn.com/table-of-contents/',
['Pirateaba']
)

View File

@ -1,68 +0,0 @@
const fs = require('fs')
const cheerio = require('cheerio')
const fetch = require('node-fetch')
const epub = require('epub-gen')
let post = 0
let page = 0
const MAX_VOLUME = 3
const books = []
if (!fs.existsSync('output')) {
fs.mkdirSync('output')
}
const volume = (post) => post <= 69 ? 1 : post <= 168 ? 2 : MAX_VOLUME
const metadata = (volume) => ({
title: `L'auberge Vagabonde - Volume ${volume}`,
author: ['Maroti', 'ElliVia', 'Pirateaba'],
cover: 'https://i.pinimg.com/originals/0b/fd/cf/0bfdcfb42ba3ff0a22f4a7bc52928af4.png',
output: `output/L'auberge Vagabonde - Volume ${volume}.epub`,
version: 3,
lang: 'fr',
tocTitle: 'Table des matières',
appendChapterTitles: true,
content: [],
verbose: true,
description: "L'histoire d'une fille, d'une auberge et d'un monde plein de niveaux",
})
for (let i = 1; i <= MAX_VOLUME; i++) {
books.push(metadata(i))
}
(async () => {
while (true) {
const response = await fetch(`https://www.jeunesecrivains.com/t53075p${page++ * 15}-the-wandering-inn-fan-traduction-fantastique-aventure`)
const responseHtml = await response.text()
const html = cheerio.load(responseHtml)
const postBody = html('div.postbody')
if (postBody.html() === null) break
postBody.each((i, el) => {
if (++post === 1) return
const title = html('div[align=center]', el)
if (title.html() === null) return
let text = html('div > div', el)
text.attr('style', '')
const titleFirst = title.first()
titleFirst.find('br').replaceWith(' ')
const titleText = titleFirst.text().replace(/\*/g, '')
titleFirst.empty()
console.log(`${post} - ${titleText}`)
books[volume(post) - 1].content.push({
title: titleText,
data: text.html(),
})
})
}
books.map(book => new epub(book))
})()