mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-27 04:29:05 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0bce3517fd | |||
| 089815a8fd | |||
| 7e8f1a9632 | |||
| 8469648241 | |||
| e7a44358a5 | |||
| fb930d889f | |||
| 721a75309b | |||
| b856bff91b | |||
| 0744f000f9 |
+8
-1
@@ -2,7 +2,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## 3.0.0 (pre)
|
||||
## 3.0.2
|
||||
- Fix crash for anchor links
|
||||
|
||||
## 3.0.1
|
||||
- Fix regression in link resolution when contain anchor
|
||||
- Fix `structure.<name>` configuration not supporting filenames with dots
|
||||
|
||||
## 3.0.0
|
||||
- Summary can contain external links and anchors (Fix [#776](https://github.com/GitbookIO/gitbook/issues/776))
|
||||
- Summary can contain differents entitled sections
|
||||
- Glossary is generated as a normal page
|
||||
|
||||
@@ -51,5 +51,5 @@ This is the default content
|
||||
|
||||
# License
|
||||
|
||||
{% import "./LICENSE" %}
|
||||
{% include "./LICENSE" %}
|
||||
```
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
var jsonschema = require('jsonschema');
|
||||
var schema = require('../configSchema');
|
||||
|
||||
describe('configSchema', function() {
|
||||
|
||||
function validate(cfg) {
|
||||
var v = new jsonschema.Validator();
|
||||
return v.validate(cfg, schema, {
|
||||
propertyName: 'config'
|
||||
});
|
||||
}
|
||||
|
||||
describe('structure', function() {
|
||||
|
||||
it('should accept dot in filename', function() {
|
||||
var result = validate({
|
||||
structure: {
|
||||
readme: 'book-intro.adoc'
|
||||
}
|
||||
});
|
||||
|
||||
expect(result.errors.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should not accept filepath', function() {
|
||||
var result = validate({
|
||||
structure: {
|
||||
readme: 'folder/myFile.md'
|
||||
}
|
||||
});
|
||||
|
||||
expect(result.errors.length).toBe(1);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
@@ -1,3 +1,5 @@
|
||||
var FILENAME_REGEX = '^[a-z-._\d,\s]+$';
|
||||
|
||||
module.exports = {
|
||||
'$schema': 'http://json-schema.org/schema#',
|
||||
'id': 'https://gitbook.com/schemas/book.json',
|
||||
@@ -57,25 +59,25 @@ module.exports = {
|
||||
'default': 'LANGS.md',
|
||||
'type': 'string',
|
||||
'title': 'File to use as languages index',
|
||||
'pattern': '^[0-9a-zA-Z ... ]+$'
|
||||
'pattern': FILENAME_REGEX
|
||||
},
|
||||
'readme': {
|
||||
'default': 'README.md',
|
||||
'type': 'string',
|
||||
'title': 'File to use as preface',
|
||||
'pattern': '^[0-9a-zA-Z ... ]+$'
|
||||
'pattern': FILENAME_REGEX
|
||||
},
|
||||
'glossary': {
|
||||
'default': 'GLOSSARY.md',
|
||||
'type': 'string',
|
||||
'title': 'File to use as glossary index',
|
||||
'pattern': '^[0-9a-zA-Z ... ]+$'
|
||||
'pattern': FILENAME_REGEX
|
||||
},
|
||||
'summary': {
|
||||
'default': 'SUMMARY.md',
|
||||
'type': 'string',
|
||||
'title': 'File to use as table of contents',
|
||||
'pattern': '^[0-9a-zA-Z ... ]+$'
|
||||
'pattern': FILENAME_REGEX
|
||||
}
|
||||
},
|
||||
'additionalProperties': false
|
||||
|
||||
@@ -4,7 +4,6 @@ var Promise = require('../utils/promise');
|
||||
var error = require('../utils/error');
|
||||
var timing = require('../utils/timing');
|
||||
|
||||
var Parse = require('../parse');
|
||||
var Templating = require('../templating');
|
||||
var JSONUtils = require('../json');
|
||||
var createTemplateEngine = require('./createTemplateEngine');
|
||||
|
||||
@@ -4,7 +4,7 @@ var resolveLinks = require('../resolveLinks');
|
||||
|
||||
describe('resolveLinks', function() {
|
||||
function resolveFileBasic(href) {
|
||||
return href;
|
||||
return 'fakeDir/' + href;
|
||||
}
|
||||
|
||||
function resolveFileCustom(href) {
|
||||
@@ -24,7 +24,7 @@ describe('resolveLinks', function() {
|
||||
return resolveLinks('hello.md', resolveFileBasic, $)
|
||||
.then(function() {
|
||||
var link = $('a');
|
||||
expect(link.attr('href')).toBe('test/cool.md');
|
||||
expect(link.attr('href')).toBe('fakeDir/test/cool.md');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -34,7 +34,31 @@ describe('resolveLinks', function() {
|
||||
return resolveLinks('afolder/hello.md', resolveFileBasic, $)
|
||||
.then(function() {
|
||||
var link = $('a');
|
||||
expect(link.attr('href')).toBe('../test/cool.md');
|
||||
expect(link.attr('href')).toBe('../fakeDir/test/cool.md');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Anchor', function() {
|
||||
it('should prevent anchors in resolution', function() {
|
||||
var TEST = '<p>This is a <a href="test/cool.md#an-anchor"></a></p>';
|
||||
var $ = cheerio.load(TEST);
|
||||
|
||||
return resolveLinks('hello.md', resolveFileCustom, $)
|
||||
.then(function() {
|
||||
var link = $('a');
|
||||
expect(link.attr('href')).toBe('test/cool.html#an-anchor');
|
||||
});
|
||||
});
|
||||
|
||||
it('should ignore pure anchor links', function() {
|
||||
var TEST = '<p>This is a <a href="#an-anchor"></a></p>';
|
||||
var $ = cheerio.load(TEST);
|
||||
|
||||
return resolveLinks('hello.md', resolveFileCustom, $)
|
||||
.then(function() {
|
||||
var link = $('a');
|
||||
expect(link.attr('href')).toBe('#an-anchor');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
var path = require('path');
|
||||
var url = require('url');
|
||||
|
||||
var LocationUtils = require('../../utils/location');
|
||||
var editHTMLElement = require('./editHTMLElement');
|
||||
@@ -27,14 +28,23 @@ function resolveLinks(currentFile, resolveFile, $) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Calcul absolute path for this
|
||||
href = LocationUtils.toAbsolute(href, currentDirectory, '.');
|
||||
// Split anchor
|
||||
var parsed = url.parse(href);
|
||||
href = parsed.pathname || '';
|
||||
|
||||
// Resolve file
|
||||
href = resolveFile(href);
|
||||
if (href) {
|
||||
// Calcul absolute path for this
|
||||
href = LocationUtils.toAbsolute(href, currentDirectory, '.');
|
||||
|
||||
// Convert back to relative
|
||||
href = LocationUtils.relative(currentDirectory, href);
|
||||
// Resolve file
|
||||
href = resolveFile(href);
|
||||
|
||||
// Convert back to relative
|
||||
href = LocationUtils.relative(currentDirectory, href);
|
||||
}
|
||||
|
||||
// Add back anchor
|
||||
href = href + (parsed.hash || '');
|
||||
|
||||
$a.attr('href', href);
|
||||
});
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "gitbook",
|
||||
"version": "3.0.0",
|
||||
"version": "3.0.2",
|
||||
"homepage": "https://www.gitbook.com",
|
||||
"description": "Library and cmd utility to generate GitBooks",
|
||||
"main": "lib/index.js",
|
||||
@@ -29,7 +29,7 @@
|
||||
"gitbook-plugin-lunr": "1.1.0",
|
||||
"gitbook-plugin-search": "2.2.1",
|
||||
"gitbook-plugin-sharing": "1.0.2",
|
||||
"gitbook-plugin-theme-default": "1.0.1",
|
||||
"gitbook-plugin-theme-default": "1.0.2",
|
||||
"github-slugid": "1.0.1",
|
||||
"graceful-fs": "4.1.4",
|
||||
"i18n-t": "1.0.0",
|
||||
|
||||
Reference in New Issue
Block a user