mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-29 23:22:11 -05:00
Writing relative links to absolute so they work in feeds
This commit is contained in:
parent
e76c3feb52
commit
51e3098548
2 changed files with 16 additions and 1 deletions
|
@ -83,6 +83,8 @@ func (site *Site) Render() {
|
||||||
site.timer.Step("render and write lists")
|
site.timer.Step("render and write lists")
|
||||||
site.ProcessShortcodes()
|
site.ProcessShortcodes()
|
||||||
site.timer.Step("render shortcodes")
|
site.timer.Step("render shortcodes")
|
||||||
|
site.AbsUrlify()
|
||||||
|
site.timer.Step("absolute URLify")
|
||||||
site.RenderPages()
|
site.RenderPages()
|
||||||
site.timer.Step("render pages")
|
site.timer.Step("render pages")
|
||||||
site.RenderHomePage()
|
site.RenderHomePage()
|
||||||
|
@ -182,6 +184,17 @@ func (s *Site) ProcessShortcodes() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Site) AbsUrlify() {
|
||||||
|
for i, _ := range s.Pages {
|
||||||
|
content := string(s.Pages[i].Content)
|
||||||
|
content = strings.Replace(content, " src=\"/", " src=\""+s.c.BaseUrl+"/", -1)
|
||||||
|
content = strings.Replace(content, " src='/", " src='"+s.c.BaseUrl+"/", -1)
|
||||||
|
content = strings.Replace(content, " href='/", " href='"+s.c.BaseUrl+"/", -1)
|
||||||
|
content = strings.Replace(content, " href=\"/", " href=\""+s.c.BaseUrl+"/", -1)
|
||||||
|
s.Pages[i].Content = template.HTML(content)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Site) CreatePages() {
|
func (s *Site) CreatePages() {
|
||||||
for _, fileName := range s.Files {
|
for _, fileName := range s.Files {
|
||||||
page := NewPage(fileName)
|
page := NewPage(fileName)
|
||||||
|
|
4
main.go
4
main.go
|
@ -64,7 +64,9 @@ func main() {
|
||||||
|
|
||||||
if *baseUrl != "" {
|
if *baseUrl != "" {
|
||||||
config.BaseUrl = *baseUrl
|
config.BaseUrl = *baseUrl
|
||||||
}
|
} else if *server {
|
||||||
|
config.BaseUrl = "http://localhost:" + *port
|
||||||
|
}
|
||||||
|
|
||||||
if *version {
|
if *version {
|
||||||
fmt.Println("Hugo Static Site Generator v0.8")
|
fmt.Println("Hugo Static Site Generator v0.8")
|
||||||
|
|
Loading…
Reference in a new issue