diff --git a/assets/public/js/application.js b/assets/public/js/application.js index 98ae8d96..2c563b2f 100644 --- a/assets/public/js/application.js +++ b/assets/public/js/application.js @@ -39,16 +39,19 @@ document.addEventListener('listing', event => { let button = document.getElementById('new'); let html = button.changeToLoading(); let request = new XMLHttpRequest(); - request.open("POST", window.location); + request.open("PUT", toWebDavURL(window.location.pathname + name)); request.setRequestHeader('Filename', name); request.setRequestHeader('Archetype', archetype); request.send(); request.onreadystatechange = function() { if (request.readyState == 4) { - button.changeToDone((request.status != 200), html); - if (request.status == 200) { - window.location = window.location.pathname + name; + if (request.status != 200 && request.status != 201) { + button.changeToDone(true, html); + return; } + + button.changeToDone(false, html); + window.location = window.location.pathname + name; } } } diff --git a/hugo.go b/hugo.go index 741d1070..69166b94 100644 --- a/hugo.go +++ b/hugo.go @@ -73,7 +73,7 @@ func (h Hugo) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) { return 0, nil } - if r.Method == http.MethodPost && r.Header.Get("archetype") != "" { + if r.Method == http.MethodPut && r.Header.Get("archetype") != "" { filename := r.Header.Get("Filename") archetype := r.Header.Get("archetype") @@ -81,7 +81,7 @@ func (h Hugo) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) { return h.FileManager.ServeHTTP(w, r) } - filename = strings.Replace(r.URL.Path, h.Config.BaseURL+"/content/", "", 1) + filename + filename = strings.Replace(r.URL.Path, h.Config.BaseURL+h.Config.WebDavURL+"/content/", "", 1) filename = filepath.Clean(filename) args := []string{"new", filename, "--kind", archetype} @@ -90,7 +90,7 @@ func (h Hugo) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) { return http.StatusInternalServerError, err } - return http.StatusOK, nil + return http.StatusCreated, nil } if canBeEdited(r.URL.Path) && r.Method == http.MethodPut { diff --git a/setup.go b/setup.go index a4883a2a..b03bc5ad 100644 --- a/setup.go +++ b/setup.go @@ -62,12 +62,13 @@ func setup(c *caddy.Controller) error { // Config is a configuration for managing a particular hugo website. type Config struct { - Public string // Public content path - Root string // Hugo files path - Hugo string // Hugo executable location - Styles string // Admin styles path - Args []string // Hugo arguments - BaseURL string // BaseURL of admin interface + Public string // Public content path + Root string // Hugo files path + Hugo string // Hugo executable location + Styles string // Admin styles path + Args []string // Hugo arguments + BaseURL string // BaseURL of admin interface + WebDavURL string } // Parse parses the configuration set by the user so it can be @@ -152,6 +153,8 @@ func parse(c *caddy.Controller, root string) (*Config, *filemanager.FileManager, format := getFrontMatter(cfg) + cfg.WebDavURL = fm.Configs[0].WebDavURL + for _, user := range fm.Configs[0].Users { user.FrontMatter = format }