ref: 197aacb6472732126312c22b5bde730ef34258a6
parent: 06da609138475de317e7e5fbf3a0a8c3af3c64e4
author: Noah Campbell <[email protected]>
date: Wed Oct 2 16:00:21 EDT 2013
Add support for Relative Permalinks
--- a/docs/content/layout/index.md
+++ /dev/null
@@ -1,122 +1,0 @@
----
-title: "Index Templates"
-date: "2013-07-01"
----
-
-An index template is any template that will be used to render multiple pieces of
-content (with the exception of the [homepage](/layout/homepage) which has a
-dedicated template).
-
-We are using the term index in its truest sense, a sequential arrangement of
-material, especially in alphabetical or numerical order. In the case of Hugo
-each index will render the content in newest first order based on the date
-provided in the [front matter](/content/front-matter).
-
-index pages are of the type "node" and have all the [node
-variables](/layout/variables/) available to use in the templates.
-All index templates live in the layouts/indexes directory. There are 3 different
-kinds of indexes that Hugo can produce.
-
-1. A listing of all the content for a given [section](/content/sections)
-2. A listing of all the content for a given [index](/extras/indexes)
-3. A listing of listings... [meta index](/extras/indexes)
-
-It's critical that the name of the index template matches either:
-
-1. The section name
-2. The index singular name
-3. "indexes"
-
-The following illustrates the location of one of each of these types.
-
- ▾ layouts/
- ▾ indexes/
- indexes.html
- post.html
- tag.html
-
-## Example section template (post.html)
-This content template is used for [spf13.com](http://spf13.com).
-It makes use of [chrome templates](/layout/chrome). All examples use a
-[view](/layout/views/) called either "li" or "summary" which this example site
-defined.
-
- {{ template "chrome/header.html" . }}
- {{ template "chrome/subheader.html" . }}
-
- <section id="main">
- <div>
- <h1 id="title">{{ .Title }}</h1>
- <ul id="list">
- {{ range .Data.Pages }}
- {{ .Render "li"}}
- {{ end }}
- </ul>
- </div>
- </section>
-
- {{ template "chrome/footer.html" }}
-
-## Example index template (tag.html)
-This content template is used for [spf13.com](http://spf13.com).
-It makes use of [chrome templates](/layout/chrome). All examples use a
-[view](/layout/views/) called either "li" or "summary" which this example site
-defined.
-
- {{ template "chrome/header.html" . }}
- {{ template "chrome/subheader.html" . }}
-
- <section id="main">
- <div>
- <h1 id="title">{{ .Title }}</h1>
- {{ range .Data.Pages }}
- {{ .Render "summary"}}
- {{ end }}
- </div>
- </section>
-
- {{ template "chrome/footer.html" }}
-
-
-## Example listing of indexes template (indexes.html)
-This content template is used for [spf13.com](http://spf13.com).
-It makes use of [chrome templates](/layout/chrome). The list of indexes
-templates cannot use a [content view](/layout/views) as they don't display the content, but
-rather information about the content.
-
-This particular template lists all of the Tags used on
-[spf13.com](http://spf13.com) and provides a count for the number of pieces of
-content tagged with each tag.
-
-This example demonstrates two different approaches. The first uses .Data.Index and
-the latter uses .Data.OrderedIndex. .Data.Index is alphabetical by key name, while
-.Data.Orderedindex is ordered by the quantity of content assigned to that particular
-index key. In practice you would only use one of these approaches.
-
- {{ template "chrome/header.html" . }}
- {{ template "chrome/subheader.html" . }}
-
- <section id="main">
- <div>
- <h1 id="title">{{ .Title }}</h1>
-
- <ul>
- {{ $data := .Data }}
- {{ range $key, $value := .Data.Index }}
- <li><a href="{{ $data.Plural }}/{{ $key | urlize }}"> {{ $key }} </a> {{ len $value }} </li>
- {{ end }}
- </ul>
- </div>
-
- <ul>
- {{ range $data.OrderedIndex }}
- <li><a href="{{ $data.Plural }}/{{ .Name | urlize }}"> {{ .Name }} </a> {{ .Count }} </li>
- {{ end }}
- </ul>
- </section>
-
- {{ template "chrome/footer.html" }}
-
-
-
-
--- /dev/null
+++ b/docs/content/layout/indexes.md
@@ -1,0 +1,122 @@
+---
+title: "Index Templates"
+date: "2013-07-01"
+---
+
+An index template is any template that will be used to render multiple pieces of
+content (with the exception of the [homepage](/layout/homepage) which has a
+dedicated template).
+
+We are using the term index in its truest sense, a sequential arrangement of
+material, especially in alphabetical or numerical order. In the case of Hugo
+each index will render the content in newest first order based on the date
+provided in the [front matter](/content/front-matter).
+
+index pages are of the type "node" and have all the [node
+variables](/layout/variables/) available to use in the templates.
+All index templates live in the layouts/indexes directory. There are 3 different
+kinds of indexes that Hugo can produce.
+
+1. A listing of all the content for a given [section](/content/sections)
+2. A listing of all the content for a given [index](/extras/indexes)
+3. A listing of listings... [meta index](/extras/indexes)
+
+It's critical that the name of the index template matches either:
+
+1. The section name
+2. The index singular name
+3. "indexes"
+
+The following illustrates the location of one of each of these types.
+
+ ▾ layouts/
+ ▾ indexes/
+ indexes.html
+ post.html
+ tag.html
+
+## Example section template (post.html)
+This content template is used for [spf13.com](http://spf13.com).
+It makes use of [chrome templates](/layout/chrome). All examples use a
+[view](/layout/views/) called either "li" or "summary" which this example site
+defined.
+
+ {{ template "chrome/header.html" . }}
+ {{ template "chrome/subheader.html" . }}
+
+ <section id="main">
+ <div>
+ <h1 id="title">{{ .Title }}</h1>
+ <ul id="list">
+ {{ range .Data.Pages }}
+ {{ .Render "li"}}
+ {{ end }}
+ </ul>
+ </div>
+ </section>
+
+ {{ template "chrome/footer.html" }}
+
+## Example index template (tag.html)
+This content template is used for [spf13.com](http://spf13.com).
+It makes use of [chrome templates](/layout/chrome). All examples use a
+[view](/layout/views/) called either "li" or "summary" which this example site
+defined.
+
+ {{ template "chrome/header.html" . }}
+ {{ template "chrome/subheader.html" . }}
+
+ <section id="main">
+ <div>
+ <h1 id="title">{{ .Title }}</h1>
+ {{ range .Data.Pages }}
+ {{ .Render "summary"}}
+ {{ end }}
+ </div>
+ </section>
+
+ {{ template "chrome/footer.html" }}
+
+
+## Example listing of indexes template (indexes.html)
+This content template is used for [spf13.com](http://spf13.com).
+It makes use of [chrome templates](/layout/chrome). The list of indexes
+templates cannot use a [content view](/layout/views) as they don't display the content, but
+rather information about the content.
+
+This particular template lists all of the Tags used on
+[spf13.com](http://spf13.com) and provides a count for the number of pieces of
+content tagged with each tag.
+
+This example demonstrates two different approaches. The first uses .Data.Index and
+the latter uses .Data.OrderedIndex. .Data.Index is alphabetical by key name, while
+.Data.Orderedindex is ordered by the quantity of content assigned to that particular
+index key. In practice you would only use one of these approaches.
+
+ {{ template "chrome/header.html" . }}
+ {{ template "chrome/subheader.html" . }}
+
+ <section id="main">
+ <div>
+ <h1 id="title">{{ .Title }}</h1>
+
+ <ul>
+ {{ $data := .Data }}
+ {{ range $key, $value := .Data.Index }}
+ <li><a href="{{ $data.Plural }}/{{ $key | urlize }}"> {{ $key }} </a> {{ len $value }} </li>
+ {{ end }}
+ </ul>
+ </div>
+
+ <ul>
+ {{ range $data.OrderedIndex }}
+ <li><a href="{{ $data.Plural }}/{{ .Name | urlize }}"> {{ .Name }} </a> {{ .Count }} </li>
+ {{ end }}
+ </ul>
+ </section>
+
+ {{ template "chrome/footer.html" }}
+
+
+
+
--- a/docs/layouts/index.html
+++ /dev/null
@@ -1,54 +1,0 @@
-<!doctype html>
-<html>
- <head>
- <title>Hugo Static Site Generator written in Go lang</title>
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
- {{ template "chrome/includes.html" . }}
- </head>
- <body>
- <div class="navbar"></div>
- <div class="container-fluid">
- <div class="row-fluid">
- <div class="span3">
- {{ template "chrome/menu.html" . }}
- </div>
- <div class="span9">
-
- <div class="hero-unit" style="background-color: #222; color: #ccc;">
- <h1>Hugo</h1>
- <p>A Fast and Flexible Static Site Generator built with love by <a href="http://spf13.com">spf13</a>
- and <a href="http://github.com/spf13/hugo/graphs/contributors">friends</a> in Go</p>
- <p>
- <a class="btn btn-large btn-success" href="/doc/installing">Get Started</a>
- </p>
- </div>
- <div class="row-fluid">
- <div class="span4">
- <h2>Fast
- <br>
- </h2>
- <p>Written in GoLang for speed, Hugo is significantly faster than most
- other static site generators.
- A typical website of moderate size can be
- rendered in a fraction of a second. A good rule of thumb is that Hugo
- takes around 1 millisecond for each piece of content.<br>
- It's so fast that it will render the site in
- less time than it takes to switch to your browser and reload.</p>
- </div>
- <div class="span4">
- <h2>Flexible</h2>
- <p>Hugo is made to be very flexible. Define your own content types. Define
- your own indexes. Build your own templates, shortcodes and more.
- It is written to work well with any
- kind of website including blogs, tumbles and docs.</p>
- </div>
- <div class="span4">
- <h2>Fun</h2>
- <p>Hugo runs everywhere. Sites generated with Hugo work on every web
- server without any special configuration. Hugo
- removes all the cruft of building a site allowing you to
- focus on writing great content.</p>
- </div>
- </div>
-{{ template "chrome/footer.html" }}
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -253,6 +253,19 @@
return link.String(), nil
}
+func (p *Page) RelPermalink() (string, error) {
+ link, err := p.permalink()
+ if err != nil {
+ return "", err
+ }
+
+ link.Scheme = ""
+ link.Host = ""
+ link.User = nil
+ link.Opaque = ""
+ return link.String(), nil
+}
+
func (page *Page) handleTomlMetaData(datum []byte) (interface{}, error) {
m := map[string]interface{}{}
datum = removeTomlIdentifier(datum)
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -551,7 +551,7 @@
section := ""
page, ok := d.(*Page)
if ok {
- section, _ = page.Permalink()
+ section, _ = page.RelPermalink()
}
fmt.Println("Section is:", section)