mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-20 21:31:32 +02:00
@@ -20,6 +20,7 @@ package helpers
|
||||
import (
|
||||
"bytes"
|
||||
"html/template"
|
||||
"strings"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
@@ -33,8 +34,6 @@ import (
|
||||
|
||||
bp "github.com/gohugoio/hugo/bufferpool"
|
||||
"github.com/gohugoio/hugo/config"
|
||||
|
||||
"strings"
|
||||
)
|
||||
|
||||
// SummaryDivider denotes where content summarization should end. The default is "<!--more-->".
|
||||
@@ -66,7 +65,6 @@ type ContentSpec struct {
|
||||
// NewContentSpec returns a ContentSpec initialized
|
||||
// with the appropriate fields from the given config.Provider.
|
||||
func NewContentSpec(cfg config.Provider, logger loggers.Logger, contentFs afero.Fs) (*ContentSpec, error) {
|
||||
|
||||
spec := &ContentSpec{
|
||||
summaryLength: cfg.GetInt("summaryLength"),
|
||||
BuildFuture: cfg.GetBool("buildFuture"),
|
||||
@@ -81,7 +79,6 @@ func NewContentSpec(cfg config.Provider, logger loggers.Logger, contentFs afero.
|
||||
ContentFs: contentFs,
|
||||
Logger: logger,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -112,7 +109,6 @@ var stripHTMLReplacer = strings.NewReplacer("\n", " ", "</p>", "\n", "<br>", "\n
|
||||
|
||||
// StripHTML accepts a string, strips out all HTML tags and returns it.
|
||||
func StripHTML(s string) string {
|
||||
|
||||
// Shortcut strings with no tags in them
|
||||
if !strings.ContainsAny(s, "<>") {
|
||||
return s
|
||||
|
@@ -118,7 +118,6 @@ func TestNewContentSpec(t *testing.T) {
|
||||
c.Assert(spec.BuildFuture, qt.Equals, true)
|
||||
c.Assert(spec.BuildExpired, qt.Equals, true)
|
||||
c.Assert(spec.BuildDrafts, qt.Equals, true)
|
||||
|
||||
}
|
||||
|
||||
var benchmarkTruncateString = strings.Repeat("This is a sentence about nothing.", 20)
|
||||
@@ -225,7 +224,7 @@ func TestExtractTOCGreaterThanSeventy(t *testing.T) {
|
||||
content := []byte("<nav>\n<ul>\nTOC This is a very long content which will definitely be greater than seventy, I promise you that.<li><a href=\"#")
|
||||
|
||||
actualTocLessContent, actualToc := ExtractTOC(content)
|
||||
//Because the start of Toc is greater than 70+startpoint of <li> content and empty TOC will be returned
|
||||
// Because the start of Toc is greater than 70+startpoint of <li> content and empty TOC will be returned
|
||||
expectedToc := []byte("")
|
||||
|
||||
if !bytes.Equal(actualTocLessContent, content) {
|
||||
@@ -255,7 +254,6 @@ func TestExtractNoTOC(t *testing.T) {
|
||||
var totalWordsBenchmarkString = strings.Repeat("Hugo Rocks ", 200)
|
||||
|
||||
func TestTotalWords(t *testing.T) {
|
||||
|
||||
for i, this := range []struct {
|
||||
s string
|
||||
words int
|
||||
|
@@ -11,9 +11,7 @@ import (
|
||||
|
||||
// This is is just some helpers used to create some JSON used in the Hugo docs.
|
||||
func init() {
|
||||
|
||||
docsProvider := func() docshelper.DocProvider {
|
||||
|
||||
var chromaLexers []interface{}
|
||||
|
||||
sort.Sort(lexers.Registry.Lexers)
|
||||
@@ -50,7 +48,6 @@ func init() {
|
||||
}
|
||||
|
||||
return docshelper.DocProvider{"chroma": map[string]interface{}{"lexers": chromaLexers}}
|
||||
|
||||
}
|
||||
|
||||
docshelper.AddDocProviderFunc(docsProvider)
|
||||
|
@@ -93,5 +93,4 @@ func initEmoji() {
|
||||
emojiMaxSize = len(k)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -74,7 +74,6 @@ func TestEmojiCustom(t *testing.T) {
|
||||
// Hugo have a byte slice, wants a byte slice and doesn't mind if the original is modified.
|
||||
|
||||
func BenchmarkEmojiKyokomiFprint(b *testing.B) {
|
||||
|
||||
f := func(in []byte) []byte {
|
||||
buff := bufferpool.GetBuffer()
|
||||
defer bufferpool.PutBuffer(buff)
|
||||
@@ -89,7 +88,6 @@ func BenchmarkEmojiKyokomiFprint(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkEmojiKyokomiSprint(b *testing.B) {
|
||||
|
||||
f := func(in []byte) []byte {
|
||||
return []byte(emoji.Sprint(string(in)))
|
||||
}
|
||||
@@ -102,7 +100,6 @@ func BenchmarkHugoEmoji(b *testing.B) {
|
||||
}
|
||||
|
||||
func doBenchmarkEmoji(b *testing.B, f func(in []byte) []byte) {
|
||||
|
||||
type input struct {
|
||||
in []byte
|
||||
expect []byte
|
||||
@@ -119,8 +116,8 @@ func doBenchmarkEmoji(b *testing.B, f func(in []byte) []byte) {
|
||||
{"No smiles for you or " + strings.Repeat("you ", 1000), "No smiles for you or " + strings.Repeat("you ", 1000)},
|
||||
}
|
||||
|
||||
var in = make([]input, b.N*len(data))
|
||||
var cnt = 0
|
||||
in := make([]input, b.N*len(data))
|
||||
cnt := 0
|
||||
for i := 0; i < b.N; i++ {
|
||||
for _, this := range data {
|
||||
in[cnt] = input{[]byte(this.input), []byte(this.expect)}
|
||||
@@ -142,6 +139,5 @@ func doBenchmarkEmoji(b *testing.B, f func(in []byte) []byte) {
|
||||
b.Fatalf("[%d] emoji std, got \n%q but expected \n%q", j, result, currIn.expect)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -157,7 +157,6 @@ func ReaderToString(lines io.Reader) string {
|
||||
|
||||
// ReaderContains reports whether subslice is within r.
|
||||
func ReaderContains(r io.Reader, subslice []byte) bool {
|
||||
|
||||
if r == nil || len(subslice) == 0 {
|
||||
return false
|
||||
}
|
||||
@@ -345,7 +344,6 @@ func InitLoggers() {
|
||||
func Deprecated(item, alternative string, err bool) {
|
||||
if err {
|
||||
DistinctErrorLog.Printf("%s is deprecated and will be removed in Hugo %s. %s", item, hugo.CurrentVersion.Next().ReleaseVersion(), alternative)
|
||||
|
||||
} else {
|
||||
DistinctWarnLog.Printf("%s is deprecated and will be removed in a future release. %s", item, alternative)
|
||||
}
|
||||
|
@@ -219,7 +219,6 @@ func TestGetTitleFunc(t *testing.T) {
|
||||
c.Assert(GetTitleFunc("ap")(title), qt.Equals, "Somewhere Over the Rainbow")
|
||||
c.Assert(GetTitleFunc("")(title), qt.Equals, "Somewhere Over the Rainbow")
|
||||
c.Assert(GetTitleFunc("unknown")(title), qt.Equals, "Somewhere Over the Rainbow")
|
||||
|
||||
}
|
||||
|
||||
func BenchmarkReaderContains(b *testing.B) {
|
||||
@@ -354,7 +353,6 @@ func BenchmarkMD5FromFileFast(b *testing.B) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func BenchmarkUniqueStrings(b *testing.B) {
|
||||
@@ -406,7 +404,6 @@ func BenchmarkUniqueStrings(b *testing.B) {
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func TestHashString(t *testing.T) {
|
||||
|
@@ -36,10 +36,8 @@ import (
|
||||
"github.com/spf13/afero"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrThemeUndefined is returned when a theme has not be defined by the user.
|
||||
ErrThemeUndefined = errors.New("no theme set")
|
||||
)
|
||||
// ErrThemeUndefined is returned when a theme has not be defined by the user.
|
||||
var ErrThemeUndefined = errors.New("no theme set")
|
||||
|
||||
// filepathPathBridge is a bridge for common functionality in filepath vs path
|
||||
type filepathPathBridge interface {
|
||||
@@ -169,7 +167,6 @@ func ReplaceExtension(path string, newExt string) string {
|
||||
}
|
||||
|
||||
func makePathRelative(inPath string, possibleDirectories ...string) (string, error) {
|
||||
|
||||
for _, currentPath := range possibleDirectories {
|
||||
if strings.HasPrefix(inPath, currentPath) {
|
||||
return strings.TrimPrefix(inPath, currentPath), nil
|
||||
@@ -281,7 +278,6 @@ func fileAndExt(in string, b filepathPathBridge) (name string, ext string) {
|
||||
}
|
||||
|
||||
func extractFilename(in, ext, base, pathSeparator string) (name string) {
|
||||
|
||||
// No file name cases. These are defined as:
|
||||
// 1. any "in" path that ends in a pathSeparator
|
||||
// 2. any "base" consisting of just an pathSeparator
|
||||
@@ -299,7 +295,6 @@ func extractFilename(in, ext, base, pathSeparator string) (name string) {
|
||||
name = base
|
||||
}
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
// GetRelativePath returns the relative path of a given path.
|
||||
@@ -474,21 +469,18 @@ func ExtractRootPaths(paths []string) []string {
|
||||
r[i] = root
|
||||
}
|
||||
return r
|
||||
|
||||
}
|
||||
|
||||
// FindCWD returns the current working directory from where the Hugo
|
||||
// executable is run.
|
||||
func FindCWD() (string, error) {
|
||||
serverFile, err := filepath.Abs(os.Args[0])
|
||||
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("can't get absolute path for executable: %v", err)
|
||||
}
|
||||
|
||||
path := filepath.Dir(serverFile)
|
||||
realFile, err := filepath.EvalSymlinks(serverFile)
|
||||
|
||||
if err != nil {
|
||||
if _, err = os.Stat(serverFile + ".exe"); err == nil {
|
||||
realFile = filepath.Clean(serverFile + ".exe")
|
||||
@@ -516,7 +508,6 @@ func SymbolicWalk(fs afero.Fs, root string, walker hugofs.WalkFunc) error {
|
||||
})
|
||||
|
||||
return w.Walk()
|
||||
|
||||
}
|
||||
|
||||
// LstatIfPossible can be used to call Lstat if possible, else Stat.
|
||||
@@ -555,7 +546,6 @@ func OpenFilesForWriting(fs afero.Fs, filenames ...string) (io.WriteCloser, erro
|
||||
}
|
||||
|
||||
return hugio.NewMultiWriteCloser(writeClosers...), nil
|
||||
|
||||
}
|
||||
|
||||
// OpenFileForWriting opens or creates the given file. If the target directory
|
||||
@@ -598,7 +588,6 @@ func GetCacheDir(fs afero.Fs, cfg config.Provider) (string, error) {
|
||||
|
||||
// Fall back to a cache in /tmp.
|
||||
return GetTempDir("hugo_cache", fs), nil
|
||||
|
||||
}
|
||||
|
||||
func getCacheDir(cfg config.Provider) string {
|
||||
@@ -614,7 +603,6 @@ func getCacheDir(cfg config.Provider) string {
|
||||
// is this project:
|
||||
// https://github.com/philhawksworth/content-shards/blob/master/gulpfile.js
|
||||
return "/opt/build/cache/hugo_cache/"
|
||||
|
||||
}
|
||||
|
||||
// This will fall back to an hugo_cache folder in the tmp dir, which should work fine for most CI
|
||||
|
@@ -184,7 +184,6 @@ func TestGetDottedRelativePath(t *testing.T) {
|
||||
for _, f := range []func(string) string{filepath.FromSlash, func(s string) string { return s }} {
|
||||
doTestGetDottedRelativePath(f, t)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func doTestGetDottedRelativePath(urlFixer func(string) string, t *testing.T) {
|
||||
@@ -422,7 +421,6 @@ func createTempDirWithZeroLengthFiles() (string, error) {
|
||||
}
|
||||
// the dir now has one, zero length file in it
|
||||
return d, nil
|
||||
|
||||
}
|
||||
|
||||
func createTempDirWithNonZeroLengthFiles() (string, error) {
|
||||
@@ -451,7 +449,6 @@ func createTempDirWithNonZeroLengthFiles() (string, error) {
|
||||
|
||||
// the dir now has one, zero length file in it
|
||||
return d, nil
|
||||
|
||||
}
|
||||
|
||||
func deleteTempDir(d string) {
|
||||
@@ -490,7 +487,6 @@ func TestExists(t *testing.T) {
|
||||
t.Errorf("Test %d failed. Expected %q got %q", i, d.expectedErr, err)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestAbsPathify(t *testing.T) {
|
||||
@@ -544,7 +540,6 @@ func TestAbsPathify(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestExtNoDelimiter(t *testing.T) {
|
||||
@@ -611,15 +606,12 @@ func TestFileAndExt(t *testing.T) {
|
||||
t.Errorf("Test %d failed. Expected extension %q got %q.", i, d.expectedExt, ext)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestPathPrep(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestPrettifyPath(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestExtractAndGroupRootPaths(t *testing.T) {
|
||||
@@ -642,16 +634,19 @@ func TestExtractAndGroupRootPaths(t *testing.T) {
|
||||
|
||||
// Make sure the original is preserved
|
||||
c.Assert(in, qt.DeepEquals, inCopy)
|
||||
|
||||
}
|
||||
|
||||
func TestExtractRootPaths(t *testing.T) {
|
||||
tests := []struct {
|
||||
input []string
|
||||
expected []string
|
||||
}{{[]string{filepath.FromSlash("a/b"), filepath.FromSlash("a/b/c/"), "b",
|
||||
filepath.FromSlash("/c/d"), filepath.FromSlash("d/"), filepath.FromSlash("//e//")},
|
||||
[]string{"a", "a", "b", "c", "d", "e"}}}
|
||||
}{{
|
||||
[]string{
|
||||
filepath.FromSlash("a/b"), filepath.FromSlash("a/b/c/"), "b",
|
||||
filepath.FromSlash("/c/d"), filepath.FromSlash("d/"), filepath.FromSlash("//e//"),
|
||||
},
|
||||
[]string{"a", "a", "b", "c", "d", "e"},
|
||||
}}
|
||||
|
||||
for _, test := range tests {
|
||||
output := ExtractRootPaths(test.input)
|
||||
@@ -667,7 +662,7 @@ func TestFindCWD(t *testing.T) {
|
||||
expectedErr error
|
||||
}
|
||||
|
||||
//cwd, _ := os.Getwd()
|
||||
// cwd, _ := os.Getwd()
|
||||
data := []test{
|
||||
//{cwd, nil},
|
||||
// Commenting this out. It doesn't work properly.
|
||||
|
@@ -45,7 +45,6 @@ func NewPathSpec(fs *hugofs.Fs, cfg config.Provider, logger loggers.Logger) (*Pa
|
||||
// NewPathSpecWithBaseBaseFsProvided creats a new PathSpec from the given filesystems and language.
|
||||
// If an existing BaseFs is provided, parts of that is reused.
|
||||
func NewPathSpecWithBaseBaseFsProvided(fs *hugofs.Fs, cfg config.Provider, logger loggers.Logger, baseBaseFs *filesystems.BaseFs) (*PathSpec, error) {
|
||||
|
||||
p, err := paths.New(fs, cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -85,5 +84,4 @@ func (p *PathSpec) PermalinkForBaseURL(link, baseURL string) string {
|
||||
baseURL += "/"
|
||||
}
|
||||
return baseURL + link
|
||||
|
||||
}
|
||||
|
@@ -56,5 +56,4 @@ func TestNewPathSpecFromConfig(t *testing.T) {
|
||||
c.Assert(p.BaseURL.String(), qt.Equals, "http://base.com")
|
||||
c.Assert(p.ThemesDir, qt.Equals, "thethemes")
|
||||
c.Assert(p.WorkingDir, qt.Equals, "thework")
|
||||
|
||||
}
|
||||
|
@@ -83,7 +83,6 @@ func (s *ProcessingStats) Table(w io.Writer) {
|
||||
table.SetHeader([]string{"", s.Name})
|
||||
table.SetBorder(false)
|
||||
table.Render()
|
||||
|
||||
}
|
||||
|
||||
// ProcessingStatsTable writes a table-formatted representation of stats to w.
|
||||
@@ -108,7 +107,6 @@ func ProcessingStatsTable(w io.Writer, stats ...*ProcessingStats) {
|
||||
} else {
|
||||
data[j] = append(data[j], strconv.Itoa(int(tv.val)))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -119,5 +117,4 @@ func ProcessingStatsTable(w io.Writer, stats ...*ProcessingStats) {
|
||||
table.SetHeader(names)
|
||||
table.SetBorder(false)
|
||||
table.Render()
|
||||
|
||||
}
|
||||
|
@@ -32,7 +32,6 @@ func newTestCfgFor(fs *hugofs.Fs) *viper.Viper {
|
||||
v.SetFs(fs.Source)
|
||||
|
||||
return v
|
||||
|
||||
}
|
||||
|
||||
func newTestCfg() *viper.Viper {
|
||||
|
@@ -83,7 +83,7 @@ func sanitizeURLWithFlags(in string, f purell.NormalizationFlags) string {
|
||||
return u.String()
|
||||
// End temporary kludge
|
||||
|
||||
//return s
|
||||
// return s
|
||||
|
||||
}
|
||||
|
||||
@@ -103,7 +103,6 @@ func SanitizeURLKeepTrailingSlash(in string) string {
|
||||
// urlize: vim-text-editor
|
||||
func (p *PathSpec) URLize(uri string) string {
|
||||
return p.URLEscape(p.MakePathSanitized(uri))
|
||||
|
||||
}
|
||||
|
||||
// URLizeFilename creates an URL from a filename by esacaping unicode letters
|
||||
@@ -130,7 +129,6 @@ func (p *PathSpec) URLEscape(uri string) string {
|
||||
// path: post/how-i-blog
|
||||
// result: http://spf13.com/post/how-i-blog
|
||||
func MakePermalink(host, plink string) *url.URL {
|
||||
|
||||
base, err := url.Parse(host)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -275,7 +273,6 @@ func (p *PathSpec) RelURL(in string, addLanguage bool) string {
|
||||
// For relative URL entries on sites with a base url with a context root set (i.e. http://example.com/mysite),
|
||||
// relative URLs must not include the context root if canonifyURLs is enabled. But if it's disabled, it must be set.
|
||||
func AddContextRoot(baseURL, relativePath string) string {
|
||||
|
||||
url, err := url.Parse(baseURL)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
@@ -23,7 +23,6 @@ import (
|
||||
)
|
||||
|
||||
func TestURLize(t *testing.T) {
|
||||
|
||||
v := newTestCfg()
|
||||
l := langs.NewDefaultLanguage(v)
|
||||
p, _ := NewPathSpec(hugofs.NewMem(v), l, nil)
|
||||
@@ -113,7 +112,6 @@ func doTestAbsURL(t *testing.T, defaultInSubDir, addLanguage, multilingual bool,
|
||||
} else {
|
||||
expected = strings.Replace(expected, "MULTI", lang+"/", 1)
|
||||
}
|
||||
|
||||
} else {
|
||||
expected = strings.Replace(expected, "MULTI", "", 1)
|
||||
}
|
||||
@@ -294,7 +292,6 @@ func TestURLPrep(t *testing.T) {
|
||||
t.Errorf("Test #%d failed. Expected %q got %q", i, d.output, output)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestAddContextRoot(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user