Pages

Wednesday, 23 October 2013

在linux vps上搭建基于nodejs的静态博客程序-romulus

as3:~# npm install -g romulus
as3:~# mkdir romulus-site
as3:~# cd romulus-site
as3:~/romulus-site# ls
as3:~/romulus-site# mkdir pages layouts public
as3:~/romulus-site# ls
layouts  pages  public
as3:~/romulus-site# nano pages/index.html
as3:~/romulus-site# romulus build
You static empire was built in "/root/romulus-site/build" (took 10 ms)
as3:~/romulus-site# ls
build  layouts  pages  public (新生成的build目录就是静态网站的根目录)
as3:~/romulus-site# cd build
as3:~/romulus-site/build# ls
index.html
as3:~/romulus-site/build# nohup Rwebserver 8983 > /dev/null &
[2] 32156
as3:~/romulus-site/build# nohup: ignoring input and redirecting stderr to stdout
as3:~/romulus-site/build#

演示站点:http://as3.brite.biz:8983/ (这也只是个初步框架,还需自己设计模板)

补充说明:
Layouts
In order to make this more interesting, let's say you want to wrap your new page in a fancy

layout. To do this you need to change your pages/index.html file like this:

<% this.layout = 'default' %>
<p>Hello World</p>

Now you need to create the layout itself, so add a file called layouts/default.html:

<!doctype html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>My static empire</title>

    <!-- Can be a plain css file or rendered from less, continue reading -->
    <link rel="stylesheet" type="text/css" href="/css/main.css" />
    <!-- You can include any JS / CSS files, main.js / main.css are just examples -->
    <script src="/js/main.js"></script>
  </head>
  <body>
    <h1>My Header</h1>
    <%- page %>
  </body>
</html>

That's it, you should now see your page being rendered inside your template!
Accessing page variables in your layout

Let's say you want to set a title variable in your page that should be used by the layout. For

this, add this to your page template:

<% this.title = 'My title'; %>

And output it in your layout like this:

<title><%= this.title %></title>

Generating css from less files

Now that you have this wonderful site, you probably want to style it. To do so, create a file

called public/css/main.less:

body{
  h1{
    color: #0080FF;
  }
}

Sweet, your headline is now featuring my favorite color!

Static file support
Any file placed in the public folder will be included at the top level of the build output

folder. The local development server also supports serving them.
Using markdown

romulus natively supports github flavored markdown( https://github.com/isaacs/github-flavored-

markdown) for page files. Using markdown is as easy as creating a file with a .md extension like

pages/markdown-rocks.md and adding some markdown to it:

<% this.layout = 'default'; %>

Markdown is **fun**, and you can still use EJS inside of your markdown
templates.

This page now will be served at /markdown-rocks.

Deploying to github pages
Deploying to github pages is as simple as:
romulus deploy

This should work well for project pages, but has not been tested for organization pages yet.
from https://github.com/felixge/node-romulus