From: Noah Campbell Date: Thu, 3 Oct 2013 00:00:21 +0000 (-0400) Subject: Add support for Relative Permalinks X-Git-Tag: v0.9~53 X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=197aacb6472732126312c22b5bde730ef34258a6;p=brevno-suite%2Fhugo Add support for Relative Permalinks --- diff --git a/docs/content/layout/index.md b/docs/content/layout/index.md deleted file mode 100644 index 307e5460..00000000 --- a/docs/content/layout/index.md +++ /dev/null @@ -1,122 +0,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" . }} - -
-
-

{{ .Title }}

-
    - {{ range .Data.Pages }} - {{ .Render "li"}} - {{ end }} -
-
-
- - {{ 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" . }} - -
-
-

{{ .Title }}

- {{ range .Data.Pages }} - {{ .Render "summary"}} - {{ end }} -
-
- - {{ 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" . }} - -
-
-

{{ .Title }}

- -
    - {{ $data := .Data }} - {{ range $key, $value := .Data.Index }} -
  • {{ $key }} {{ len $value }}
  • - {{ end }} -
-
- - -
- - {{ template "chrome/footer.html" }} - - - - diff --git a/docs/content/layout/indexes.md b/docs/content/layout/indexes.md new file mode 100644 index 00000000..307e5460 --- /dev/null +++ b/docs/content/layout/indexes.md @@ -0,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" . }} + +
+
+

{{ .Title }}

+
    + {{ range .Data.Pages }} + {{ .Render "li"}} + {{ end }} +
+
+
+ + {{ 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" . }} + +
+
+

{{ .Title }}

+ {{ range .Data.Pages }} + {{ .Render "summary"}} + {{ end }} +
+
+ + {{ 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" . }} + +
+
+

{{ .Title }}

+ +
    + {{ $data := .Data }} + {{ range $key, $value := .Data.Index }} +
  • {{ $key }} {{ len $value }}
  • + {{ end }} +
+
+ + +
+ + {{ template "chrome/footer.html" }} + + + + diff --git a/docs/layouts/index.html b/docs/layouts/index.html deleted file mode 100644 index b6646e75..00000000 --- a/docs/layouts/index.html +++ /dev/null @@ -1,54 +0,0 @@ - - - - Hugo Static Site Generator written in Go lang - - - {{ template "chrome/includes.html" . }} - - - -
-
-
- {{ template "chrome/menu.html" . }} -
-
- -
-

Hugo

-

A Fast and Flexible Static Site Generator built with love by spf13 - and friends in Go

-

- Get Started -

-
-
-
-

Fast -
-

-

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.
- It's so fast that it will render the site in - less time than it takes to switch to your browser and reload.

-
-
-

Flexible

-

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.

-
-
-

Fun

-

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.

-
-
-{{ template "chrome/footer.html" }} diff --git a/hugolib/page.go b/hugolib/page.go index f35b1a5e..44f10921 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -253,6 +253,19 @@ func (p *Page) Permalink() (string, error) { 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) diff --git a/hugolib/site.go b/hugolib/site.go index 3f2f565a..782bafbb 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -551,7 +551,7 @@ func (s *Site) render(d interface{}, out string, layouts ...string) (err error) section := "" page, ok := d.(*Page) if ok { - section, _ = page.Permalink() + section, _ = page.RelPermalink() } fmt.Println("Section is:", section)