changing to suport yaml rather than json and adding optional restructuredtext support
authortycho garen <garen@tychoish.com>
Sun, 7 Jul 2013 02:31:43 +0000 (22:31 -0400)
committertycho garen <garen@tychoish.com>
Sun, 7 Jul 2013 02:48:12 +0000 (22:48 -0400)
docs/content/doc/configuration.md
docs/content/doc/example.md
docs/content/doc/front-matter.md
hugolib/page.go
main.go

index eea530f02c56058fcaea7bfc2d07660c4c125442..09cfb48f3a5d0ac07d6759bf5e43e8b4dc6f1e97 100644 (file)
@@ -7,13 +7,15 @@ The directory structure and templates provide the majority of the
 configuration for a site. In fact a config file isn't even needed for many websites
 since the defaults used follow commonly used patterns.
 
-The following is an example of a config file with the default values
+The following is an example of a config file with the default values: 
+
+    SourceDir: "content"
+    LayoutDir: "layouts"
+    PublishDir: "public"
+    BuildDrafts: false
+    Tags:
+       category: "categories"
+       tag: "tags"
+    BaseUrl: "http://yourSite.com/"
+    ...
 
-    {
-        "SourceDir" : "content",
-        "LayoutDir" : "layouts",
-        "PublishDir" : "public",
-        "BuildDrafts" : false,
-        "Tags" : { "category" : "categories", "tag" : "tags" },
-        "BaseUrl"    : "http://yourSite.com/"
-    }
index 75f35f2bfe97c618a0eabeb662ca3cebe2858c63..03595ad10ad49d25e01b9fc8a443dd35f5187623 100644 (file)
@@ -7,16 +7,16 @@ Somethings are better shown than explained. The following is a very basic exampl
 
 **mysite/project/nitro.md  <- http://mysite.com/project/nitro.html**
 
-    {
-        "Title": "Nitro : A quick and simple profiler for golang",
-        "Description": "",
-        "Keywords": [ "Development", "golang", "profiling" ],
-        "Tags": [ "Development", "golang", "profiling" ],
-        "Pubdate": "2013-06-19",
-        "Topics": [ "Development", "GoLang" ],
-        "Slug": "nitro",
-        "project_url": "http://github.com/spf13/nitro"
-    }
+    ---
+    Title: "Nitro : A quick and simple profiler for golang"
+    Description": ""
+    Keywords": [ "Development", "golang", "profiling" ]
+    Tags": [ "Development", "golang", "profiling" ]
+    Pubdate": "2013-06-19"
+    Topics": [ "Development", "GoLang" ]
+    Slug": "nitro"
+    project_url": "http://github.com/spf13/nitro"
+    ...
 
     # Nitro
 
index 3f00837132791885f145fc12befadf73bebd67af..af930b25f86581d4f5f216052aee4e03688adf57 100644 (file)
@@ -5,18 +5,21 @@ Pubdate: "2013-07-01"
 
 The front matter is one of the features that gives Hugo it's strength. It enables
 you to include the meta data of the content right with it. Hugo supports a few 
-different formats. The main format supported is JSON. Here is an example:
-
-    {
-        "Title": "spf13-vim 3.0 release and new website",
-        "Description": "spf13-vim is a cross platform distribution of vim plugins and resources for Vim.",
-        "Tags": [ ".vimrc", "plugins", "spf13-vim", "vim" ],
-        "Pubdate": "2012-04-06",
-        "Categories": [ "Development", "VIM" ],
-        "Slug": "spf13-vim-3-0-release-and-new-website"
-    }
+different formats. The main format supported is YAML. Here is an example:
+
+    ---
+    Title: "spf13-vim 3.0 release and new website"
+    Description: "spf13-vim is a cross platform distribution of vim plugins and resources for Vim."
+    Tags: [ ".vimrc", "plugins", "spf13-vim", "vim" ]
+    Pubdate: "2012-04-06"
+    Categories:
+      - "Development"
+      - "VIM"
+    Slug: "spf13-vim-3-0-release-and-new-website"
+    ...
 
 ### Variables
+
 There are a few predefined variables that Hugo is aware of and utilizes. The user can also create
 any variable they want to. These will be placed into the `.Params` variable available to the templates.
 
@@ -31,6 +34,8 @@ any variable they want to. These will be placed into the `.Params` variable avai
 
 **Draft** If true the content will not be rendered unless `hugo` is called with -d<br>
 **Type** The type of the content (will be derived from the directory automatically if unset).<br>
+**Markup** (Experimental) Specify "rst" for reStructuredText (requires
+           `rst2html`,) or "md" (default) for the Markdown.<br>
 **Slug** The token to appear in the tail of the url.<br>
   *or*<br>
 **Url** The full path to the content from the web root.<br>
index 46c56641291b93c0f56d6b2f06dd7776a199de6c..61b3cf0d35161d17a49e86858d0a58d88cb54cda 100644 (file)
@@ -21,6 +21,7 @@ import (
        "html/template"
        "io/ioutil"
        "os"
+       "os/exec"
        "path/filepath"
        "sort"
        "strings"
@@ -40,6 +41,7 @@ type Page struct {
        contentType     string
        Draft           bool
        Tmpl            *template.Template
+       Markup          string
        PageMeta
        File
        Position
@@ -80,6 +82,7 @@ func initializePage(filename string) (page Page) {
        page.Extension = "html"
        page.Params = make(map[string]interface{})
        page.Keywords = make([]string, 10, 30)
+       page.Markup = "md"
        page.setSection()
 
        return page
@@ -216,6 +219,8 @@ func (page *Page) handleYamlMetaData(datum []byte) error {
                        page.Draft = interfaceToBool(v)
                case "layout":
                        page.layout = interfaceToString(v)
+               case "markup":
+                       page.Markup = interfaceToString(v)
                case "status":
                        page.Status = interfaceToString(v)
                default:
@@ -352,7 +357,12 @@ func (page *Page) buildPageFromFile() error {
                return err
        }
 
-       page.convertMarkdown(content)
+       switch page.Markup {
+       case "md":
+               page.convertMarkdown(content)
+       case "rst":
+               page.convertRestructuredText(content)
+       }
        return nil
 }
 
@@ -379,3 +389,20 @@ func (page *Page) convertMarkdown(lines []string) {
        page.Content = template.HTML(content)
        page.Summary = template.HTML(TruncateWordsToWholeSentence(StripHTML(StripShortcodes(content)), summaryLength))
 }
+
+func (page *Page) convertRestructuredText(lines []string) {
+
+       page.RawMarkdown = strings.Join(lines, " ")
+
+       cmd := exec.Command("rst2html.py", "--template=/tmp/template.txt")
+       cmd.Stdin = strings.NewReader(page.RawMarkdown)
+       var out bytes.Buffer
+       cmd.Stdout = &out
+       if err := cmd.Run(); err != nil {
+               print(err)
+       }
+
+       content := out.String()
+       page.Content = template.HTML(content)
+       page.Summary = template.HTML(TruncateWordsToWholeSentence(StripHTML(StripShortcodes(content)), summaryLength))
+}
diff --git a/main.go b/main.go
index 1de48f766518d45ed74e612904ca206e6b2d6586..3f4b6f96812fae2c1ba2f387704aacae60f908a8 100644 (file)
--- a/main.go
+++ b/main.go
 package main
 
 import (
+       "./hugolib"
        "flag"
        "fmt"
        "github.com/howeyc/fsnotify"
-       "./hugolib"
        "net/http"
        "os"
        "path/filepath"