jenkins-bot has submitted this change and it was merged.
Change subject: Render attribution page
......................................................................
Render attribution page
Change-Id: I4e6c3b6d92088fe1a600ddb35eed66abfa630327
---
M lib/index.js
1 file changed, 54 insertions(+), 16 deletions(-)
Approvals:
Cscott: Looks good to me, approved
jenkins-bot: Verified
diff --git a/lib/index.js b/lib/index.js
index 772f416..1d39b00 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -112,7 +112,12 @@
// Set the default font
"\\setmainfont[" + (SCRIPT_FONTS['default'].options||'') + "]{" +
SCRIPT_FONTS['default'].name + "}",
"\\newcommand{\\LTRfont}{}",
- "\\newcommand{\\textsmall}[1]{\\small #1}",
+ "\\newcommand{\\textsmall}[1]{{\\small #1}}",
+ // smaller size, one column for attributions
+ "\\newcommand{\\attributions}{" +
+ "\\renewcommand{\\textsmall}[1]{{\\scriptsize ##1}}" +
+ "\\footnotesize\\onecolumn" +
+ "}",
"\\date{}\\author{}"
].join("\n");
@@ -723,7 +728,9 @@
// Don't allow them in single item collections, as the article class doesn't
// allow \chapters
Visitor.prototype.visitHn = function(node, n) {
- if (!this.options.hasChapters) { n -= 1; }
+ if (this.options.isAttribution) {
+ if (this.options.hasChapters) { n -= 1; }
+ } else if (!this.options.hasChapters) { n -= 1; }
if (this.options.singleItem && n === 0) {
/* the article class doesn't allow chapters */
return;
@@ -1436,7 +1443,8 @@
// files have been written.
var generateLatex = function(metabook, builddir, imagemap, options) {
var status = options.status;
- status.createStage(countItems(metabook), 'Processing collection');
+ // add one to the item count to accomodate attribution 'chapter'
+ status.createStage(countItems(metabook)+1, 'Processing collection');
status.report(null, metabook.title);
var output = fs.createWriteStream(path.join(builddir, 'output.tex'), {
@@ -1509,16 +1517,22 @@
);
var write = {};
write.article = function(item) {
- console.assert(item.type === 'article');
- status.report('Processing article', item.title);
+ var isAttribution = (item.type === 'attribution');
+ console.assert(item.type === 'article' || isAttribution);
+ status.report('Processing', item.type, item.title);
var revid = item.revision;
var document, base = '', articleLanguage;
var key = (item.wiki ? (item.wiki+'|') : '') + revid;
var outfile = path.join(
- builddir, 'latex', item.wiki + '-' + revid + '.tex'
+ builddir, 'latex',
+ isAttribution ? 'attribution.tex' :
+ (item.wiki + '-' + revid + '.tex')
);
output.write('\\input{' + outfile + '}\n');
- return pdb.get(key, 'nojson').then(function(data) {
+ var pContents = isAttribution ?
+ P.call(fs.readFile, fs, item.filename, { encoding:
'utf8' }) :
+ pdb.get(key, 'nojson');
+ return pContents.then(function(data) {
document = domino.createDocument(data);
var baseElem = document.querySelector('head >
base[href]');
if (baseElem) {
@@ -1542,14 +1556,17 @@
singleItem: singleItem,
hasChapters: hasChapters,
lang: collectionLanguage,
- dir: collectionDir
+ dir: collectionDir,
+ isAttribution: isAttribution
});
- var h1 = document.createElement('h1');
- var span = document.createElement('span');
- h1.appendChild(span);
- span.textContent = item.title;
- span.lang = articleLanguage;
- visitor.visit(h1); // emit document title!
+ if (!isAttribution) {
+ var h1 = document.createElement('h1');
+ var span = document.createElement('span');
+ h1.appendChild(span);
+ span.textContent = item.title;
+ span.lang = articleLanguage;
+ visitor.visit(h1); // emit document title!
+ }
document.body.lang = document.body.lang ||
articleLanguage;
document.body.dir = document.body.dir ||
Polyglossia.lookup(document.body.lang).dir;
@@ -1573,7 +1590,26 @@
};
return P.forEachSeq(metabook.items, function(item) {
- return write[item.type](item);
+ if (write[item.type]) {
+ return write[item.type](item);
+ } else {
+ console.warn("Unknown item type '%s', ignoring",
item.type);
+ }
+ }).then(function() {
+ var filename = path.join(builddir, 'bundle',
'attribution.html');
+ if (!fs.existsSync(filename)) {
+ status.report('Processing attribution (skipped)');
+ return;
+ }
+ // write attribution 'chapter'
+ output.write('\\attributions\n');
+ return write.article({
+ type: 'attribution',
+ filename: filename,
+ title: '',
+ // XXX should use options.lang to choose an appropriate
wiki
+ wiki: 0
+ });
}).then(function() {
return P.call(output.end, output, STD_FOOTER);
}).then(function() {
@@ -1720,7 +1756,9 @@
builddir = _builddir;
// read the main metabook.json file
return P.call(
- fs.readFile, fs, path.join(builddir, 'bundle',
'metabook.json')
+ fs.readFile, fs,
+ path.join(builddir, 'bundle', 'metabook.json'),
+ { encoding: 'utf8' }
).then(function(data) {
metabook = JSON.parse(data);
});
--
To view, visit https://gerrit.wikimedia.org/r/148611
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I4e6c3b6d92088fe1a600ddb35eed66abfa630327
Gerrit-PatchSet: 6
Gerrit-Project:
mediawiki/extensions/Collection/OfflineContentGenerator/latex_renderer
Gerrit-Branch: master
Gerrit-Owner: Mwalker <[email protected]>
Gerrit-Reviewer: Cscott <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits