Skip to content
Snippets Groups Projects
Commit cec190e7 authored by Alexandros Georgantas's avatar Alexandros Georgantas
Browse files

feat: download html for pagedJS

parent 250510b4
No related branches found
No related tags found
No related merge requests found
...@@ -148,6 +148,20 @@ const EpubBackend = app => { ...@@ -148,6 +148,20 @@ const EpubBackend = app => {
res.status(500).json({ error: error.message }) res.status(500).json({ error: error.message })
} }
}) })
app.use('/api/pagedStyler/exportHTML/:id/', async (req, res, next) => {
const { id } = req.params
const path = `${process.cwd()}/uploads/paged/${id}/index.html`
try {
const file = await readFile(path)
res.setHeader('Content-Type', 'text/html')
res.setHeader('Content-Disposition', `attachment; filename=${id}.html`)
res.write(file, 'binary')
res.end()
} catch (error) {
res.status(500).json({ error: error.message })
}
})
} }
const writeFile = (location, content) => const writeFile = (location, content) =>
...@@ -157,5 +171,12 @@ const writeFile = (location, content) => ...@@ -157,5 +171,12 @@ const writeFile = (location, content) =>
return resolve() return resolve()
}) })
}) })
const readFile = location =>
new Promise((resolve, reject) => {
fs.readFile(location, 'binary', (err, data) => {
if (err) return reject(err)
return resolve(data)
})
})
module.exports = EpubBackend module.exports = EpubBackend
...@@ -144,6 +144,16 @@ module.exports = ( ...@@ -144,6 +144,16 @@ module.exports = (
} }
}) })
$('highlighter').each((i, elem) => {
const $elem = $(elem)
$elem.replaceWith($elem.text())
})
$('ornament').each((i, elem) => {
const $elem = $(elem)
const hr = $('<hr>')
$elem.replaceWith(hr)
})
// replace inline notes with endnotes // replace inline notes with endnotes
$('note').each((i, elem) => { $('note').each((i, elem) => {
const $elem = $(elem) const $elem = $(elem)
......
...@@ -144,7 +144,15 @@ module.exports = ( ...@@ -144,7 +144,15 @@ module.exports = (
$elem.remove() $elem.remove()
} }
}) })
$('highlighter').each((i, elem) => {
const $elem = $(elem)
$elem.replaceWith($elem.text())
})
$('ornament').each((i, elem) => {
const $elem = $(elem)
const hr = $('<hr>')
$elem.replaceWith(hr)
})
const hasNotes = $('note').length > 0 const hasNotes = $('note').length > 0
if (hasNotes) { if (hasNotes) {
......
...@@ -168,6 +168,16 @@ module.exports = ( ...@@ -168,6 +168,16 @@ module.exports = (
} }
}) })
$('highlighter').each((i, elem) => {
const $elem = $(elem)
$elem.replaceWith($elem.text())
})
$('ornament').each((i, elem) => {
const $elem = $(elem)
const hr = $('<hr>')
$elem.replaceWith(hr)
})
// replace inline notes with endnotes // replace inline notes with endnotes
$('note').each((i, elem) => { $('note').each((i, elem) => {
const $elem = $(elem) const $elem = $(elem)
......
...@@ -164,6 +164,17 @@ module.exports = ( ...@@ -164,6 +164,17 @@ module.exports = (
$elem.remove() $elem.remove()
} }
}) })
$('highlighter').each((i, elem) => {
const $elem = $(elem)
$elem.replaceWith($elem.text())
})
$('ornament').each((i, elem) => {
const $elem = $(elem)
const hr = $('<hr>')
$elem.replaceWith(hr)
})
const hasNotes = $('note').length > 0 const hasNotes = $('note').length > 0
if (hasNotes) { if (hasNotes) {
......
...@@ -3,7 +3,9 @@ const cheerio = require('cheerio') ...@@ -3,7 +3,9 @@ const cheerio = require('cheerio')
const create = async (book, parts, resourceRoot, stylesRoot, fontsRoot) => { const create = async (book, parts, resourceRoot, stylesRoot, fontsRoot) => {
const output = cheerio.load( const output = cheerio.load(
`<!DOCTYPE html><html><head><title>${book.title}</title> `<!DOCTYPE html><html><head><title>${book.title}</title>
<meta charset="UTF-8"></head><body class="hyphenate" lang="en-us"></body></html>`, <meta charset="UTF-8"></head><body class="hyphenate" lang="en-us"><section class="titlepage"><header><h1 class="booktitle">${
book.title
}</h1></header></section></body></html>`,
) )
const TOC = createTOC(parts) const TOC = createTOC(parts)
output('body').append(TOC.html()) output('body').append(TOC.html())
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment