updates on #98

This commit is contained in:
Henrique Dias 2016-12-11 10:41:03 +00:00
parent 744d8c917e
commit 76c91576cf
3 changed files with 19 additions and 13 deletions

View File

@ -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;
}
}
}

View File

@ -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 {

View File

@ -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
}