mirror of
https://github.com/filebrowser/filebrowser.git
synced 2024-06-07 23:00:43 +00:00
update config
This commit is contained in:
parent
3dd946d0ca
commit
f5b4b43248
28
setup.go
28
setup.go
@ -5,16 +5,20 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/hacdias/caddy-filemanager"
|
"github.com/hacdias/caddy-filemanager"
|
||||||
"github.com/hacdias/caddy-filemanager/config"
|
"github.com/hacdias/caddy-filemanager/config"
|
||||||
|
"github.com/hacdias/caddy-filemanager/directory"
|
||||||
|
"github.com/hacdias/caddy-filemanager/frontmatter"
|
||||||
"github.com/hacdias/caddy-hugo/installer"
|
"github.com/hacdias/caddy-hugo/installer"
|
||||||
"github.com/hacdias/caddy-hugo/utils/commands"
|
"github.com/hacdias/caddy-hugo/utils/commands"
|
||||||
"github.com/mholt/caddy"
|
"github.com/mholt/caddy"
|
||||||
"github.com/mholt/caddy/caddyhttp/httpserver"
|
"github.com/mholt/caddy/caddyhttp/httpserver"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// AssetsURL is the base url for the assets
|
||||||
const AssetsURL = "/_hugointernal"
|
const AssetsURL = "/_hugointernal"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -30,19 +34,24 @@ func setup(c *caddy.Controller) error {
|
|||||||
cnf := httpserver.GetConfig(c)
|
cnf := httpserver.GetConfig(c)
|
||||||
conf, _ := parse(c, cnf.Root)
|
conf, _ := parse(c, cnf.Root)
|
||||||
|
|
||||||
|
format := "config.toml"
|
||||||
|
|
||||||
// Checks if there is an Hugo website in the path that is provided.
|
// Checks if there is an Hugo website in the path that is provided.
|
||||||
// If not, a new website will be created.
|
// If not, a new website will be created.
|
||||||
create := true
|
create := true
|
||||||
|
|
||||||
if _, err := os.Stat(conf.Root + "config.yaml"); err == nil {
|
if _, err := os.Stat(conf.Root + "config.yaml"); err == nil {
|
||||||
|
format = "yaml"
|
||||||
create = false
|
create = false
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := os.Stat(conf.Root + "config.json"); err == nil {
|
if _, err := os.Stat(conf.Root + "config.json"); err == nil {
|
||||||
|
format = "json"
|
||||||
create = false
|
create = false
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := os.Stat(conf.Root + "config.toml"); err == nil {
|
if _, err := os.Stat(conf.Root + "config.toml"); err == nil {
|
||||||
|
format = "toml"
|
||||||
create = false
|
create = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,6 +62,24 @@ func setup(c *caddy.Controller) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get Default FrontMatter
|
||||||
|
bytes, err := ioutil.ReadFile(filepath.Clean(conf.Root + "/config." + format))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes = directory.AppendFrontMatterRune(bytes, format)
|
||||||
|
f, err := frontmatter.Unmarshal(bytes)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, ok := f.(map[string]interface{})["metaDataFormat"]; ok {
|
||||||
|
format = val.(string)
|
||||||
|
}
|
||||||
|
|
||||||
// Generates the Hugo website for the first time the plugin is activated.
|
// Generates the Hugo website for the first time the plugin is activated.
|
||||||
go RunHugo(conf, true)
|
go RunHugo(conf, true)
|
||||||
|
|
||||||
@ -66,6 +93,7 @@ func setup(c *caddy.Controller) error {
|
|||||||
config.Config{
|
config.Config{
|
||||||
HugoEnabled: true,
|
HugoEnabled: true,
|
||||||
PathScope: conf.Root,
|
PathScope: conf.Root,
|
||||||
|
FrontMatter: format,
|
||||||
Root: http.Dir(conf.Root),
|
Root: http.Dir(conf.Root),
|
||||||
BaseURL: conf.BaseURL,
|
BaseURL: conf.BaseURL,
|
||||||
StyleSheet: conf.Styles,
|
StyleSheet: conf.Styles,
|
||||||
|
Loading…
Reference in New Issue
Block a user