
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
A gulp plugin to help generate a static website from a bunch of files.
$ npm install gulp-ssg
var ssg = require('gulp-ssg');
gulp.task('html', function() {
return gulp.src('content/**/*.html')
.pipe(ssg())
.pipe(gulp.dest('public/'));
});
This will add properties to each file's data
property:
file.data.url
- A URL, which is the file.relative
with a slash prepended and any trailing index.*
removedfile.data.dirtyUrl
- As above, but without trailing index.*
removedfile.data.root
- A pointer to the root filefile.data.parent
- A pointer to the parent filefile.data.children
- An array of pointers to child filesfile.data.siblings
- An array of pointers to sibling filesTo explain these a bit more:
root
file is the root index.html
file. If there isn't one then root
will be null
.parent
file is the parent index.html
file. If there isn't one then parent
will be null
.children
are all the files that have a URL that starts with the current files path plus at least one more token in there path. Because index.html
is truncated from URLs this means /foo/bar/
and /foo/fred.html
are both children of /foo/index.html
.siblings
are all the files that have a common parent URL.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.
So how can this be used? It gets more interesting when combined with other pipes. For example:
var gulp = require('gulp');
var ssg = require('gulp-ssg');
var rename = require('gulp-rename');
var data = require('gulp-data');
var matter = require('gray-matter');
var markdown = require('gulp-markdown');
var wrap = require('gulp-wrap');
var del = require('del');
gulp.task('default', function() {
return gulp.src('src/content/*.md')
// Extract YAML front-matter and assign with gulp-data
.pipe(data(function(file) {
var m = matter(String(file.contents));
file.contents = new Buffer(m.content);
return m.data;
}))
// markdown -> HTML
.pipe(markdown())
// Rename to .html
.pipe(rename({ extname: '.html' }))
// Run through gulp-ssg
.pipe(ssg())
// Wrap file in template
.pipe(wrap(
{ src: 'src/templates/template.html' },
{ siteTitle: 'Example Website'},
{ engine: 'hogan' }
))
// Output to build directory
.pipe(gulp.dest('public/'));
});
There are complete examples with templates in the git repo.
string
The base URL of the site, defaults to '/'. This should be the path to where your site will eventually be deployed.
string
A property to sort pages by, defaults to url
. For example, this could be a property like order
extracted from the YAML front-matter.
FAQs
Generate a static website content tree
We found that gulp-ssg demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.