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-decorate-files

v2.0.0

Published

Decorate Stratic files with standard useful information

Downloads

6

Readme

stratic-decorate-files

Gulp plugin to decorate Stratic files with standard useful information

Installation

npm install stratic-decorate-files

Usage

To use this module, just pipe a stream of parsed Stratic posts into it. It's probably a bad idea to do this after you've added extra files into the stream, like e.g. templates.

Note: it's actually very important to use the values produced by this module. It's very easy to do, for example:

var date = new Date(post.data.time.epoch * 1000);
var month = date.getMonth();
// Etc.

but this is wrong because it doesn't take the UTC offset into account. If you rebuild your site in a different timezone, you may find that some posts - particularly those authored near the boundaries between days, months, or years - will now display a different timestamp.

This module will take care of handling the offset for you, so you don't have to worry about any of that. Plus, some of the values it provides (particularly monthName) are awkward to get with regular Date objects, so now you don't have to worry about that either.

See "Properties" below for the full list of properties this module provides.

Example

Minimal example:

var gulp = require('gulp');
var frontMatter = require('gulp-gray-matter');
var straticDecorateFiles = require('stratic-decorate-files');

gulp.task('post-index', function() {
	return gulp.src('*.md')
	           .pipe(frontMatter())
	           .pipe(straticDecorateFiles());
});

Full example:

var gulp = require('gulp');
var remark = require('gulp-remark');
var remarkHtml = require('remark-html');
var frontMatter = require('gulp-gray-matter');
var straticDecorateFiles = require('stratic-decorate-files');
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(straticDecorateFiles())
	           .pipe(addsrc('index.jade'))
	           .pipe(straticPostsToIndex('index.jade'))
	           .pipe(jade({basedir: __dirname}))
	           .pipe(rename({ extname: '.html' }))
	           .pipe(gulp.dest('dist'));
});

Properties

Each of these properties is attached to file.data.time; e.g. file.data.time.year for year. If file.data.edited is present, it also gets these properties attached.

moment (Object) - a MomentJS moment, preconfigured to handle the offset. Use this if what you need isn't already exposed.

year (Number) - the year the post was authored, as you would get from Date#getFullYear()

yearStr (String) - the year the post was authored, typecast to a string

month (Number) - the month the post was authored, as you would get from Date#getMonth() (i.e. zero-indexed)

monthName (String) - the name of the month the post was authored in; e.g. January

monthStr (String) - the month the post was authored in, made human-readable (i.e. 1 for January) and typecast to a string

monthUrlStr (String) - monthStr but with a 0 prepended if necessary to make the month two characters

dayOfMonth (Number) - the day of the month the post was authored, as you would get from Date#getDate()

dayOfMonthStr (String) - the day of the month the post was authored, typecast to a string

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

AJ Jordan [email protected]