ref: a883948c4fa6d6de9ef2912709b42655c4cead83
parent: bc36d468ab56b5bcf01c3dc1478b1818dd17e4ff
author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
date: Tue Apr 4 14:05:19 EDT 2017
Register all media types when in server mode Fixes #3274
--- a/commands/server.go
+++ b/commands/server.go
@@ -24,8 +24,6 @@
"strings"
"time"
- "mime"
-
"github.com/spf13/afero"
"github.com/spf13/cobra"
"github.com/spf13/hugo/config"
@@ -95,9 +93,6 @@
serverCmd.RunE = server
- mime.AddExtensionType(".json", "application/json; charset=utf-8")
- mime.AddExtensionType(".css", "text/css; charset=utf-8")
-
}
func server(cmd *cobra.Command, args []string) error {
@@ -166,6 +161,10 @@
if err := c.build(serverWatch); err != nil {
return err
+ }
+
+ for _, s := range Hugo.Sites {
+ s.RegisterMediaTypes()
}
// Watch runs its own server as part of the routine
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -18,6 +18,7 @@
"fmt"
"html/template"
"io"
+ "mime"
"net/url"
"os"
"path/filepath"
@@ -608,6 +609,15 @@
type whatChanged struct {
source bool
other bool
+}
+
+// RegisterMediaTypes will register the Site's media types in the mime
+// package, so it will behave correctly with Hugo's built-in server.
+func (s *Site) RegisterMediaTypes() {
+ for _, mt := range s.mediaTypesConfig {
+ // The last one will win if there are any duplicates.
+ mime.AddExtensionType("."+mt.Suffix, mt.Type()+"; charset=utf-8")
+ }
}
// reBuild partially rebuilds a site given the filesystem events.
--- a/media/mediaType.go
+++ b/media/mediaType.go
@@ -177,5 +177,3 @@
return m, nil
}
-
-// TODO(bep) output mime.AddExtensionType
--
⑨