Skip to content

Commit

Permalink
More
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed May 10, 2024
1 parent 8590278 commit 02a9123
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 23 deletions.
7 changes: 4 additions & 3 deletions commands/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ import (
"github.com/fsnotify/fsnotify"
"github.com/gohugoio/hugo/common/herrors"
"github.com/gohugoio/hugo/common/hugo"
"github.com/gohugoio/hugo/media"

"github.com/gohugoio/hugo/common/types"
"github.com/gohugoio/hugo/common/urls"
"github.com/gohugoio/hugo/config"
"github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/hugofs"
"github.com/gohugoio/hugo/hugofs/files"
"github.com/gohugoio/hugo/hugolib"
"github.com/gohugoio/hugo/hugolib/filesystems"
"github.com/gohugoio/hugo/livereload"
Expand Down Expand Up @@ -1193,11 +1194,11 @@ func pickOneWriteOrCreatePath(events []fsnotify.Event) string {

for _, ev := range events {
if ev.Op&fsnotify.Write == fsnotify.Write || ev.Op&fsnotify.Create == fsnotify.Create {
if files.IsIndexContentFile(ev.Name) {
if media.IsIndexContentFile(ev.Name) {
return ev.Name
}

if files.IsContentFile(ev.Name) {
if media.IsContentFile(ev.Name) {
name = ev.Name
}

Expand Down
5 changes: 2 additions & 3 deletions create/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ import (
"strings"

"github.com/gohugoio/hugo/hugofs/glob"
"github.com/gohugoio/hugo/media"

"github.com/gohugoio/hugo/common/hexec"
"github.com/gohugoio/hugo/common/hstrings"
"github.com/gohugoio/hugo/common/paths"

"github.com/gohugoio/hugo/hugofs/files"

"github.com/gohugoio/hugo/hugofs"

"github.com/gohugoio/hugo/helpers"
Expand Down Expand Up @@ -98,7 +97,7 @@ func NewContent(h *hugolib.HugoSites, kind, targetPath string, force bool) error
return "", fmt.Errorf("failed to resolve %q to an archetype template", targetPath)
}

if !files.IsContentFile(b.targetPath) {
if !media.IsContentFile(b.targetPath) {
return "", fmt.Errorf("target path %q is not a known content format", b.targetPath)
}

Expand Down
14 changes: 0 additions & 14 deletions hugofs/files/classifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,6 @@ const (
FilenameHugoStatsJSON = "hugo_stats.json"
)

func IsContentFile(filename string) bool {
panic("not implemented")
}

func IsIndexContentFile(filename string) bool {
if !IsContentFile(filename) {
return false
}

base := filepath.Base(filename)

return strings.HasPrefix(base, "index.") || strings.HasPrefix(base, "_index.")
}

func IsGoTmplExt(ext string) bool {
return ext == "gotmpl"
}
Expand Down
2 changes: 1 addition & 1 deletion hugolib/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ Home.

enConfig := b.H.Sites[0].conf
m, _ := enConfig.MediaTypes.Config.GetByType("text/html")
b.Assert(m.Suffixes(), qt.DeepEquals, []string{"html"})
b.Assert(m.Suffixes(), qt.DeepEquals, []string{"html", "htm"})

svConfig := b.H.Sites[1].conf
f, _ := svConfig.OutputFormats.Config.GetByName("html")
Expand Down
4 changes: 3 additions & 1 deletion hugolib/page__meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,9 @@ func (p *pageState) setMetaPostParams() error {
if p.File().FileInfo() != nil {
mtime = p.File().FileInfo().ModTime()
}
ext = p.File().Ext()
if !p.File().IsMultipart() {
ext = p.File().Ext()
}
}

var gitAuthorDate time.Time
Expand Down
24 changes: 24 additions & 0 deletions media/builtin.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package media

import (
"path/filepath"
"strings"
)

type BuiltinTypes struct {
CalendarType Type
CSSType Type
Expand All @@ -20,6 +25,7 @@ type BuiltinTypes struct {
TextType Type
TOMLType Type
YAMLType Type
GoTmplType Type

// Common image types
PNGType Type
Expand Down Expand Up @@ -95,6 +101,7 @@ var Builtin = BuiltinTypes{
PandocType: Type{Type: "text/x-pandoc"},
ReStructuredTextType: Type{Type: "text/x-restructuredtext"},
EmacsOrgModeType: Type{Type: "text/org"},
GoTmplType: Type{Type: "text/x-gotmpl"},

// Common video types
AVIType: Type{Type: "video/x-msvideo"},
Expand Down Expand Up @@ -150,6 +157,7 @@ var defaultMediaTypesConfig = map[string]any{
"text/x-pandoc": map[string]any{"suffixes": []string{"pandoc", "pdc"}},
"text/x-restructuredtext": map[string]any{"suffixes": []string{"rst"}},
"text/org": map[string]any{"suffixes": []string{"org"}},
"text/x-gotmpl": map[string]any{"suffixes": []string{"gotmpl"}},

// Common video types
"video/x-msvideo": map[string]any{"suffixes": []string{"avi"}},
Expand All @@ -173,6 +181,22 @@ func IsContentSuffix(suffix string) bool {
return contentMediaTypesExtensionsSet[suffix]
}

// IsContentFile returns whether the given filename is a content file.
func IsContentFile(filename string) bool {
return IsContentSuffix(strings.TrimPrefix(filepath.Ext(filename), "."))
}

// IsIndexContentFile returns whether the given filename is an index content file.
func IsIndexContentFile(filename string) bool {
if !IsContentFile(filename) {
return false
}

base := filepath.Base(filename)

return strings.HasPrefix(base, "index.") || strings.HasPrefix(base, "_index.")
}

// IsHTMLSuffix returns whether the given suffix is a HTML media type.
func IsHTMLSuffix(suffix string) bool {
for _, suffix := range Builtin.HTMLType.Suffixes() {
Expand Down
3 changes: 2 additions & 1 deletion media/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func TestDefaultTypes(t *testing.T) {
{Builtin.EmacsOrgModeType, "text", "org", "org", "text/org", "text/org"},
{Builtin.PandocType, "text", "x-pandoc", "pandoc,pdc", "text/x-pandoc", "text/x-pandoc"},
{Builtin.ReStructuredTextType, "text", "x-restructuredtext", "rst", "text/x-restructuredtext", "text/x-restructuredtext"},
{Builtin.GoTmplType, "text", "x-gotmpl", "gotmpl", "text/x-gotmpl", "text/x-gotmpl"},
{Builtin.AsciiDocType, "text", "x-asciidoc", "adoc,asciidoc,ad", "text/x-asciidoc", "text/x-asciidoc"},
{Builtin.JavascriptType, "text", "javascript", "js,jsm,mjs", "text/javascript", "text/javascript"},
{Builtin.TypeScriptType, "text", "typescript", "ts", "text/typescript", "text/typescript"},
Expand All @@ -151,5 +152,5 @@ func TestDefaultTypes(t *testing.T) {

}

c.Assert(len(DefaultTypes), qt.Equals, 40)
c.Assert(len(DefaultTypes), qt.Equals, 41)
}

0 comments on commit 02a9123

Please sign in to comment.