Skip to content

Commit 23295fd

Browse files
committed
Initial commit
Based on `yo stratic`.
0 parents  commit 23295fd

File tree

14 files changed

+342
-0
lines changed

14 files changed

+342
-0
lines changed

.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false

.gitignore

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Logs
2+
logs
3+
*.log
4+
5+
# Runtime data
6+
pids
7+
*.pid
8+
*.seed
9+
10+
# Directory for instrumented libs generated by jscoverage/JSCover
11+
lib-cov
12+
13+
# Coverage directory used by tools like istanbul
14+
coverage
15+
16+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17+
.grunt
18+
19+
# node-waf configuration
20+
.lock-wscript
21+
22+
# Compiled binary addons (http://nodejs.org/api/addons.html)
23+
build/Release
24+
25+
# Dependency directory
26+
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
27+
node_modules
28+
29+
# Debug log from npm
30+
npm-debug.log

.jshintrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"node": true
3+
}

gulpfile.js

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
'use strict';
2+
3+
var gulp = require('gulp'),
4+
gutil = require('gulp-util'),
5+
plumber = require('gulp-plumber'),
6+
pug = require('gulp-pug'),
7+
stylus = require('gulp-stylus'),
8+
rename = require('gulp-rename'),
9+
remark = require('gulp-remark'),
10+
frontMatter = require('gulp-gray-matter'),
11+
remarkHtml = require('remark-html'),
12+
attachToTemplate = require('gulp-attach-to-template'),
13+
filterDrafts = require('stratic-filter-drafts'),
14+
dateInPath = require('stratic-date-in-path'),
15+
postsToIndex = require('stratic-posts-to-index'),
16+
paginateIndexes = require('stratic-paginate-indexes'),
17+
indexesToRss = require('stratic-indexes-to-rss'),
18+
addsrc = require('gulp-add-src'),
19+
ecstatic = require('ecstatic'),
20+
ghpages = require('gh-pages'),
21+
path = require('path'),
22+
http = require('http'),
23+
through2 = require('through2'),
24+
isDist = process.argv.indexOf('serve') === -1;
25+
26+
gulp.task('build', ['build:html', 'build:css', 'build:js', 'build:blog']);
27+
gulp.task('build:blog', ['build:blog:posts', 'build:blog:index', 'build:blog:rss']);
28+
29+
gulp.task('build:html', function() {
30+
return gulp.src('src/*.pug')
31+
.pipe(isDist ? through2.obj() : plumber())
32+
.pipe(pug({ pretty: true, basedir: __dirname }))
33+
.pipe(rename({ extname: '.html' }))
34+
.pipe(gulp.dest('dist'));
35+
});
36+
37+
gulp.task('build:blog:posts', function() {
38+
return gulp.src('src/blog/*.md')
39+
.pipe(isDist ? through2.obj() : plumber())
40+
.pipe(frontMatter())
41+
.pipe(filterDrafts())
42+
.pipe(remark({quiet: true}).use(remarkHtml))
43+
.pipe(dateInPath())
44+
.pipe(addsrc('src/blog/post.pug'))
45+
.pipe(attachToTemplate('post.pug'))
46+
.pipe(pug({ pretty: true, basedir: __dirname }))
47+
.pipe(rename({ extname: '.html' }))
48+
.pipe(gulp.dest('dist/blog'));
49+
});
50+
51+
gulp.task('build:blog:index', function() {
52+
return gulp.src('src/blog/*.md')
53+
.pipe(isDist ? through2.obj() : plumber())
54+
.pipe(frontMatter())
55+
.pipe(filterDrafts())
56+
.pipe(remark({quiet: true}).use(remarkHtml))
57+
.pipe(dateInPath())
58+
.pipe(addsrc('src/blog/index.pug'))
59+
.pipe(postsToIndex('index.pug'))
60+
.pipe(paginateIndexes())
61+
.pipe(pug({ pretty: true, basedir: __dirname }))
62+
.pipe(rename({ extname: '.html' }))
63+
.pipe(gulp.dest('dist/blog'));
64+
});
65+
66+
gulp.task('build:blog:rss', function() {
67+
return gulp.src('src/blog/*.md')
68+
.pipe(frontMatter())
69+
.pipe(filterDrafts())
70+
.pipe(remark({quiet: true}).use(remarkHtml))
71+
.pipe(dateInPath())
72+
.pipe(addsrc('src/blog/index.pug'))
73+
.pipe(postsToIndex('index.pug'))
74+
.pipe(indexesToRss({
75+
title: 'My personal blog'
76+
}, 'http://stratic.js.org/blog/'))
77+
.pipe(rename({ extname: '.rss' }))
78+
.pipe(gulp.dest('dist/blog'));
79+
});
80+
81+
gulp.task('build:css', function() {
82+
return gulp.src('src/styles/*.styl')
83+
.pipe(isDist ? through2.obj() : plumber())
84+
.pipe(stylus())
85+
.pipe(rename({ extname: '.css' }))
86+
.pipe(gulp.dest('dist/css'));
87+
});
88+
89+
gulp.task('build:js', function() {
90+
return gulp.src('src/scripts/*.js')
91+
.pipe(gulp.dest('dist/js'));
92+
93+
});
94+
95+
gulp.task('build:images', function() {
96+
return gulp.src('src/img/*')
97+
.pipe(gulp.dest('dist/img'));
98+
99+
});
100+
101+
gulp.task('deploy', ['build'], function(done) {
102+
ghpages.publish(path.join(__dirname, 'dist'), { logger: gutil.log, branch: 'master' }, done);
103+
});
104+
105+
gulp.task('serve', ['watch'], function() {
106+
http.createServer(
107+
ecstatic({ root: __dirname + '/dist' })
108+
).listen(process.env.PORT || 8080);
109+
});
110+
111+
gulp.task('watch', ['build'], function() {
112+
gulp.watch(['src/*.pug', 'src/includes/*.pug'], ['build:html', 'build:blog:posts', 'build:blog:index']);
113+
gulp.watch('src/styles/*.styl', ['build:css']);
114+
gulp.watch('src/scripts/*.js', ['build:js']);
115+
gulp.watch('src/blog/*.md', ['build:blog']);
116+
gulp.watch('src/blog/*.pug', ['build:blog:posts', 'build:blog:index']);
117+
});

