Merge pull request #509 from nature-of-code/dev/add-chapter-opening-only-build

This commit is contained in:
Yifei Gao 2023-10-03 12:35:54 -05:00 committed by GitHub
commit a4ec039e3c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 23 deletions

View file

@ -11,10 +11,10 @@
"magicbook/plugins/chapter-opening.js",
"magicbook/plugins/callout.js"
],
"destination": "build",
"files": [
"content/*.html"
],
"layout": "magicbook/layouts/pdf.html",
"images": {
"colorspace": "grey16",
"files": [
@ -23,19 +23,24 @@
"magicbook/images/**/*.*"
]
},
"stylesheets": {
"files": [
"magicbook/stylesheets/index.scss"
]
},
"fonts": {
"files": "magicbook/fonts/**/*.*",
"destination": "assets/fonts/"
},
"builds": [
{
"format": "pdf",
"layout": "magicbook/layouts/pdf.html",
"stylesheets": {
"files": [
"magicbook/stylesheets/index.scss"
]
},
"fonts": {
"files": "magicbook/fonts/**/*.*",
"destination": "assets/fonts/"
}
"destination": "build/chapter-opening-preview",
"chapterOpeningPagesOnly": true
},
{
"format": "pdf",
"destination": "build/full"
}
]
}

View file

@ -19,23 +19,27 @@ Plugin.prototype = {
// match the number and name
const match = /(\d+)\.\s([A-Za-z\s]+)/.exec(chapterTitle.text());
if (match) {
chapterTitle.replaceWith(
`<div class="chapter-opening"><div class="chapter-opening-header"><span class="chapter-number">${match[1]}</span><div class="chapter-opening-title"><h1>${match[2]}</h1></div></div></div>`,
);
chapterTitle.replaceWith(
`<div class="chapter-opening"><div class="chapter-opening-header"><span class="chapter-number">${match[1]}</span><div class="chapter-opening-title"><h1>${match[2]}</h1></div></div></div>`,
);
// if chapter-opening-quote exist
const chapterOpeningQuote = file.$el('div.chapter-opening-quote');
if (chapterOpeningQuote) {
file.$el('div.chapter-opening-title').append(chapterOpeningQuote);
}
// if chapter-opening-quote exist
const chapterOpeningQuote = file.$el('div.chapter-opening-quote');
if (chapterOpeningQuote) {
file.$el('div.chapter-opening-title').append(chapterOpeningQuote);
// if chapter-opening-figure exist
const chapterOpeningFigure = file.$el('div.chapter-opening-figure');
if (chapterOpeningFigure) {
file.$el('div.chapter-opening').append(chapterOpeningFigure);
}
}
// if chapter-opening-figure exist
const chapterOpeningFigure = file.$el('div.chapter-opening-figure');
if (chapterOpeningFigure) {
file.$el('div.chapter-opening').append(chapterOpeningFigure);
if (config.chapterOpeningPagesOnly) {
file.$el('div.chapter-opening').nextAll().remove();
}
cb(null, file);
}),
);