GithubHelp home page GithubHelp logo

straticjs / stratic-posts-to-index Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 48 KB

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

License: GNU Lesser General Public License v3.0

JavaScript 100.00%
gulp stratic javascript gulp-plugin hacktoberfest

stratic-posts-to-index's Introduction

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(straticPostsToIndex('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(straticPostsToIndex('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

AJ Jordan [email protected]

stratic-posts-to-index's People

Contributors

strugee avatar

Watchers

 avatar  avatar

stratic-posts-to-index's Issues

Allow no template

You really don't need a template for stratic-indexes-to-rss so we should probably let the user explicitly pass null or something to mean "just mangle the posts array and attach to a completely new file with no contents attribute"

Handle customized paths

I.e. with days, no months, etc.

This also includes setups which straight up don't use stratic-date-in-path.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.