Skip to content

Commit

Permalink
feat(cover-page): add support for subtitle and revision infos
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Petot committed Mar 12, 2021
1 parent ea58b3c commit 850a90b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6,976 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ node_modules/
!/test/fixtures/*docinfo*-pdf.html
/test/output/visual-comparison-workdir/
build
.idea/
42 changes: 40 additions & 2 deletions lib/document/document-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,19 @@ ${faDom.css()}
if (node.getDocumentTitle()) {
const doc = node.getDocument()
if (this.hasTitlePage(doc)) {
const docTitle = node.getDocument().getDocumentTitle({ partition: true })
const title = docTitle.hasSubtitle() ? `<h1>${docTitle.getMain()}</h1><h2>${docTitle.getSubtitle()}</h2>` : `<h1>${docTitle.getCombined()}</h1>`
const formattedAuthors = `${this.formatAuthorsInfos(node.getDocument().getAuthors())}`
const formattedRevisionInfos = this.formatRevisionInfos(node.getDocument())
let titlePageContent = `${title}`
if (formattedAuthors || formattedAuthors) {
titlePageContent += `<div class="cover-details">
${formattedAuthors}
${formattedRevisionInfos}
</div>`
}
return `<div id="cover" class="title-page front-matter">
<h1>${node.getDocumentTitle()}</h1>
<h2>${node.getDocument().getAuthor()}</h2>
${titlePageContent}
</div>`
}
return `<div class="title-document">
Expand All @@ -498,6 +508,34 @@ ${faDom.css()}
return ''
}

/**
* returns a string that contains the formatted authors infos
* @param {Asciidoctor.Document.Author[]} authors
* @return {string}
*/
formatAuthorsInfos (authors) {
return authors.map((author, index) => {
if (author.getEmail()) return `<span class="author">${author.getName()} &lt<a class="email" href="mailto:${author.getEmail()}">${author.getEmail()}</a>&gt</span>`
else return `<span class="author">${author.getName()}</span>`
}).reduce((previousValue, currentValue) => previousValue.concat(`\r\n${currentValue}`), '')
}

/**
* returns a string that contains the formatted revision infos
* @param {Asciidoctor.Document} document
* @return {string}
*/
formatRevisionInfos (document) {
let res = ''
if (document.getRevisionNumber() || document.getRevisionDate()) {
res += '<span class="revinfos">'
if (document.getRevisionNumber()) res += `\r\n<span id="revnumber">Version ${document.getRevisionNumber()}</span>`
if (document.getRevisionDate()) res += `\r\n<span id="revdate">${document.getRevisionDate()}</span>`
res += '</span>'
}
return res
}

/**
* Generate an (hidden) outline otherwise Chrome won't generate "Dests" fields and we won't be able to generate a PDF outline.
*/
Expand Down
Loading

0 comments on commit 850a90b

Please sign in to comment.