mirror of
https://github.com/gohugoio/hugo.git
synced 2024-07-02 15:20:28 +00:00
Use md5 against the file path for uniqueness.
This commit is contained in:
parent
603b24a163
commit
9cdd2e54c2
|
@ -15,6 +15,8 @@ package hugolib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"crypto/md5"
|
||||||
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
@ -62,7 +64,7 @@ type Page struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type File struct {
|
type File struct {
|
||||||
Name, FileName, Extension, Dir string
|
Name, FileName, Extension, Dir, UniqueId string
|
||||||
}
|
}
|
||||||
|
|
||||||
type PageMeta struct {
|
type PageMeta struct {
|
||||||
|
@ -94,6 +96,10 @@ func (p *Page) IsPage() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Page) UniqueId() string {
|
||||||
|
return p.File.UniqueId
|
||||||
|
}
|
||||||
|
|
||||||
func (p *Page) setSummary() {
|
func (p *Page) setSummary() {
|
||||||
if bytes.Contains(p.rawContent, summaryDivider) {
|
if bytes.Contains(p.rawContent, summaryDivider) {
|
||||||
// If user defines split:
|
// If user defines split:
|
||||||
|
@ -119,11 +125,11 @@ func bytesToHTML(b []byte) template.HTML {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Page) renderBytes(content []byte) []byte {
|
func (p *Page) renderBytes(content []byte) []byte {
|
||||||
return renderBytes(content, p.guessMarkupType(), p.File.Name)
|
return renderBytes(content, p.guessMarkupType(), p.UniqueId())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Page) renderContent(content []byte) []byte {
|
func (p *Page) renderContent(content []byte) []byte {
|
||||||
return renderBytesWithTOC(content, p.guessMarkupType(), p.File.Name)
|
return renderBytesWithTOC(content, p.guessMarkupType(), p.UniqueId())
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderBytesWithTOC(content []byte, pagefmt string, footnoteref string) []byte {
|
func renderBytesWithTOC(content []byte, pagefmt string, footnoteref string) []byte {
|
||||||
|
@ -154,7 +160,7 @@ func newPage(filename string) *Page {
|
||||||
name = name[:len(name)-len(filepath.Ext(name))]
|
name = name[:len(name)-len(filepath.Ext(name))]
|
||||||
|
|
||||||
page := Page{contentType: "",
|
page := Page{contentType: "",
|
||||||
File: File{Name: name, FileName: filename, Extension: "html"},
|
File: File{Name: name, FileName: filename, Extension: "html", UniqueId: md5ForFilename(filename)},
|
||||||
Node: Node{Keywords: []string{}, Sitemap: Sitemap{Priority: -1}},
|
Node: Node{Keywords: []string{}, Sitemap: Sitemap{Priority: -1}},
|
||||||
Params: make(map[string]interface{})}
|
Params: make(map[string]interface{})}
|
||||||
|
|
||||||
|
@ -804,3 +810,9 @@ func sliceToLower(s []string) []string {
|
||||||
|
|
||||||
return l
|
return l
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func md5ForFilename(f string) string {
|
||||||
|
h := md5.New()
|
||||||
|
h.Write([]byte(f))
|
||||||
|
return hex.EncodeToString(h.Sum([]byte{}))
|
||||||
|
}
|
||||||
|
|
|
@ -93,7 +93,7 @@ func ShortcodesHandle(stringToParse string, p *Page, t Template) string {
|
||||||
var data = &ShortcodeWithPage{Params: params, Page: p}
|
var data = &ShortcodeWithPage{Params: params, Page: p}
|
||||||
if endStart > 0 {
|
if endStart > 0 {
|
||||||
s := stringToParse[leadEnd+3 : leadEnd+endStart]
|
s := stringToParse[leadEnd+3 : leadEnd+endStart]
|
||||||
data.Inner = template.HTML(renderBytes([]byte(CleanP(ShortcodesHandle(s, p, t))), p.guessMarkupType(), p.File.Name))
|
data.Inner = template.HTML(renderBytes([]byte(CleanP(ShortcodesHandle(s, p, t))), p.guessMarkupType(), p.UniqueId()))
|
||||||
remainder := CleanP(stringToParse[leadEnd+endEnd:])
|
remainder := CleanP(stringToParse[leadEnd+endEnd:])
|
||||||
|
|
||||||
return CleanP(stringToParse[:leadStart]) +
|
return CleanP(stringToParse[:leadStart]) +
|
||||||
|
|
Loading…
Reference in a new issue