package.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "package",
3+
"version": "0.0.0",
4+
"license": "CC-BY-SA-4.0",
5+
"dependencies": {},
6+
"devDependencies": {
7+
"ecstatic": "^2.1.0",
8+
"gh-pages": "^0.12.0",
9+
"gulp": "^3.9.1",
10+
"gulp-add-src": "^0.2.0",
11+
"gulp-attach-to-template": "^1.0.0",
12+
"gulp-gray-matter": "^3.0.1",
13+
"gulp-pug": "^3.3.0",
14+
"gulp-plumber": "^1.1.0",
15+
"gulp-remark": "^4.0.1",
16+
"gulp-rename": "^1.2.2",
17+
"gulp-stylus": "^2.6.0",
18+
"gulp-util": "^3.0.8",
19+
"remark-html": "^6.0.0",
20+
"stratic-date-in-path": "^3.0.0",
21+
"stratic-filter-drafts": "^1.0.0",
22+
"stratic-indexes-to-rss": "^1.0.0",
23+
"stratic-paginate-indexes": "^1.0.1",
24+
"stratic-posts-to-index": "^2.0.0",
25+
"through2": "^2.0.3"
26+
}
27+
}

src/blog/hello-world.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: "Hello, World!"
3+
time:
4+
epoch: 1499578388
5+
utcoffset: "UTC-0"
6+
author: "Jane Doe"
7+
categories:
8+
- example
9+
---
10+
11+
This is your first blog post! Edit it, delete it, or do whatever you want with it! (Note, also, that the filename becomes the URL slug.)

