Permalink
Browse files

redo as a new static site

  • Loading branch information...
1 parent ecd6ea7 commit e962d6157611988a416019858c1edd386cf2cdcc @maxogden maxogden committed with Mar 14, 2014
View
@@ -0,0 +1 @@
+.DS_Store
View
@@ -1,64 +0,0 @@
-var EventEmitter = require('events').EventEmitter;
-var hyperglue = require('hyperglue');
-
-var html = require('./html/article.js');
-var catchLinks = require('catch-links');
-
-module.exports = Article;
-
-function Article (target) {
- if (!(this instanceof Article)) return new Article(target);
- this.target = target;
- this.articles = [];
- this.name = 'articles';
-}
-
-Article.prototype = new EventEmitter;
-
-Article.prototype.push = function (doc) {
- var self = this;
- var name = doc.title.replace(/[^A-Za-z0-9]+/g, '_');
-
- var div = hyperglue(html, {
- '.title a' : {
- name : name,
- href : '/' + name,
- _text : doc.title
- },
- '.commit' : doc.commit,
- '.author' : doc.author,
- '.date' : doc.date,
- '.body' : { _html : doc.body }
- });
- if (self.name === 'articles') {
- div.style.display = 'block';
- div.className = 'article summary';
- }
- else {
- div.style.display = name === self.name ? 'block' : 'none';
- }
- catchLinks(div, function (href) {
- self.emit('link', href);
- });
-
- self.articles.push({ name : name, element : div, doc : doc });
- self.target.appendChild(div);
-};
-
-Article.prototype.show = function (href) {
- var name = href.replace(/^\//, '');
- this.name = name;
-
- for (var i = 0; i < this.articles.length; i++) {
- var article = this.articles[i];
- if (name === 'articles') {
- article.element.style.display = 'block';
- article.element.className = 'article summary';
- }
- else {
- var d = name === article.name ? 'block' : 'none';
- article.element.style.display = d;
- article.element.className = 'article';
- }
- }
-};
@@ -1,25 +0,0 @@
-module.exports = [
- '<div class="article">',
- '<div class="title">',
- '<a name="name"></a>',
- '</div>',
- '<div class="inner">',
- '<div class="headers">',
- '<div class="header">',
- '<div class="key">commit</div>',
- '<div class="value commit"></div>',
- '</div>',
- '<div class="header">',
- '<div class="key">Author:</div>',
- '<div class="value author"></div>',
- '</div>',
- '<div class="header">',
- '<div class="key">Date:</div>',
- '<div class="value date"></div>',
- '</div>',
- '</div>',
- '<div class="body"></div>',
- '<div class="fade"></div>',
- '</div>',
- '</div>'
-].join('\n')
@@ -1,18 +0,0 @@
-module.exports = [
- '<div class="preview">',
- '<div class="label">',
- 'browserify articles',
- '</div>',
- '<div class="inner">',
- '<div class="image"></div>',
- '<div class="title">',
- '<a></a>',
- '<span class="index"></span>',
- '</div>',
- '<div class="arrows">',
- '<div class="left arrow"></div>',
- '<div class="right arrow"></div>',
- '</div>',
- '</div>',
- '</div>'
-].join('\n');
@@ -1,27 +0,0 @@
-module.exports = [
- '<div class="result">',
- '<div class="icons">',
- '<a class="featured">',
- '<img src="/images/star.png">',
- '</a>',
- '<a class="github">',
- '<img src="/images/octocat.png">',
- '</a>',
- '<a class="npm">',
- '<img src="/images/npm.png">',
- '</a>',
- '</div>',
- '<div class="inner">',
- '<div class="middle">',
- '<div class="name">',
- '<a></a>',
- '</div>',
- '<div class="description"></div>',
- '<div class="keywords"></div>',
- '</div>',
- '<div class="badge">',
- '<a><img></a>',
- '</div>',
- '</div>',
- '</div>'
-].join('\n');
View
@@ -1,58 +0,0 @@
-var JSONStream = require('JSONStream');
-var http = require('http');
-
-var divs = {
- splash : document.querySelector('#splash'),
- articles : document.querySelector('#articles'),
- articleBox : document.querySelector('#article-box'),
- previews : document.querySelector('#previews'),
- previewBox : document.querySelector('#preview-box'),
- search : document.querySelector('#search')
-};
-
-var articles = require('./article')(divs.articles);
-var previews = require('./preview')(divs.previews);
-var search = require('./search')(divs.search);
-
-http.get({ path : '/blog.json?inline=html' }, function (res) {
- var parser = JSONStream.parse([ true ]);
-
- parser.on('data', function (doc) {
- articles.push(doc);
- previews.push(doc);
- });
-
- res.pipe(parser);
-});
-
-var singlePage = require('single-page');
-var showPage = singlePage(function (href, page) {
- hide(divs.articleBox);
- hide(divs.search);
- hide(divs.splash);
- show(divs.previewBox);
-
- if (href === '/') {
- show(divs.splash);
- }
- else if (href === '/search') {
- hide(divs.previewBox);
- show(divs.search);
- search.focus();
- }
- else {
- show(divs.articleBox);
- articles.show(href);
- }
- process.nextTick(function () {
- window.scrollTo(page.scrollX, page.scrollY);
- });
-
- function hide (e) { e.style.display = 'none' }
- function show (e) { e.style.display = 'block' }
-});
-
-var catchLinks = require('catch-links');
-catchLinks(document, showPage);
-articles.on('link', showPage);
-previews.on('link', showPage);
View
@@ -1,68 +0,0 @@
-var EventEmitter = require('events').EventEmitter;
-var hyperglue = require('hyperglue');
-
-var catchLinks = require('catch-links');
-var html = require('./html/preview.js');
-
-module.exports = Preview;
-
-function Preview (target) {
- if (!(this instanceof Preview)) return new Preview(target);
- var self = this;
- self.target = target;
- self.length = 0;
-
- var iv = setInterval(interval, 5000);
- var ix = 0;
- function interval () {
- self.show(ix++ % self.length);
- }
-
- target.addEventListener('mouseover', function () {
- clearInterval(iv);
- iv = null;
- });
-
- target.addEventListener('mouseout', function () {
- if (!iv) iv = setInterval(interval, 5000);
- });
-}
-
-Preview.prototype = new EventEmitter;
-
-Preview.prototype.push = function (doc) {
- var self = this;
- var index = self.length ++;
- var div = hyperglue(html, {
- '.title a' : {
- href : '/' + doc.title.replace(/[^A-Za-z0-9]+/g, '_'),
- _text : doc.title
- },
- '.index' : '[' + index + ']'
- });
- if (self.length === 1) {
- div.className = 'preview active';
- }
- catchLinks(div, function (href) {
- self.emit('link', href);
- });
-
- var left = div.querySelector('.arrow.left');
- left.addEventListener('click', function () {
- self.show((index - 1 + self.length) % self.length);
- });
- var right = div.querySelector('.arrow.right');
- right.addEventListener('click', function () {
- self.show((index + 1) % self.length);
- });
-
- self.target.appendChild(div);
-};
-
-Preview.prototype.show = function (ix) {
- var prev = this.target.querySelector('.preview.active');
- if (prev) prev.className = 'preview';
-
- var div = this.target.childNodes[ix++ % this.length];
- if (div) div.className = 'preview active';
-};
View
@@ -1,106 +0,0 @@
-module.exports = Search;
-
-var http = require('http');
-var JSONStream = require('JSONStream');
-var through = require('through');
-
-var hyperglue = require('hyperglue');
-var html = {
- result : require('./html/result')
-};
-
-function Search (target) {
- if (!(this instanceof Search)) return new Search(target);
- var elements = this.elements = {
- form: target.querySelector('form'),
- query: target.querySelector('.query'),
- results: target.querySelector('.results'),
- featured: target.querySelector('.results .featured'),
- testling: target.querySelector('.results .testling'),
- npm: target.querySelector('.results .npm')
- };
-
- this.elements.form.addEventListener('submit', function (ev) {
- ev.preventDefault();
-
- elements.testling.innerHTML = '';
- elements.npm.innerHTML = '';
- elements.featured.innerHTML = '';
- show(elements.results);
-
- var q = encodeURIComponent(elements.query.value);
- http.get({ path : '/search.json?query=' + q }, function (res) {
- if (!/^2../.test(res.statusCode)) {
- var err = '';
- res.on('data', function (buf) { err += buf });
- res.on('end', function () { onerror(err) });
- return;
- }
- res.on('error', onerror);
-
- var parser = JSONStream.parse([ true ]);
- parser.pipe(through(write, end));
- res.pipe(parser);
- });
- });
-
- function onerror (err) {
- console.log('error: ' + err);
- }
-
- function write (pkg) {
- var div = hyperglue(html.result, {
- '.name a' : {
- href : 'https://npmjs.org/package/' + pkg.name,
- _text : pkg.name,
- },
- '.description' : pkg.description,
- '.github' : pkg.github ? { href : pkg.github } : {},
- '.npm' : { href : 'https://npmjs.org/package/' + pkg.name },
- '.featured' : pkg.article ? { href : pkg.article } : {},
- });
-
- if (pkg.testling) {
- hyperglue(div, {
- '.badge img' : {
- src : 'http://ci.testling.com/' + pkg.testling + '.png'
- },
- '.badge a' : {
- href : 'http://ci.testling.com/' + pkg.testling
- }
- });
- }
- else hide(div.querySelector('.badge img'))
-
- if (pkg.github) {
- show(div.querySelector('.github img'));
- }
- if (pkg.article) {
- show(div.querySelector('.featured img'));
- }
-
- if (pkg.article) {
- elements.featured.appendChild(div);
- }
- else if (pkg.testling) {
- elements.testling.appendChild(div);
- }
- else {
- elements.npm.appendChild(div);
- }
- }
-
- function end () {
- }
-}
-
-Search.prototype.focus = function () {
- this.elements.query.focus();
-};
-
-function hide (e) { e.style.display = 'none' }
-function show (e) {
- e.style.display = e.tagName === 'div'
- ? 'block' : 'inline'
- ;
-}
View
Binary file not shown.
Oops, something went wrong.

0 comments on commit e962d61

Please sign in to comment.