Epub: Basics for epub generation (use of an internal bootstrap copy, fixed minor html errors, added dependencies, added step in build)

This commit is contained in:
Thomas Schwery 2016-05-30 19:14:48 +02:00
parent 4d7aab58da
commit 10b2f9e290
6 changed files with 61 additions and 12 deletions

View file

@ -91,6 +91,7 @@ metalsmith(__dirname)
.use(tags(require('./config/tags'))) .use(tags(require('./config/tags')))
.use(layouts(require('./config/layouts'))) .use(layouts(require('./config/layouts')))
.use(copyVendor()) .use(copyVendor())
.use(epubGen())
.destination('build') .destination('build')
.build(function (err) { .build(function (err) {
if (err) { if (err) {
@ -98,8 +99,40 @@ metalsmith(__dirname)
} }
}) })
function addCategory() { function epubGen() {
var fs = require('fs');
var epubGenerator = require('epub-generator');
return function(files, metalsmith, done) {
var epubStream = epubGenerator({
title: 'Hello World',
author: 'LastLeaf'
});
for (var f in files) {
if (files[f].type == 'recette') {
epubStream.add(f, files[f].contents, {
title: files[f].data.title,
toc: true
});
} else if (files[f].type == 'style') {
epubStream.add(f, files[f].contents, {
toc: false
});
}
}
epubStream.end()
.pipe( fs.createWriteStream('basic.epub') )
.on('error', function(err){
console.trace(err);
});
return done();
}
}
function addCategory() {
return function(files, metalsmith, done) { return function(files, metalsmith, done) {
for (var f in files) { for (var f in files) {
@ -141,9 +174,14 @@ function copyVendor() {
return function(files, metalsmith, done){ return function(files, metalsmith, done){
var bufferMoment = fs.readFileSync('styles/customHighlight.css');
files['styles/customHighlight.css'] = { files['styles/customHighlight.css'] = {
contents: bufferMoment contents: fs.readFileSync('styles/customHighlight.css'),
type: 'style'
};
files['styles/bootstrap.min.css'] = {
contents: fs.readFileSync('styles/bootstrap.min.css'),
type: 'style'
}; };
return done(); return done();

View file

@ -4,6 +4,7 @@
"private": true, "private": true,
"dependencies": { "dependencies": {
"bower": "^1.5.2", "bower": "^1.5.2",
"epub-generator": "^1.0.1",
"handlebars": "^3.0.3", "handlebars": "^3.0.3",
"handlebars-layouts": "^3.1.0", "handlebars-layouts": "^3.1.0",
"highlight.js": "^9.4.0", "highlight.js": "^9.4.0",

6
styles/bootstrap.min.css vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -28,9 +28,12 @@
.content-title { .content-title {
border-bottom: solid 1px; border-bottom: solid 1px;
margin-bottom: -10px;
} }
.header-metadata { .header-metadata {
text-align: right; text-align: right;
} }
.header-container {
font-size: smaller;
}

View file

@ -4,12 +4,13 @@
<meta charset="utf-8"> <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<script src="http://localhost:35729/livereload.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.4.0/styles/default.min.css"> <link rel="stylesheet" href="/styles/bootstrap.min.css">
<link rel="stylesheet" href="/styles/customHighlight.css"> <link rel="stylesheet" href="/styles/customHighlight.css">
<link rel="stylesheet" href="../styles/bootstrap.min.css">
<link rel="stylesheet" href="../styles/customHighlight.css">
<title>{{#block "title"}} {{/block}}</title> <title>{{#block "title"}} {{/block}}</title>
</head> </head>
<body> <body>

View file

@ -19,7 +19,7 @@
<h1 class="content-title"> <h1 class="content-title">
Recette {{ data.title }} Recette {{ data.title }}
</h1> </h1>
<small class="header-container row"> <div class="header-container row">
<div class="header-category col-sm-4"> <div class="header-category col-sm-4">
<a href="/tags/{{ category }}/">{{ category }}</a> <a href="/tags/{{ category }}/">{{ category }}</a>
</div> </div>
@ -30,7 +30,7 @@
{{ data.portion }} {{ data.portion }}
{{#if data.time }}{{ data.time }}{{/if }} {{#if data.time }}{{ data.time }}{{/if }}
</div> </div>
</small> </div>
</header> </header>
<section class="content"> <section class="content">
{{#each data.steps }} {{#each data.steps }}
@ -58,7 +58,7 @@
{{{ contents }}} {{{ contents }}}
</section> </section>
<comments> <section class="comments">
<h2>Commentaires</h2> <h2>Commentaires</h2>
<div id="disqus_thread"></div> <div id="disqus_thread"></div>
<script> <script>
@ -72,7 +72,7 @@
})(); })();
</script> </script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript" rel="nofollow">comments powered by Disqus.</a></noscript> <noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript" rel="nofollow">comments powered by Disqus.</a></noscript>
</comments> </section>
{{/ content}} {{/ content}}
{{/ extend}} {{/ extend}}