├── .gitignore
├── assets
└── css
│ └── site.css
├── views
├── page.ejs
└── index.ejs
├── package.json
├── lib
├── yaml-indent-documents.js
├── page
│ ├── index.js
│ └── render.js
└── render.js
├── Gruntfile.js
└── test.js
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | /build
3 |
--------------------------------------------------------------------------------
/assets/css/site.css:
--------------------------------------------------------------------------------
1 | #content {
2 | width: 600px;
3 | }
4 |
5 | .highlight {
6 | border: 1px solid #ccc;
7 | background: #eee;
8 | padding: 0 0.5em;
9 | }
10 |
--------------------------------------------------------------------------------
/views/page.ejs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
Index
11 |
<%= meta.title %>
12 | <%- render('content') %>
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/views/index.ejs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
Index
11 | <% pages.forEach(function(page) { %>
12 | <%= dateformat(page.meta.date, 'mm/dd/yyyy') %>
<%= page.meta.title %>
13 | <% }) %>
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "benalman.com",
3 | "version": "0.1.0",
4 | "description": "Website?",
5 | "main": "index.js",
6 | "dependencies": {
7 | "github-flavored-markdown": "~1.0.1",
8 | "js-yaml": "~1.0.2",
9 | "gitteh": "~0.1.0",
10 | "ejs": "~0.8.3",
11 | "dateformat": "~1.0.2-1.2.3"
12 | },
13 | "devDependencies": {},
14 | "scripts": {
15 | "test": "grunt test"
16 | },
17 | "repository": "",
18 | "author": "",
19 | "license": "BSD"
20 | }
21 |
--------------------------------------------------------------------------------
/lib/yaml-indent-documents.js:
--------------------------------------------------------------------------------
1 | /*
2 | * yaml-literal-hack
3 | *
4 | * Copyright (c) 2012 "Cowboy" Ben Alman
5 | * Licensed under the MIT license.
6 | * http://benalman.com/about/license/
7 | */
8 |
9 | 'use strict';
10 |
11 | var fs = require('fs');
12 |
13 | var yaml = module.exports = require('js-yaml');
14 |
15 | // https://github.com/nodeca/js-yaml/issues/53
16 | var hack = function(src) {
17 | return String(src).split(/^\-{3}/gm).map(function(s) {
18 | var matches = s.match(/^\s+([\|\^].*?)\n([\s\S]*?)\n$/);
19 | if (!matches) { return s; }
20 | var literal = matches[1];
21 | var indented = matches[2].split('\n').map(function(s) {
22 | return ' ' + s;
23 | }).join('\n');
24 | return '\n__LITERALLY_AWESOME__: ' + literal + '\n' + indented + '\n';
25 | }).join('---');
26 | };
27 |
28 | var unhack = function(docs) {
29 | return docs.map(function(doc) {
30 | return doc && doc.__LITERALLY_AWESOME__ || doc;
31 | });
32 | };
33 |
34 | // This seems to do what I want it to.
35 | yaml.parseDocs = function(src) {
36 | var docs = [];
37 | yaml.loadAll(hack(src), function(doc) {
38 | docs.push(doc);
39 | });
40 | return unhack(docs);
41 | };
42 |
43 | // So does this.
44 | yaml.parseDocsFile = function(filepath) {
45 | return yaml.parseDocs(fs.readFileSync(filepath));
46 | };
47 |
--------------------------------------------------------------------------------
/Gruntfile.js:
--------------------------------------------------------------------------------
1 | /*
2 | * a new benalman.com, maybe
3 | *
4 | * Copyright (c) 2012 "Cowboy" Ben Alman
5 | * Licensed under the MIT license.
6 | * http://benalman.com/about/license/
7 | */
8 |
9 | 'use strict';
10 |
11 | module.exports = function(grunt) {
12 |
13 | // Project configuration.
14 | grunt.initConfig({
15 | // Task configuration.
16 | jshint: {
17 | options: {
18 | curly: true,
19 | eqeqeq: true,
20 | immed: true,
21 | latedef: true,
22 | newcap: true,
23 | noarg: true,
24 | sub: true,
25 | undef: true,
26 | unused: true,
27 | boss: true,
28 | eqnull: true,
29 | es5: true,
30 | node: true,
31 | },
32 | gruntfile: {
33 | src: 'Gruntfile.js'
34 | },
35 | lib_test: {
36 | src: ['lib/**/*.js', 'test/**/*.js']
37 | }
38 | },
39 | nodeunit: {
40 | files: ['test/**/*.js']
41 | },
42 | watch: {
43 | gruntfile: {
44 | files: '<%= jshint.gruntfile.src %>',
45 | tasks: ['jshint:gruntfile']
46 | },
47 | lib_test: {
48 | files: '<%= jshint.lib_test.src %>',
49 | tasks: ['jshint:lib_test', 'nodeunit']
50 | }
51 | }
52 | });
53 |
54 | // Default task.
55 | grunt.registerTask('default', ['jshint', 'nodeunit']);
56 |
57 | };
58 |
--------------------------------------------------------------------------------
/test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * a new benalman.com, maybe
3 | *
4 | * Copyright (c) 2012 "Cowboy" Ben Alman
5 | * Licensed under the MIT license.
6 | * http://benalman.com/about/license/
7 | */
8 |
9 | 'use strict';
10 |
11 | var fs = require('fs');
12 | var path = require('path');
13 |
14 | var ejs = require('ejs');
15 | var dateformat = require('dateformat');
16 |
17 | var Index = require('./lib/page/index').Index;
18 |
19 | var src = '../benalman.com-content/new';
20 | var indices = fs.readdirSync(src).map(function(dirname) {
21 | // console.log(dirname);
22 | var abspath = path.resolve(src, dirname, 'index.md');
23 | var index = new Index(abspath);
24 | var dest = path.resolve('./build', dirname + '.html');
25 |
26 | var options = Object.create(index);
27 | options.filename = './views/page.js';
28 | var html = ejs.render('<% include page %>', options);
29 | fs.writeFileSync(dest, html);
30 |
31 | return {href: dirname + '.html', meta: index.meta};
32 | }).reverse();
33 |
34 | var options = {
35 | dateformat: dateformat,
36 | pages: indices,
37 | filename: './views/index.js'
38 | };
39 | var html = ejs.render('<% include index %>', options);
40 | fs.writeFileSync('build/index.html', html);
41 |
42 | // // var page = page.create('../benalman.com-content/new/jquery-throttle-debounce');
43 | // var page = page.create('../benalman.com-content/new/iife');
44 | // // var page = page.create('./new/');
45 |
46 | // console.log(page.index);
47 | // //console.log(page.documents);
48 | // console.log(page.meta);
49 | // console.log('title', page.meta.title);
50 | // console.log('tags', page.meta.tags);
51 | // page.meta.foo = 123;
52 | // console.log('foo', page.meta.foo);
53 |
54 | // var options = Object.create(page);
55 | // options.filename = './views/page.js';
56 | // var html = ejs.render('<% include page %>', options);
57 | // // console.log(html);
58 |
59 | // fs.writeFileSync('out.html', html);
60 |
--------------------------------------------------------------------------------
/lib/page/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * a new benalman.com, maybe
3 | *
4 | * Copyright (c) 2012 "Cowboy" Ben Alman
5 | * Licensed under the MIT license.
6 | * http://benalman.com/about/license/
7 | */
8 |
9 | 'use strict';
10 |
11 | var path = require('path');
12 | var yaml = require('../yaml-indent-documents');
13 | var render = require('./render');
14 |
15 | var Index = exports.Index = function(indexfile) {
16 | this.indexfile = path.resolve(indexfile);
17 | this.basepath = path.dirname(this.indexfile);
18 | };
19 |
20 | Index.prototype.toString = function() {
21 | return '<