src/blog/index.pug

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
extends /src/includes/layout.pug
2+
3+
include /src/includes/post.pug
4+
5+
block head
6+
if indexType === 'main'
7+
title Blog - StraticJS
8+
else if indexType === 'year'
9+
title Posts from #{year} - StraticJS
10+
else if indexType === 'month'
11+
- var monthName = new Date(1970, month).toLocaleString('en-us', {month: 'long'});
12+
title Posts from #{monthName + ' ' + year} - StraticJS
13+
else if indexType === 'category'
14+
title Posts categorized as "#{category}" - StraticJS
15+
16+
block content
17+
.h-feed
18+
//- Index title
19+
if indexType === 'main'
20+
h2.p-name Blog
21+
p#postsFrom Show only posts from
22+
each year in includedYears
23+
a(href='/blog/' + year + '/')= year
24+
|
25+
else if indexType === 'year'
26+
h2.p-name Posts from #{year}
27+
p#postsFrom Show only posts from
28+
each month in includedMonths
29+
- var monthName = new Date(1970, month).toLocaleString('en-us', {month: 'long'});
30+
- var monthStr = month + 1;
31+
- monthStr = monthStr < 10 ? '0' + monthStr.toString() : monthStr.toString();
32+
a(href='/blog/' + year + '/' + monthStr + '/')= monthName
33+
|
34+
else if indexType === 'month'
35+
- var monthName = new Date(1970, month).toLocaleString('en-us', {month: 'long'});
36+
h2.p-name Posts from #{monthName + ' ' + year}
37+
else if indexType === 'category'
38+
h2.p-name Posts categorized as "#{category}"
39+
40+
//- Posts
41+
each post, index in posts
42+
+renderPost(post, true)
43+
44+
if index < posts.length - 1
45+
hr
46+
47+
hr
48+
49+
//- Pages
50+
- function pageUrl(cur, next) {
51+
- if (cur === 2 && next === -1) return '../..';
52+
- return '../' + (cur + next);
53+
- }
54+
55+
#pages-footer
56+
if pageCount !== 1
57+
if page === 1
58+
p
59+
span.disabled-arrow
60+
| ⋅ Page #{page} out of #{pageCount}
61+
a(href='page/2')
62+
else if page === pageCount
63+
p
64+
a(href=pageUrl(page, -1))
65+
| ⋅ Page #{page} out of #{pageCount}
66+
span.disabled-arrow
67+
else
68+
p
69+
a(href=pageUrl(page, -1))
70+
| ⋅ Page #{page} out of #{pageCount}
71+
a(href=pageUrl(page, 1))
72+
else
73+
p Page 1 of 1

src/blog/post.pug

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
extends /src/includes/layout.pug
2+
3+
include /src/includes/post.pug
4+
5+
block head
6+
title #{file.data.title} - StraticJS
7+
8+
block content
9+
+renderPost(file, false)

src/images/.gitkeep

Whitespace-only changes.

src/includes/layout.pug

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
doctype html
2+
html
3+
head
4+
meta(charset='utf-8')
5+
meta(name='viewport', content='width=device-width, initial-scale=1, maximum-scale=1')
6+
link(rel='stylesheet', type='text/css', href='css/main.css')
7+
block head
8+
9+
body
10+
block content

src/includes/post.pug

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
mixin renderPost(post, isIndex)
2+
article.h-entry
3+
//- Title
4+
if isIndex
5+
a(href='/blog/' + post.relative.replace('.md', ''))
6+
h2.p-name= post.data.title
7+
else
8+
h1.p-name= post.data.title
9+
10+
//- Metadata
11+
- var author = post.data.author;
12+
- var time = post.data.time;
13+
- var categories = post.data.categories;
14+
- var date = new Date(time.epoch * 1000);
15+
- var monthName = date.toLocaleString('en-us', {month: 'long'});
16+
- var monthStr = date.getMonth() + 1;
17+
- monthStr = monthStr < 10 ? '0' + monthStr.toString() : monthStr.toString();
18+
p Published by #[span.p-author.h-card= author] on
19+
a(href='/blog/'+date.getFullYear()+'/'+monthStr+'/')= monthName
20+
| #{date.getDate()},
21+
a(href='/blog/'+date.getFullYear()+'/')= date.getFullYear()
22+
| in
23+
for category, index in categories
24+
a.p-category(href='/blog/category/' + category + '/') #{category}
25+
if index < categories.length - 2
26+
| ,
27+
else if index === categories.length - 2
28+
| and
29+
30+
//- Post content
31+
.e-content!= post.contents.toString()

src/index.pug

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
extends /src/includes/layout.pug
2+
3+
4+
5+
block head
6+
title StraticJS
7+
8+
block content
9+
h1 StraticJS
10+
p Welcome to your new website!
11+
p You can hack on your HTML using #[a(href='https://pugjs.org') Pug], you can write CSS in #[a(href='http://stylus-lang.com') Stylus], and you can write scripts in JavaScript!
12+
13+
14+
p Also, check out #[a(href='/blog/2017/07/hello-world') Hello World] on your brand-new #[a(href='/blog/') blog]!

src/scripts/main.js

Whitespace-only changes.

src/styles/main.styl

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// You can write Stylus styles here!
2+
// Stylus is like a good-lookin' superset of CSS with superpowers.
3+
// See http://stylus-lang.com
4+
5+

0 commit comments

Comments
 (0)