fork(1) download
  1. #!/usr/bin/env ruby
  2. require 'cgi'
  3.  
  4. content = STDIN.read
  5.  
  6. parts = content.split(/^---\s*$/)
  7. page_title = parts[1].match(/^title:\s+(\!\s*)?["']?(.*?)["']?\s*$/i)[2].strip
  8.  
  9. parts.shift()
  10. parts.shift()
  11.  
  12. content = parts.join("\n---\n")
  13.  
  14. #content.gsub!("{{ page.title }}", page_title)
  15.  
  16. # Process geshi tags
  17. content.gsub!(/\{% geshi '(.*?)' (.*?) class='(.*?)' %\}(?:.*?\{%\- verbatim \-%\})?(.*?)(?:\{%\- endverbatim \-%\}.*?)?\{% endgeshi %\}/ms) {|q|
  18. codeblock = $4
  19. classes = "#{$1} #{$3}"
  20. "<pre><code class=\"#{classes}\">#{CGI.escapeHTML(codeblock)}</code></pre>"
  21. }
  22. puts content
Success #stdin #stdout 0.02s 7580KB
stdin
---
title: "Creating A Default Layout"
date: "2013-06-10 00:23"
layout: "article"
image_key: 'piecrust'
article:
    language: "PHP"
    topic: "PieCrust"
    series:
        title: "Moving to PieCrust"
        index: 5
---
# {{ page.title }}
Now that you have your site generated you can load it in your browser and you should see the default PieCrust site.  
 
<img src="{{ assets['default_site'] }}" class="floatcenter" />
 
You might be wondering how your site can be working since you have not created any
layouts or template files.  The reason it works is because it will default to the layouts and templates that are bundled with the PieCrust source code.  I'm sure you are ready to start making your
site look unique so lets start off with the first layout you will create.  This will be the default page layout for your site so we will name it ```default.html```.  Go ahead and create this file under
```_content/templates/```.  For now just make it look like the following:
 
{% geshi 'twig' line_numbers class='codeblock' %}
  {%- verbatim -%}
    <html>
      <head>
        <title>Your Site Title</title>
      </head>
      <body>
        {{ content|raw }}
      </body>
    </html>
  {%- endverbatim -%}
{% endgeshi %}
Now if you run ```chef serve``` you will still see the page load with the same content but the styles are no longer making it look 'pretty'.  This is because PieCrust is now using your newly created ```default.html```
for the page layout rather than the one bundled with the PieCrust source code.  Don't worry about the styles missing we will take care of that next.
 
<img src="{{ assets['new_site'] }}" class="floatcenter" />
 
Now that you have your basic layout in place it's time to create your index page.  There are a few ways you can do this.
 
1. You can manually create the file ```_content/pages/_index.html```
2. You can execute the command ```chef prepare page _index```
 
There really is no difference between either method both are valid ways of creating pages.  Using ```chef``` will create the file and add a few lines of boiler-plate code.  For this I opted to use the ```chef```
command.  Below are the contents of the generated ```_index.html``` file.
 
{% geshi 'markdown' line_numbers class='codeblock' %}
  {%- verbatim -%}
---
title:  Index
date: 2013-08-12 18:36
---
A new page.
  {%- endverbatim -%}
{% endgeshi %}
 
As you can see from the above output it adds the title of the page and the date.  It also adds some text to the page although it's not very useful.  The one thing it does not do is add the layout to use.  I'm sure
this is because PieCrust does not know what layout you have created or wish to use if you have multiple layouts.  In order to make this page use your default layout you will have to modify the page to look like
the following.
 
{% geshi 'markdown' line_numbers class='codeblock' %}
---
title:  Index
layout: default
date: 2013-08-12 18:36
---
This is my main index page for my site.
{% endgeshi %}
 
Now if you run the ```chef serve``` command you should see nothing more than the text ```This is my main index page for my site.```.  Don't worry about it not having any content we will get to that soon.  For now
you have the site generating your index page using the default layout that you have created.  If you view the page source you should see the following HTML generated.
 
{% geshi 'html' line_numbers class='codeblock' %}
  {%- verbatim -%}
        <html>
      <head>
      <title>Your Site Title</title>
      </head>
      <body>
        <p>This is my main index page for my site.</p>
      </body>
    </html>
        {%- endverbatim -%}
{% endgeshi %}
 
You will notice that the boiler plate HTML that you added to your ```default.html``` is used and the contents of your index page have been injected into the body of your layout.
 
Before I end this article I want to make one more thing clear.  Every page that you create in PieCrust will only be displayed in your layouts content area.  For instance on this site the left pane of the site is
my content area.  The sidebar on the right of my layout is not included in my page.  This is defined in my ```default.html``` layout.  If you look back in your layout file that you created you will see something like this
```{{ content|raw }}``` to the page.  You will add this to your content area of your layout.  If you have a sidebar like I do, you will have to have that HTML in your default layout as well.
stdout
# {{ page.title }}
Now that you have your site generated you can load it in your browser and you should see the default PieCrust site.  
 
<img src="{{ assets['default_site'] }}" class="floatcenter" />
 
You might be wondering how your site can be working since you have not created any
layouts or template files.  The reason it works is because it will default to the layouts and templates that are bundled with the PieCrust source code.  I'm sure you are ready to start making your
site look unique so lets start off with the first layout you will create.  This will be the default page layout for your site so we will name it ```default.html```.  Go ahead and create this file under
```_content/templates/```.  For now just make it look like the following:
 
<pre><code class="twig codeblock">
    &lt;html&gt;
      &lt;head&gt;
        &lt;title&gt;Your Site Title&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
        {{ content|raw }}
      &lt;/body&gt;
    &lt;/html&gt;
  </code></pre>
Now if you run ```chef serve``` you will still see the page load with the same content but the styles are no longer making it look 'pretty'.  This is because PieCrust is now using your newly created ```default.html```
for the page layout rather than the one bundled with the PieCrust source code.  Don't worry about the styles missing we will take care of that next.
 
<img src="{{ assets['new_site'] }}" class="floatcenter" />
 
Now that you have your basic layout in place it's time to create your index page.  There are a few ways you can do this.
 
1. You can manually create the file ```_content/pages/_index.html```
2. You can execute the command ```chef prepare page _index```
 
There really is no difference between either method both are valid ways of creating pages.  Using ```chef``` will create the file and add a few lines of boiler-plate code.  For this I opted to use the ```chef```
command.  Below are the contents of the generated ```_index.html``` file.
 
<pre><code class="markdown codeblock">

---

title:  Index
date: 2013-08-12 18:36

---

A new page.
  </code></pre>
 
As you can see from the above output it adds the title of the page and the date.  It also adds some text to the page although it's not very useful.  The one thing it does not do is add the layout to use.  I'm sure
this is because PieCrust does not know what layout you have created or wish to use if you have multiple layouts.  In order to make this page use your default layout you will have to modify the page to look like
the following.
 
<pre><code class="markdown codeblock">
        &lt;html&gt;
      &lt;head&gt;
      &lt;title&gt;Your Site Title&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
        &lt;p&gt;This is my main index page for my site.&lt;/p&gt;
      &lt;/body&gt;
    &lt;/html&gt;
        </code></pre>
 
You will notice that the boiler plate HTML that you added to your ```default.html``` is used and the contents of your index page have been injected into the body of your layout.
 
Before I end this article I want to make one more thing clear.  Every page that you create in PieCrust will only be displayed in your layouts content area.  For instance on this site the left pane of the site is
my content area.  The sidebar on the right of my layout is not included in my page.  This is defined in my ```default.html``` layout.  If you look back in your layout file that you created you will see something like this
```{{ content|raw }}``` to the page.  You will add this to your content area of your layout.  If you have a sidebar like I do, you will have to have that HTML in your default layout as well.