Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added a built-in tags page, and a postsForTag helper

  • Loading branch information...
commit 07b85062f0d4143a399da18f6be6cf64fbab8c1d 1 parent b22a7f9
Alex Young authored
View
1  TODO.textile
@@ -1,6 +1,5 @@
h3. Features
-* Build-in tag page generator
* nib (to make it easier to share styles?)
* Mock filesystem for tests so I don't need to write to /tmp
* Make template language configurable, default to jade
View
2  lib/assets/default.jade
@@ -5,6 +5,8 @@ html(lang="en")
link(href="/stylesheets/screen.css", media="screen", rel="stylesheet", type="text/css")
link(rel="alternate", type="application/rss+xml", title="RSS 2.0", href="/feed.rss")
link(rel="alternate", type="application/atom+xml", title="Atom Feed", href="/feed.xml")
+ script(type="text/javascript", src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js")
+ script(type="text/javascript", src="/javascripts/site.js")
body
header#header
hgroup
View
6 lib/assets/screen.styl
@@ -145,6 +145,12 @@ article time, article .author, article .tags
text-decoration: none
color: dark
+.tag-list h2, p
+ margin: 10px 0
+
+.tag-list .posts
+ display: none
+
article time
margin-left: 20px
View
5 lib/assets/site.js
@@ -0,0 +1,5 @@
+$(function() {
+ $('.tag-list a.tag').live('click', function() {
+ $(this).parents('h2').next('.posts').toggle();
+ });
+});
View
17 lib/assets/tags.jade
@@ -0,0 +1,17 @@
+---
+layout: default
+---
+
+h1 Tags
+
+p Click a tag to view the associated posts.
+
+.tag-list
+ - var tags = allTags();
+ - if (tags && tags.length > 0)
+ - for (var i = 0, tag = tags[0], posts = postsForTag(tag); i < tags.length; i++, tag = tags[i], posts = postsForTag(tag))
+ h2
+ a.tag(href="#") (#{posts.length}) #{tag}
+ .posts
+ - for (var j = 0, post = posts[j]; j < posts.length; j++, post = posts[j])
+ p #{post.title}
View
18 lib/cli_tools.js
@@ -127,6 +127,24 @@ module.exports = {
},
/**
+ * Default client-side JavaScript.
+ *
+ * @return {String}
+ */
+ defaultClientJavaScript: function() {
+ return fs.readFileSync(__dirname + '/assets/site.js');
+ },
+
+ /**
+ * Default tags page.
+ *
+ * @return {String}
+ */
+ defaultTags: function() {
+ return fs.readFileSync(__dirname + '/assets/tags.jade');
+ },
+
+ /**
* Sample post, to get people started.
*
* @return {String}
View
4 lib/generators/default.js
@@ -4,7 +4,7 @@ var fs = require('fs')
var generator = {
run: function(helpers, pathName, fn) {
- var paths = ['_posts', '_lib', '_layouts', '_includes', 'stylesheets']
+ var paths = ['_posts', '_lib', '_layouts', '_includes', 'stylesheets', 'javascripts']
, postFileName = helpers.getPostFileName('/:year/:month/:day/:title', new Date(), 'Example Post About Something', 'md');
fs.mkdirSync(pathName, 0777);
@@ -17,6 +17,8 @@ var generator = {
fs.writeFileSync(path.join(pathName, '_layouts', 'default.jade'), helpers.defaultLayout());
fs.writeFileSync(path.join(pathName, '_layouts', 'post.jade'), helpers.defaultPostLayout());
fs.writeFileSync(path.join(pathName, 'stylesheets', 'screen.styl'), helpers.defaultStylus());
+ fs.writeFileSync(path.join(pathName, 'javascripts', 'site.js'), helpers.defaultClientJavaScript());
+ fs.writeFileSync(path.join(pathName, 'tags.jade'), helpers.defaultTags());
fs.writeFileSync(path.join(pathName, postFileName), helpers.samplePost());
log.info('Site created:', pathName);
View
16 lib/helpers.js
@@ -203,6 +203,22 @@ helpers = {
},
/**
+ * Get a set of posts for a tag.
+ *
+ * @param {String} Tag name
+ * @return {Array}
+ */
+ postsForTag: function(tag) {
+ var posts = [];
+ for (var key in this.posts) {
+ if (this.posts[key].tags && this.posts[key].tags.indexOf(tag) !== -1) {
+ posts.push(this.posts[key]);
+ }
+ }
+ return posts;
+ },
+
+ /**
* Display a list of tags.
*
* TODO: Link options
View
2  package.json
@@ -1,6 +1,6 @@
{ "name": "pop"
, "description": "A static website and blog generator"
-, "version": "0.0.9"
+, "version": "0.1.0"
, "url": "http://popjs.com"
, "author": "Alex R. Young <alex@helicoid.net>"
, "engines": ["node >= 0.4.7"]
Please sign in to comment.
Something went wrong with that request. Please try again.