Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gulp-ssg

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-ssg - npm Package Compare versions

Comparing version 0.5.0 to 1.0.0

.editorconfig

97

index.js

@@ -12,18 +12,15 @@ 'use strict';

/**
* Convert text files to a website with nice urls, extra file meta-data and
* provide a tree style index of the content.
* Convert text files to a website with nice urls, extra file.data and a website.map tree of content
*
* @param object site The site to attach the indexes to
* @param array options.baseUrl The base url of the final site
* @param object website An object to attach the map to, reference added to each file
* @param array options.baseUrl The base url of the final website
* @param array options.sort The property to sort by
* @param array options.property The property to attach to the file, defaults to `meta`
* @param array options.sectionProperties List of properties to copy from index file to section
* @return stream
*/
module.exports = function(site, options) {
site = site || {};
module.exports = function(website, options) {
website = website || {};
options = _.extend({
baseUrl: '',
sort: 'url',
property: 'meta',
sectionProperties: []

@@ -33,3 +30,3 @@ }, options || {});

// remove trailing slash from baseUrl
if(options.baseUrl && options.baseUrl.length > 1 && options.baseUrl.substr(-1) === '/') {
if (options.baseUrl && options.baseUrl.length > 1 && options.baseUrl.substr(-1) === '/') {
options.baseUrl = options.baseUrl.substr(0, options.baseUrl.length - 1);

@@ -43,7 +40,3 @@ }

/**
* Rename each file and add meta properties:
* - isHome
* - isIndex
* - url
* - sectionUrl
* Rename each file and add properties to `data`
*

@@ -53,5 +46,2 @@ * @param object file

function bufferContents(file) {
if (typeof options.property !== 'string' || !options.property) {
return this.emit('error', new PluginError('gulp-ssg', 'options.property is required'));
}
if (file.isNull()) {

@@ -63,2 +53,3 @@ return;

}
var basename = path.basename(file.relative, path.extname(file.path)),

@@ -70,3 +61,4 @@ isIndex = basename === 'index',

file[options.property] = _.extend({
file.data = _.extend({
website: website,
name: basename,

@@ -77,3 +69,3 @@ isIndex: isIndex,

sectionUrl: sectionUrl(fileUrl, isIndex)
}, file[options.property] || {});
}, file.data || {});

@@ -84,4 +76,4 @@ buffer.push(file);

/**
* At the end of the stream build the site index, sort, then emit the file data.
* This ensures the full index is built before the next pipe sees the file.
* At the end of the stream build the website map, sort, then emit the file data.
* This ensures the full map is built before the next pipe sees the file.
*/

@@ -95,4 +87,4 @@ function endStream() {

buffer.sort(function(a, b) {
var aDepth = a.meta.url.split('/').length;
var bDepth = b.meta.url.split('/').length;
var aDepth = a.data.url.split('/').length;
var bDepth = b.data.url.split('/').length;
if (aDepth < bDepth) {

@@ -108,8 +100,8 @@ return -1;

return a[options.property][options.sort] >= b[options.property][options.sort] ? 1 : -1;
return a.data[options.sort] >= b.data[options.sort] ? 1 : -1;
});
}
site.index = treeify(options.baseUrl, buffer);
addSectionToFiles(site.index);
website.map = treeify(options.baseUrl, buffer);
addSectionToFiles(website.map);

@@ -124,8 +116,8 @@ buffer.forEach(function(file) {

/**
* Copy options.sectionProperties from file meta to section
* Copy options.sectionProperties from file data to section
*
* @param object meta
* @param object data
* @return object
*/
function copySectionProperties(meta) {
function copySectionProperties(data) {
if (typeof options.sectionProperties.forEach !== 'function') {

@@ -136,4 +128,4 @@ return;

options.sectionProperties.forEach(function(prop) {
if (typeof meta[prop] !== 'undefined') {
props[prop] = meta[prop];
if (typeof data[prop] !== 'undefined') {
props[prop] = data[prop];
}

@@ -154,3 +146,2 @@ });

foundAtIndex,
meta,
baseUrlReplace = new RegExp('^' + baseUrl),

@@ -164,12 +155,11 @@ sectionsToFiles = mapSectionsToFiles(buffer),

buffer.forEach(function(file) {
meta = file[options.property];
if (meta.isHome) {
if (file.data.isHome) {
contentTree.name = 'root';
contentTree.url = meta.url;
contentTree = _.extend(contentTree, copySectionProperties(meta));
contentTree.url = file.data.url;
contentTree = _.extend(contentTree, copySectionProperties(file.data));
return;
}
if (!meta.isIndex) {
if (!file.data.isIndex) {
return;

@@ -179,3 +169,3 @@ }

currentList = contentTree.sections;
meta.url.replace(baseUrlReplace, '').split('/').filter(function(t) {
file.data.url.replace(baseUrlReplace, '').split('/').filter(function(t) {
return t !== '';

@@ -195,6 +185,6 @@ }).forEach(function(token, index) {

name: token,
url: meta.url,
url: file.data.url,
sections: [],
files: sectionsToFiles[meta.sectionUrl]
}, copySectionProperties(meta)));
files: sectionsToFiles[file.data.sectionUrl]
}, copySectionProperties(file.data)));

@@ -215,9 +205,8 @@ currentList = currentList[currentList.length-1].sections;

function mapSectionsToFiles() {
var map = {}, meta;
var map = {};
buffer.forEach(function(file) {
meta = file[options.property];
if (typeof map[meta.sectionUrl] === 'undefined') {
map[meta.sectionUrl] = [];
if (typeof map[file.data.sectionUrl] === 'undefined') {
map[file.data.sectionUrl] = [];
}
map[meta.sectionUrl].push(file);
map[file.data.sectionUrl].push(file);
});

@@ -229,13 +218,13 @@

/**
* Give each file meta a reference back to it's section
* Give each file data a reference back to it's section
*
* @param object index The content tree
* @param object map The website map
*/
function addSectionToFiles(index) {
if (!index.files.length) {
function addSectionToFiles(map) {
if (!map.files.length) {
return;
}
index.files.forEach(function(file) {
file[options.property].section = index;
if (!index.sections.length) {
map.files.forEach(function(file) {
file.data.section = map;
if (!map.sections.length) {
return;

@@ -245,3 +234,3 @@ }

// Recurse over nested sections
index.sections.forEach(function(section) {
map.sections.forEach(function(section) {
addSectionToFiles(section);

@@ -248,0 +237,0 @@ });

{
"name": "gulp-ssg",
"version": "0.5.0",
"version": "1.0.0",
"main": "index.js",

@@ -25,5 +25,11 @@ "homepage": "https://github.com/paulwib/gulp-ssg",

"devDependencies": {
"chai": "~1.9.0",
"event-stream": "^3.1.7",
"front-matter": "^0.2.0",
"gulp": "~3.8.9",
"chai": "~1.9.0",
"gulp-data": "^1.0.2",
"hogan.js": "^3.0.2",
"marked": "^0.3.2",
"mocha": "~2.0.1",
"mversion": "^1.6.1",
"should": "~4.1.0"

@@ -35,3 +41,6 @@ },

"scripts": {
"test": "./node_modules/mocha/bin/mocha"
"test": "./node_modules/mocha/bin/mocha",
"release-patch": "./node_modules/.bin/mversion patch -m 'Released patch version v%s'",
"release-minor": "./node_modules/.bin/mversion minor -m 'Released minor version v%s'",
"release-major": "./node_modules/.bin/mversion major -m 'Released major version v%s'"
},

@@ -38,0 +47,0 @@ "keywords": [

@@ -1,2 +0,2 @@

gulp-ssg [![NPM version][npm-image]][npm-url] [![Dependency Status][depstat-image]][depstat-url]
gulp-ssg [![NPM version][npm-image]][npm-url] [![Dependency Status][depstat-image]][depstat-url] [![Build Status][travis-image]][travis-url]
===

@@ -6,2 +6,8 @@

## Installation
```bash
$ npm install gulp-ssg
```
## Usage

@@ -11,3 +17,3 @@

var ssg = require('gulp-ssg');
var site = {
var website = {
title: 'My site'

@@ -18,3 +24,3 @@ };

return gulp.src('content/**/*.md')
.pipe(ssg(site))
.pipe(ssg(website))
.pipe(gulp.dest('public/'));

@@ -31,74 +37,45 @@ });

It will also add properties to a `meta` object of each file:
It will add properties to each files `data` property:
* `file.meta.url`
* `file.meta.isHome`
* `file.meta.isIndex`
* `file.meta.sectionUrl`
* `file.meta.section`
* `file.data.url` - `string` The full page URL
* `file.data.isHome` - `boolean` Is it the root index page?
* `file.data.isIndex` - `boolean` Is it a directory index page?
* `file.data.sectionUrl` - `string` The URL of the section this page is in
* `file.data.section` - `object` A pointer to the section in the website map
* `file.data.website` - `object` The original passed in website object
* `file.data.website.map` - `object` A map of all the files
Finally, it will add an `index` property to the passed in `site` object which is a tree of all the content.
The above example would look like:
The `file.data.website.map` represents a tree map of all files in the website. This can be used for things like generating global navigation, or making a single-page website. It looks like:
```javascript
{
name: 'root',
url: '/',
files: [<index.html>, <foo/index.html> ] // All files in this section
sections: [
{
name: 'bar',
url: 'bar',
files: [<bar/index.html>, <bar/foo/index.html>]
}
]
}
{
name: 'root',
url: '/',
files: [<index.html>, <foo/index.html> ] // All files in this section
sections: [
{
name: 'bar',
url: '/bar/',
files: [<bar/index.html>, <bar/foo/index.html>]
}
]
}
```
Also each file has a reference back to it's section in the tree, so it's possible to generate sub-navigation too with `file.data.section.files`.
As implied above each file has a reference back to it's section in this tree.
## Example
It gets more interesting when combined with other pipes. For example:
So how can this be used? It gets more interesting when combined with other pipes. For example:
```javascript
var ssg = require('gulp-ssg');
var frontmatter = require('gulp-front-matter');
var marked = require('gulp-marked');
var site = {
title: 'My site'
};
gulp.task('html', function() {
return gulp.src('content/**/*.md')
.pipe(frontmatter({
property: 'meta'
}))
.pipe(marked())
.pipe(ssg(site, {
property: 'meta'
}))
.pipe(gulp.dest('public/'));
});
```
This will extract any YAML front-matter, convert the content of each file from markdown to HTML, then run the ssg. The data extracted from the front-matter will be combined with the data extracted by the ssg in the `meta` property.
## Templates
A common requirement of static sites is to pass the content through some template engine. There is nothing built into `gulp-ssg` to do this, but it's very easy to add with another pipe.
After the step above you will have created a bunch of HTML files. Now you can run them through a templating pipe. All the files are processed before the next pipe, so the template will have access to the complete site index for things like generating global navigation, or a list of sub-pages in the current section.
So to add this to the above example:
```javascript
var ssg = require('gulp-ssg');
var frontmatter = require('gulp-front-matter');
var marked = require('gulp-marked');
var ssg = require('../');
var gulp = require('gulp');
var data = require('gulp-data');
var fm = require('front-matter');
var marked = require('marked');
var fs = require('fs');
var es = require('event-stream');
var mustache = require('mustache');
var site = {
var hogan = require('hogan.js');
var website = {
title: 'My site'

@@ -109,26 +86,30 @@ };

var template = String(fs.readFileSync('templates/page.html'));
// Compile a template for rendering each page
var template = hogan.compile(String(fs.readFileSync('templates/template.html')));
return gulp.src('content/**/*.md')
.pipe(frontmatter({
property: 'meta'
// Extract YAML front-matter, convert content to markdown via gulp-data
.pipe(data(function(file) {
var content = fm(String(file.contents));
file.contents = new Buffer(marked(content.body));
return content.attributes;
}))
.pipe(marked())
.pipe(ssg(site, {
property: 'meta'
}))
// Run through gulp-ssg, copy title from YAML to section
.pipe(ssg(website, { sectionProperties: ['title'] }))
// Run each file through a template
.pipe(es.map(function(file, cb) {
var html = mustache.render(template, {
page: file.meta,
site: site,
content: String(file.contents)
});
file.contents = new Buffer(html);
file.contents = new Buffer(template.render(file));
cb(null, file);
}))
.pipe(gulp.dest('public/'));
// Output to build directory
.pipe(gulp.dest('build/'));
});
```
This uses `es.map` to modify the stream directly, but if you have a common way of rendering many sites it might be worth writing a little plug-in with a bit more error handling etc.
This plug-in follows the [gulp-data][] convention of using `file.data`, so anything returned from a `gulp-data` pipe will be merged with the properties above.

@@ -147,8 +128,4 @@ ## Caveats

A property to sort pages by in the index, defaults to `url`. For example, this could be a property like `order` extracted from the YAML front-matter, giving content editors full control over the order of pages.
A property to sort pages by, defaults to `url`. For example, this could be a property like `order` extracted from the YAML front-matter, giving content editors full control over the order of pages.
### property `string`
The name of the property to attach data to, defaults to `meta`.
### sectionProperties `array`

@@ -158,24 +135,5 @@

## Previewing Your Website
Add a `watch` task to run a server for previewing your website:
```javascript
var http = require('http'),
ecstatic = require('ecstatic');
gulp.task('watch', function() {
http.createServer(
ecstatic({ root: __dirname + '/public' })
).listen(8745);
console.log('Preview at http://localhost:8745');
gulp.watch('content/', ['html']);
gulp.watch('templates/', ['default']);
});
```
[gulp]:http://gulpjs.com
[gulp-data]:https://github.com/colynb/gulp-data

@@ -186,2 +144,5 @@ [npm-url]: https://npmjs.org/package/gulp-ssg

[depstat-url]: https://david-dm.org/paulwib/gulp-ssg
[depstat-image]: https://david-dm.org/paulwib/gulp-ssg.svg?style=flat
[depstat-image]: https://david-dm.org/paulwib/gulp-ssg.svg?style=flat
[travis-image]: http://img.shields.io/travis/paulwib/gulp-ssg/master.svg?style=flat
[travis-url]: https://travis-ci.org/paulwib/gulp-ssg

@@ -11,3 +11,2 @@ 'use strict';

function getMarkdownFile(path, content) {

@@ -61,4 +60,4 @@ return new File({

it('should assign booleans for isHome and isIndex', function(done) {
var site = {};
var stream = ssg(site);
var website = {};
var stream = ssg(website);
var home = getMarkdownFile('test/index.md', 'home');

@@ -70,10 +69,10 @@ var page = getMarkdownFile('test/hello.md', 'page');

stream.on('end', function() {
expect(home.meta.isHome).to.be.true;
expect(home.meta.isIndex).to.be.true;
expect(page.meta.isHome).to.be.false;
expect(page.meta.isIndex).to.be.false;
expect(sectionIndex.meta.isHome).to.be.false;
expect(sectionIndex.meta.isIndex).to.be.true;
expect(sectionPage.meta.isHome).to.be.false;
expect(sectionPage.meta.isIndex).to.be.false;
expect(home.data.isHome).to.be.true;
expect(home.data.isIndex).to.be.true;
expect(page.data.isHome).to.be.false;
expect(page.data.isIndex).to.be.false;
expect(sectionIndex.data.isHome).to.be.false;
expect(sectionIndex.data.isIndex).to.be.true;
expect(sectionPage.data.isHome).to.be.false;
expect(sectionPage.data.isIndex).to.be.false;
done();

@@ -90,4 +89,4 @@ });

it('should assign a name unique within the section', function(done) {
var site = {};
var stream = ssg(site);
var website = {};
var stream = ssg(website);
var home = getMarkdownFile('test/index.md', 'home');

@@ -99,6 +98,6 @@ var page = getMarkdownFile('test/hello.md', 'page');

stream.on('end', function() {
expect(home.meta.name).to.equal('index');
expect(page.meta.name).to.equal('hello');
expect(sectionIndex.meta.name).to.equal('index');
expect(sectionPage.meta.name).to.equal('bar');
expect(home.data.name).to.equal('index');
expect(page.data.name).to.equal('hello');
expect(sectionIndex.data.name).to.equal('index');
expect(sectionPage.data.name).to.equal('bar');
done();

@@ -115,8 +114,8 @@ });

it('should not override properties assigned to the site', function(done) {
var site = { title: 'My Site' };
var stream = ssg(site);
var website = { title: 'My Site' };
var stream = ssg(website);
var file1 = getMarkdownFile('test/index.md', 'home');
stream.on('end', function() {
expect(site.title).to.equal('My Site');
expect(website.title).to.equal('My Site');
done();

@@ -130,4 +129,4 @@ });

it('should assign urls', function(done) {
var site = {};
var stream = ssg(site);
var website = {};
var stream = ssg(website);
var home = getMarkdownFile('test/index.md', 'home');

@@ -139,6 +138,6 @@ var page = getMarkdownFile('test/hello.md', 'page');

stream.on('end', function() {
expect(home.meta.url).to.equal('/');
expect(page.meta.url).to.equal('/hello/');
expect(sectionIndex.meta.url).to.equal('/foo/');
expect(sectionPage.meta.url).to.equal('/foo/bar/');
expect(home.data.url).to.equal('/');
expect(page.data.url).to.equal('/hello/');
expect(sectionIndex.data.url).to.equal('/foo/');
expect(sectionPage.data.url).to.equal('/foo/bar/');
done();

@@ -155,4 +154,4 @@ });

it('should assign section urls', function(done) {
var site = {};
var stream = ssg(site);
var website = {};
var stream = ssg(website);
var home = getMarkdownFile('test/index.md', 'home');

@@ -164,6 +163,6 @@ var page = getMarkdownFile('test/hello.md', 'page');

stream.on('end', function() {
expect(home.meta.sectionUrl).to.equal('/');
expect(page.meta.sectionUrl).to.equal('/');
expect(sectionIndex.meta.sectionUrl).to.equal('/foo/');
expect(sectionPage.meta.sectionUrl).to.equal('/foo/');
expect(home.data.sectionUrl).to.equal('/');
expect(page.data.sectionUrl).to.equal('/');
expect(sectionIndex.data.sectionUrl).to.equal('/foo/');
expect(sectionPage.data.sectionUrl).to.equal('/foo/');
done();

@@ -180,7 +179,7 @@ });

it('should use the specified base url', function(done) {
var site = {};
var website = {};
var options = {
baseUrl: '/path/to/site'
};
var stream = ssg(site, options);
var stream = ssg(website, options);
var home = getMarkdownFile('test/index.md', 'home');

@@ -192,6 +191,6 @@ var page = getMarkdownFile('test/hello.md', 'page');

stream.on('end', function() {
expect(home.meta.url).to.equal('/path/to/site/');
expect(page.meta.url).to.equal('/path/to/site/hello/');
expect(sectionIndex.meta.url).to.equal('/path/to/site/foo/');
expect(sectionPage.meta.url).to.equal('/path/to/site/foo/bar/');
expect(home.data.url).to.equal('/path/to/site/');
expect(page.data.url).to.equal('/path/to/site/hello/');
expect(sectionIndex.data.url).to.equal('/path/to/site/foo/');
expect(sectionPage.data.url).to.equal('/path/to/site/foo/bar/');
done();

@@ -208,7 +207,7 @@ });

it('should remove a trailing slash from the specified base url', function(done) {
var site = {};
var website = {};
var options = {
baseUrl: '/path/to/site/'
};
var stream = ssg(site, options);
var stream = ssg(website, options);
var home = getMarkdownFile('test/index.md', 'home');

@@ -220,6 +219,6 @@ var page = getMarkdownFile('test/hello.md', 'page');

stream.on('end', function() {
expect(home.meta.url).to.equal('/path/to/site/');
expect(page.meta.url).to.equal('/path/to/site/hello/');
expect(sectionIndex.meta.url).to.equal('/path/to/site/foo/');
expect(sectionPage.meta.url).to.equal('/path/to/site/foo/bar/');
expect(home.data.url).to.equal('/path/to/site/');
expect(page.data.url).to.equal('/path/to/site/hello/');
expect(sectionIndex.data.url).to.equal('/path/to/site/foo/');
expect(sectionPage.data.url).to.equal('/path/to/site/foo/bar/');
done();

@@ -236,4 +235,4 @@ });

it('should generate an index tree of sections', function(done) {
var site = {};
var stream = ssg(site);
var website = {};
var stream = ssg(website);
var home = getMarkdownFile('test/index.md', 'home');

@@ -244,9 +243,9 @@ var sectionIndex = getMarkdownFile('test/foo/index.md', 'section index');

stream.on('end', function() {
expect(site.index).to.not.be.undefined;
expect(site.index.sections).to.not.be.undefined;
expect(site.index.sections[0].name).to.equal('foo');
expect(site.index.sections[0].url).to.equal('/foo/');
expect(site.index.sections[0].sections[0].name).to.equal('bar');
expect(site.index.sections[0].sections[0].url).to.equal('/foo/bar/');
expect(site.index.sections[0].sections[0].sections).to.be.empty;
expect(website.map).to.not.be.undefined;
expect(website.map.sections).to.not.be.undefined;
expect(website.map.sections[0].name).to.equal('foo');
expect(website.map.sections[0].url).to.equal('/foo/');
expect(website.map.sections[0].sections[0].name).to.equal('bar');
expect(website.map.sections[0].sections[0].url).to.equal('/foo/bar/');
expect(website.map.sections[0].sections[0].sections).to.be.empty;
done();

@@ -262,7 +261,7 @@ });

it('should generate an index tree of sections with correct baseUrl', function(done) {
var site = {};
var website = {};
var options = {
baseUrl: '/path/to/site'
};
var stream = ssg(site, options);
var stream = ssg(website, options);
var home = getMarkdownFile('test/index.md', 'home');

@@ -273,9 +272,9 @@ var sectionIndex = getMarkdownFile('test/foo/index.md', 'section index');

stream.on('end', function() {
expect(site.index).to.not.be.undefined;
expect(site.index.sections).to.not.be.undefined;
expect(site.index.sections[0].name).to.equal('foo');
expect(site.index.sections[0].url).to.equal('/path/to/site/foo/');
expect(site.index.sections[0].sections[0].name).to.equal('bar');
expect(site.index.sections[0].sections[0].url).to.equal('/path/to/site/foo/bar/');
expect(site.index.sections[0].sections[0].sections).to.be.empty;
expect(website.map).to.not.be.undefined;
expect(website.map.sections).to.not.be.undefined;
expect(website.map.sections[0].name).to.equal('foo');
expect(website.map.sections[0].url).to.equal('/path/to/site/foo/');
expect(website.map.sections[0].sections[0].name).to.equal('bar');
expect(website.map.sections[0].sections[0].url).to.equal('/path/to/site/foo/bar/');
expect(website.map.sections[0].sections[0].sections).to.be.empty;
done();

@@ -291,4 +290,4 @@ });

it('should allow overriding section name in tree', function(done) {
var site = {};
var stream = ssg(site, {
var website = {};
var stream = ssg(website, {
sectionProperties: ['sectionTitle']

@@ -300,15 +299,15 @@ });

sectionIndex.meta = { sectionTitle: 'This is foo' };
subsectionIndex.meta = { sectionTitle: 'This is bar' };
sectionIndex.data = { sectionTitle: 'This is foo' };
subsectionIndex.data = { sectionTitle: 'This is bar' };
stream.on('end', function() {
expect(site.index).to.not.be.undefined;
expect(site.index.sections).to.not.be.undefined;
expect(site.index.sections[0].name).to.equal('foo');
expect(site.index.sections[0].sectionTitle).to.equal('This is foo');
expect(site.index.sections[0].url).to.equal('/foo/');
expect(site.index.sections[0].sections[0].name).to.equal('bar');
expect(site.index.sections[0].sections[0].sectionTitle).to.equal('This is bar');
expect(site.index.sections[0].sections[0].url).to.equal('/foo/bar/');
expect(site.index.sections[0].sections[0].sections).to.be.empty;
expect(website.map).to.not.be.undefined;
expect(website.map.sections).to.not.be.undefined;
expect(website.map.sections[0].name).to.equal('foo');
expect(website.map.sections[0].sectionTitle).to.equal('This is foo');
expect(website.map.sections[0].url).to.equal('/foo/');
expect(website.map.sections[0].sections[0].name).to.equal('bar');
expect(website.map.sections[0].sections[0].sectionTitle).to.equal('This is bar');
expect(website.map.sections[0].sections[0].url).to.equal('/foo/bar/');
expect(website.map.sections[0].sections[0].sections).to.be.empty;
done();

@@ -324,4 +323,4 @@ });

it('should add files to the section tree', function(done) {
var site = {};
var stream = ssg(site);
var website = {};
var stream = ssg(website);
var home = getMarkdownFile('test/index.md', 'home');

@@ -340,6 +339,6 @@ var page1 = getMarkdownFile('test/hello.md', 'page');

stream.on('end', function() {
expect(site.index).to.not.be.undefined;
expect(site.index.files.length).to.equal(3);
expect(site.index.sections[0].files.length).to.equal(4);
expect(site.index.sections[0].sections[0].files.length).to.equal(3);
expect(website.map).to.not.be.undefined;
expect(website.map.files.length).to.equal(3);
expect(website.map.sections[0].files.length).to.equal(4);
expect(website.map.sections[0].sections[0].files.length).to.equal(3);
done();

@@ -363,4 +362,4 @@ });

// ideally the inverse of this should pass, but it's difficult
var site = {};
var stream = ssg(site);
var website = {};
var stream = ssg(website);
var home = getMarkdownFile('test/index.md', 'home');

@@ -377,5 +376,5 @@ var page1 = getMarkdownFile('test/hello.md', 'page');

stream.on('end', function() {
expect(site.index).to.not.be.undefined;
expect(site.index.files.length).to.equal(3);
expect(typeof site.index.sections[0]).to.equal('undefined');
expect(website.map).to.not.be.undefined;
expect(website.map.files.length).to.equal(3);
expect(typeof website.map.sections[0]).to.equal('undefined');
done();

@@ -396,4 +395,4 @@ });

it('should give each file a section reference', function(done) {
var site = {};
var stream = ssg(site);
var website = {};
var stream = ssg(website);
var home = getMarkdownFile('test/index.md', 'home');

@@ -411,21 +410,21 @@ var page1 = getMarkdownFile('test/hello.md', 'page');

stream.on('end', function() {
expect(home.meta.section).to.not.be.undefined;
expect(home.meta.section.name).to.equal('root');
expect(page1.meta.section.name).to.equal('root');
expect(page2.meta.section.name).to.equal('root');
expect(home.meta.section.files).to.not.be.undefined;
expect(page1.meta.section.files).to.not.be.undefined;
expect(page2.meta.section.files).to.not.be.undefined;
expect(sectionIndex.meta.section.name).to.equal('foo');
expect(sectionPage1.meta.section.name).to.equal('foo');
expect(sectionPage2.meta.section.name).to.equal('foo');
expect(sectionIndex.meta.section.files).to.not.be.undefined;
expect(sectionPage1.meta.section.files).to.not.be.undefined;
expect(sectionPage2.meta.section.files).to.not.be.undefined;
expect(subsectionIndex.meta.section.name).to.equal('bar');
expect(subsectionPage1.meta.section.name).to.equal('bar');
expect(subsectionPage2.meta.section.name).to.equal('bar');
expect(subsectionIndex.meta.section.files).to.not.be.undefined;
expect(subsectionPage1.meta.section.files).to.not.be.undefined;
expect(subsectionPage2.meta.section.files).to.not.be.undefined;
expect(home.data.section).to.not.be.undefined;
expect(home.data.section.name).to.equal('root');
expect(page1.data.section.name).to.equal('root');
expect(page2.data.section.name).to.equal('root');
expect(home.data.section.files).to.not.be.undefined;
expect(page1.data.section.files).to.not.be.undefined;
expect(page2.data.section.files).to.not.be.undefined;
expect(sectionIndex.data.section.name).to.equal('foo');
expect(sectionPage1.data.section.name).to.equal('foo');
expect(sectionPage2.data.section.name).to.equal('foo');
expect(sectionIndex.data.section.files).to.not.be.undefined;
expect(sectionPage1.data.section.files).to.not.be.undefined;
expect(sectionPage2.data.section.files).to.not.be.undefined;
expect(subsectionIndex.data.section.name).to.equal('bar');
expect(subsectionPage1.data.section.name).to.equal('bar');
expect(subsectionPage2.data.section.name).to.equal('bar');
expect(subsectionIndex.data.section.files).to.not.be.undefined;
expect(subsectionPage1.data.section.files).to.not.be.undefined;
expect(subsectionPage2.data.section.files).to.not.be.undefined;
done();

@@ -448,4 +447,4 @@ });

it('should default to sort by url', function(done) {
var site = {};
var stream = ssg(site);
var website = {};
var stream = ssg(website);
var home = getMarkdownFile('test/index.md', 'home');

@@ -459,4 +458,4 @@ var page1 = getMarkdownFile('test/xyz.md', 'page');

stream.on('end', function() {
var urls = site.index.files.map(function(file) {
return file.meta.url;
var urls = website.map.files.map(function(file) {
return file.data.url;
});

@@ -468,4 +467,4 @@ expect(urls).to.deep.equal([

]);
var sectionUrls = site.index.sections[0].files.map(function(file) {
return file.meta.url;
var sectionUrls = website.map.sections[0].files.map(function(file) {
return file.data.url;
});

@@ -490,7 +489,7 @@ expect(sectionUrls).to.deep.equal([

it('should be possible to sort pages by assigned property', function(done) {
var site = {};
var website = {};
var options = {
sort: 'order'
};
var stream = ssg(site, options);
var stream = ssg(website, options);
var home = getMarkdownFile('test/index.md', 'home');

@@ -504,11 +503,11 @@ var page1 = getMarkdownFile('test/xyz.md', 'page');

page1.meta = { order: 1 };
page2.meta = { order: 12 };
page3.meta = { order: 6 };
sectionPage1.meta = { order: 1 };
sectionPage2.meta = { order: 2 };
page1.data = { order: 1 };
page2.data = { order: 12 };
page3.data = { order: 6 };
sectionPage1.data = { order: 1 };
sectionPage2.data = { order: 2 };
stream.on('end', function() {
var urls = site.index.files.map(function(file) {
return file.meta.url;
var urls = website.map.files.map(function(file) {
return file.data.url;
});

@@ -521,4 +520,4 @@ expect(urls).to.deep.equal([

]);
var sectionUrls = site.index.sections[0].files.map(function(file) {
return file.meta.url;
var sectionUrls = website.map.sections[0].files.map(function(file) {
return file.data.url;
});

@@ -544,7 +543,7 @@ expect(sectionUrls).to.deep.equal([

it('should be possible to sort indexes in section (but indexes always come first in their own section)', function(done) {
var site = {};
var website = {};
var options = {
sort: 'order'
};
var stream = ssg(site, options);
var stream = ssg(website, options);
var home = getMarkdownFile('test/index.md', 'home');

@@ -561,16 +560,16 @@ var section1Index = getMarkdownFile('test/foo/index.md', 'section index');

section1Index.meta = { order: 5 };
section1Page1.meta = { order: 1 };
section1Page2.meta = { order: 2 };
section1Index.data = { order: 5 };
section1Page1.data = { order: 1 };
section1Page2.data = { order: 2 };
section2Index.meta = { order: 3 };
section2Page1.meta = { order: 1 };
section2Page2.meta = { order: 2 };
section2Index.data = { order: 3 };
section2Page1.data = { order: 1 };
section2Page2.data = { order: 2 };
section3Index.meta = { order: 1 };
section3Page1.meta = { order: 1 };
section3Page2.meta = { order: 2 };
section3Index.data = { order: 1 };
section3Page1.data = { order: 1 };
section3Page2.data = { order: 2 };
stream.on('end', function() {
var sectionUrls = site.index.sections.map(function(section) {
var sectionUrls = website.map.sections.map(function(section) {
return section.url;

@@ -584,4 +583,4 @@ });

var section1Urls = site.index.sections[0].files.map(function(file) {
return file.meta.url;
var section1Urls = website.map.sections[0].files.map(function(file) {
return file.data.url;
});

@@ -594,4 +593,4 @@ expect(section1Urls).to.deep.equal([

var section2Urls = site.index.sections[1].files.map(function(file) {
return file.meta.url;
var section2Urls = website.map.sections[1].files.map(function(file) {
return file.data.url;
});

@@ -604,4 +603,4 @@ expect(section2Urls).to.deep.equal([

var section3Urls = site.index.sections[2].files.map(function(file) {
return file.meta.url;
var section3Urls = website.map.sections[2].files.map(function(file) {
return file.data.url;
});

@@ -631,4 +630,4 @@ expect(section3Urls).to.deep.equal([

it('should emit file data after the full index is created', function(done) {
var site = {};
var stream = ssg(site);
var website = {};
var stream = ssg(website);
var home = getMarkdownFile('test/index.md', 'home');

@@ -640,9 +639,9 @@ var sectionIndex = getMarkdownFile('test/foo/index.md', 'section index');

stream.on('data', function() {
expect(site.index).to.not.be.undefined;
expect(site.index.sections).to.not.be.undefined;
expect(site.index.sections[0].name).to.equal('foo');
expect(site.index.sections[0].url).to.equal('/foo/');
expect(site.index.sections[0].sections[0].name).to.equal('bar');
expect(site.index.sections[0].sections[0].url).to.equal('/foo/bar/');
expect(site.index.sections[0].sections[0].sections).to.be.empty;
expect(website.map).to.not.be.undefined;
expect(website.map.sections).to.not.be.undefined;
expect(website.map.sections[0].name).to.equal('foo');
expect(website.map.sections[0].url).to.equal('/foo/');
expect(website.map.sections[0].sections[0].name).to.equal('bar');
expect(website.map.sections[0].sections[0].url).to.equal('/foo/bar/');
expect(website.map.sections[0].sections[0].sections).to.be.empty;
if (testCount++ === 2) {

@@ -649,0 +648,0 @@ done();

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc