ref: 45ce6e2b309dc247315885db4de4d03192b93914
parent: 733c0207cb855d2d4a5130bc469c662e50b61d59
parent: e2a28114d196689337fea8a78f250c7ef706b4be
author: spf13 <[email protected]>
date: Sat Aug 10 10:08:38 EDT 2013
Merge branch 'redirect' of https://github.com/rozza/hugo into rozza-redirect Conflicts: hugolib/page.go
--- a/docs/content/doc/front-matter.md
+++ b/docs/content/doc/front-matter.md
@@ -4,8 +4,8 @@
+++
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 each with their own identifying tokens.
+you to include the meta data of the content right with it. Hugo supports a few
+different formats each with their own identifying tokens.
Supported formats: <br>
**YAML**, identified by '\-\-\-'. <br>
@@ -24,7 +24,7 @@
- "VIM"
slug: "spf13-vim-3-0-release-and-new-website"
---
- Content of the file goes Here
+ Content of the file goes Here
### TOML Example
@@ -39,7 +39,7 @@
]
slug = "spf13-vim-3-0-release-and-new-website"
+++
- Content of the file goes Here
+ Content of the file goes Here
### JSON Example
@@ -54,7 +54,7 @@
],
"slug": "spf13-vim-3-0-release-and-new-website",
}
- Content of the file goes Here
+ Content of the file goes Here
### Variables
@@ -71,6 +71,7 @@
#### Optional
+**redirect** Mark the post as a redirect post<br>
**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
--- /dev/null
+++ b/docs/content/doc/redirects.md
@@ -1,0 +1,37 @@
+---
+title: "Redirects"
+Pubdate: "2013-07-09"
+---
+
+For people migrating existing published content to Hugo theres a good chance
+you need a mechanism to handle redirecting old urls.
+
+Luckily, this can be handled easily in a couple of easy steps.
+
+1. Create a special post for the redirect and mark the file as a `redirect`
+ file in the front matter. Here is an example
+ `content/redirects/my-awesome-blog-post.md` :
+
+ ```markdown
+ ---
+ redirect: true
+ slug: /my-awesome-blog-post/
+ url: /docs/redirects/
+ ---
+```
+
+2. Set the redirect template `layouts/redirects/single.html`:
+
+ ```html
+ <!DOCTYPE html>
+ <html>
+ <head>
+ <link rel="canonical" href="{{ .Url }}"/>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+ <meta http-equiv="refresh" content="0;url={{ .Url }}" />
+ </head>
+ </html>
+ ```
+
+Now when you go to `/my-awesome-blog-post/` it will do a meta redirect to
+`/docs/redirects/`.
\ No newline at end of file
--- /dev/null
+++ b/docs/content/redirects/my-awesome-blog-post.md
@@ -1,0 +1,5 @@
+---
+redirect: true
+slug: /my-awesome-blog-post/
+url: /docs/redirects1/
+---
\ No newline at end of file
--- a/docs/layouts/chrome/menu.html
+++ b/docs/layouts/chrome/menu.html
@@ -19,6 +19,7 @@
<li class="nav-header">Extras</li>
<li> <a href="/doc/shortcodes">ShortCodes</a></li>
<li> <a href="/doc/indexes">Indexes</a></li>
+ <li> <a href="/doc/redirects">Redirects</a></li>
<li class="divider"></li>
<li class="nav-header">Meta</li>
<li> <a href="/doc/release-notes">Release Notes</a></li>
--- /dev/null
+++ b/docs/layouts/redirects/single.html
@@ -1,0 +1,8 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <link rel="canonical" href="{{ .Url }}"/>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+ <meta http-equiv="refresh" content="0;url={{ .Url }}" />
+</head>
+</html>
\ No newline at end of file
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -46,6 +46,7 @@
RenderedContent *bytes.Buffer
contentType string
Draft bool
+ Aliases []string
Tmpl *template.Template
Markup string
PageMeta
@@ -98,9 +99,21 @@
return
}
+ //section := x[len(x)-2]
if section := x[len(x)-2]; section != "content" {
p.Section = section
}
+
+ //c := p.Site.Config
+ //systemDirs := map[string]bool{
+ //c.ContentDir: true,
+ //c.StaticDir: true,
+ //c.LayoutDir: true,
+ //}
+
+ //if !systemDirs[section] && !p.Redirect {
+ //p.Section = section
+ //}
}
func (page *Page) Type() string {
@@ -107,7 +120,7 @@
if page.contentType != "" {
return page.contentType
}
-
+ page.setSection()
if x := page.GetSection(); x != "" {
return x
}
@@ -151,6 +164,7 @@
// TODO initalize separately... load from reader (file, or []byte)
func NewPage(filename string) *Page {
p := initializePage(filename)
+
if err := p.buildPageFromFile(); err != nil {
fmt.Println(err)
}
@@ -264,6 +278,13 @@
page.layout = interfaceToString(v)
case "markup":
page.Markup = interfaceToString(v)
+ case "aliases":
+ page.Aliases = interfaceArrayToStringArray(v)
+ for _, alias := range page.Aliases {
+ if strings.HasPrefix(alias, "http://") || strings.HasPrefix(alias, "https://") {
+ return fmt.Errorf("Only relative aliases are supported, %v provided", alias)
+ }
+ }
case "status":
page.Status = interfaceToString(v)
default: