npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

stratic-posts-to-index

v2.1.0

Published

Prepare Vinyl files with indexes of a stream of Stratic posts

Downloads

8

Readme

stratic-posts-to-index

Gulp plugin to prepare Vinyl files with indexes of a stream of Stratic posts

Installation

npm install stratic-posts-to-index

Example

Minimal example:

var gulp = require('gulp');
var frontMatter = require('gulp-gray-matter');
var straticPostsToIndex = require('stratic-posts-to-index');
var addsrc = require('gulp-add-src');
var straticDateInPath = require('stratic-date-in-path');

gulp.task('post-index', function() {
	return gulp.src('*.md')
	           .pipe(frontMatter())
	           .pipe(straticDateInPath())
	           .pipe(addsrc('src/blog/index.jade'))
	           .pipe(postsToIndex('index.jade'))
});

Full example:

var gulp = require('gulp');
var remark = require('gulp-remark');
var remarkHtml = require('remark-html');
var frontMatter = require('gulp-gray-matter');
var straticPostsToIndex = require('stratic-posts-to-index');
var addsrc = require('gulp-add-src');
var jade = require('gulp-jade');
var straticDateInPath = require('stratic-date-in-path');
var rename = require('gulp-rename');

gulp.task('post-index', function() {
	return gulp.src('*.md')
	           .pipe(frontMatter())
	           .pipe(remark().use(remarkHtml))
	           .pipe(straticDateInPath())
	           .pipe(addsrc('index.jade'))
	           .pipe(postsToIndex('index.jade'))
	           .pipe(jade({basedir: __dirname}))
	           .pipe(rename({ extname: '.html' }))
	           .pipe(gulp.dest('dist'));
});

What's happening here? First we read in the Stratic posts from disk, render them as Markdown, and put the date in their path. Then we add index.jade into the stream of files. index.jade is what will be used for the template.

When we pipe all the files to postsToIndex, we pass it the name of the template file. From there, stratic-posts-to-index will output copies of this template, one for each index page. See "Locals" below for information on the locals that are provided to the template.

The rest is just standard Gulp: we render the Jade, rename the templates to .html files, and write to the dist directory.

Locals

Each template file gets some information as an object in its data attribute. Most template system plugins will use this object as locals for the template being rendered.

posts (Array) - the posts that should be included in that particular index, presorted in reverse-chronological order

indexType (String) - the type of index this is. The value will be one of main, year, month, or category.

includedYears (Array) - years that the posts included in the index were authored in (set for main indexes)

includedMonths (Array) - months that the posts included in the index were authored in (set for main and year indexes)

includedCategories (Array) - categories that the posts included in the index were categorized as (set for main, year and month indexes)

year (Number) - the year that the index is for (set for year and month indexes)

month (Number) - the (zero-based) month that the index is for (set for month indexes)

category (String) - the category that the index is for (set for category indexes)

Code of Conduct

Please note that StraticJS is developed under the Contributor Covenant Code of Conduct. Project contributors are expected to respect these terms.

For the full Code of Conduct, see CODE_OF_CONDUCT.md. Violations may be reported to [email protected].

License

LGPL 3.0+

Author

Alex Jordan [email protected]