mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-21 01:53:26 +00:00
Fix GitbookIO/plugin-youtube#2: hash remote image for local path
This commit is contained in:
+16
-19
@@ -1,6 +1,7 @@
|
||||
var path = require('path');
|
||||
var _ = require('lodash');
|
||||
var assert = require('assert');
|
||||
var cheerio = require('cheerio');
|
||||
|
||||
var fs = require("fs");
|
||||
var fsUtil = require("../lib/utils/fs");
|
||||
@@ -15,26 +16,22 @@ describe('eBook Generator', function () {
|
||||
|
||||
it('should correctly convert svg images to png', function(done) {
|
||||
testGeneration(books[4], "ebook", function(output) {
|
||||
var readmeContent = fs.readFileSync(path.join(output, "index.html"), {encoding: "utf8"});
|
||||
var pageContent = fs.readFileSync(path.join(output, "sub/PAGE.html"), {encoding: "utf8"});
|
||||
// Check that all images exists
|
||||
_.each([
|
||||
"index.html",
|
||||
"sub/PAGE.html"
|
||||
], function(pageName) {
|
||||
var pageFile = path.join(output, pageName);
|
||||
var pageFolder = path.dirname(pageFile);
|
||||
var pageContent = fs.readFileSync(pageFile, {encoding: "utf8"});
|
||||
var $ = cheerio.load(pageContent);
|
||||
|
||||
// Remote image
|
||||
assert(pageContent.indexOf('src="../Tux.png"') >= 0);
|
||||
assert(fs.existsSync(path.join(output, "Tux.png")));
|
||||
|
||||
assert(fs.existsSync(path.join(output, "test.png")));
|
||||
assert(fs.existsSync(path.join(output, "NewTux.png")));
|
||||
|
||||
assert(!fs.existsSync(path.join(output, "test_0.png")));
|
||||
assert(!fs.existsSync(path.join(output, "sub/test.png")));
|
||||
assert(!fs.existsSync(path.join(output, "sub/NewTux.png")));
|
||||
|
||||
assert(pageContent.indexOf('src="../test.png"') >= 0);
|
||||
assert(pageContent.indexOf('src="../NewTux.png"') >= 0);
|
||||
assert(pageContent.indexOf('<svg') < 0);
|
||||
|
||||
assert(readmeContent.indexOf('src="test.png"') >= 0);
|
||||
assert(readmeContent.indexOf('src="NewTux.png"') >= 0);
|
||||
$("img").each(function() {
|
||||
var src = $(this).attr("src");
|
||||
console.log(path.resolve(pageFolder, src));
|
||||
assert(fs.existsSync(path.resolve(pageFolder, src)), src+" not found for page "+pageName);
|
||||
})
|
||||
});
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
|
||||
Vendored
+4
@@ -5,3 +5,7 @@ A description
|
||||

|
||||

|
||||

|
||||
|
||||
# Test with youtube videos that have the same filename:
|
||||

|
||||

|
||||
|
||||
Vendored
+2
-2
@@ -8,8 +8,8 @@
|
||||
## Inline svg
|
||||
|
||||
{% html %}
|
||||
<svg width="400" height="110">
|
||||
<rect width="300" height="100" style="fill:rgb(0,0,255);stroke-width:3;stroke:rgb(0,0,0)">
|
||||
<svg xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M97.008198003228,6.103238498249268A97.2,97.2 0 0,1 87.9491894996971,41.385747140125076L54.289623147961166,25.546757493904366A60,60 0 0,0 59.88160370569629,3.7674311717588074Z"></path>
|
||||
</svg>
|
||||
{% endhtml %}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user