DocPad (like Jekyll) is a static website generator, unlike Jekyll it's written in CoffeeScript+Node.js instead of Ruby, and also allows the template engine complete access to the document model. This means you have unlimited power as a CMS and the simplicity of a notepad.
-
Say you were to create the following website structure:
- myWebsite - src - documents - files - layouts
-
And you were to create the following files:
-
A layout at
src/layouts/default.html
, which contains<html> <head><title><%[email protected]%></title></head> <body> <%-@content%> </body> </html>
-
And a layout at
src/layouts/post.html
, which contains:--- layout: default --- <h1><%[email protected]%></h1> <div><%-@content%></div>
-
And a document at
src/documents/posts/hello.md
, which contains:--- layout: post title: Hello World! --- Hello **World!**
-
-
Then when you generate your website with docpad you will get a html file at
out/posts/hello.html
, which contains:<html> <head><title>Hello World!</title></head> <body> <h1>Hello World!</h1> <div>Hello <strong>World!</strong></div> </body> </html>
-
And any files that you have in
src/files
will be copied to theout
directory. E.g.src/files/styles/style.css
->out/styles/style.css
-
Allowing you to easily generate a website which only changes (and automatically updates) when a document changes (which when you think about it; is the majority of websites)
-
Cool, now what was with the
<%=...%>
and<%-...%>
parts which were substituted away?-
This is possible because we parse the documents and layouts through a template rendering engine. The template rendering engine we use is Eco which allows you to do some pretty nifty things. In fact we can display the all titles and links of our posts with the following html:
<% for Document in @Documents: %> <% if Document.url.indexOf('/posts') is 0: %> <a href="<%= Document.url %>"><%= Document.title %></a><br/> <% end %> <% end %>
-
-
Cool that makes sense... now how did
Hello **World!**
in our document get converted intoHello <strong>World!</strong>
?- That was possible as that file was a Markdown file (i.e. it had the
.md
extension). Markdown is a great markup language as with it you have an extremely simple and readable document which generates a rich semantic HTML document. DocPad also supports a series of other markup languages which are listed later on.
- That was possible as that file was a Markdown file (i.e. it had the
-
Install CoffeeScript
npm -g install coffee-script
-
Install DocPad
npm -g install docpad
-
To generate the rendered website, watch the files for changes, and run the docpad server
docpad
-
To generate a basic website structure in the current working directory
docpad skeleton
-
To regenerate the rendered website
docpad generate
-
To regenerate the rendered website automatically whenever we make a change to a file
docpad watch
-
To run the docpad server which allows you to access the generated website in a web browser
docpad server
- Node.js - Server Side Javascript
- Express.js - The "Server" in Server Side Javascript
- Query-Engine - The MongoDB Query-Engine without the Database
- CoffeeScript - JavaScript Made Easy
- Async - Asynchrounous Programming Made Easy
- Eco - Templating Made Easy
To learn more about DocPad (including using and extending it) visit its wiki here
-
v0.9 July 6, 2011
- No longer uses MongoDB/Mongoose! We now use Query-Engine which doesn't need any database server :)
- Watching files now working even better
- Now supports clean urls :)
-
v0.8 May 23, 2011
- Now supports mutliple skeletons
- Structure changes
-
v0.7 May 20, 2011
- Now supports multiple docpad instances
-
v0.6 May 12, 2011
- Moved to CoffeeScript
- Removed highlight.js (should be a plugin or client-side feature)
-
v0.5 May 9, 2011
- Pretty big clean
-
v0.4 May 9, 2011
- The CLI is now working as documented
-
v0.3 May 7, 2011
- Got the generation and server going
-
v0.2 March 24, 2011
- Prototyping with disenchant
-
v0.1 March 16, 2011
- Initial commit with bergie
Licensed under the MIT License Copyright 2011 Benjamin Arthur Lupton