regenerate button working

pull/82/head
Henrique Dias 2016-06-28 22:20:42 +01:00
parent 380d4fb60c
commit 3dd946d0ca
2 changed files with 51 additions and 14 deletions

View File

@ -6,25 +6,58 @@ document.addEventListener('DOMContentLoaded', event => {
<i class="material-icons">settings</i>
</div>
</a>`);
});
document.addEventListener('listing', event => {
document.getElementById('newdir').placeholder = "file[:archetype]...";
});
document.addEventListener('editor', event => {
document.getElementById('submit').insertAdjacentHTML('afterend', `<div class="right">
<button id="publish" type="submit" data-type="content-only">
<span>
<i class="material-icons">send</i>
</span>
<span>publish</span>
</button>
</div>`);
<button id="publish">
<span>
<i class="material-icons">send</i>
</span>
<span>publish</span>
</button>
</div>`);
if (document.getElementById('date') || document.getElementById('publishdate')) {
document.querySelector('#editor .right').insertAdjacentHTML('afterbegin', ` <button id="schedule" type="submit" data-type="content-only">
<span>
<i class="material-icons">alarm</i>
</span>
<span>Schedule</span>
</button>`);
document.querySelector('#editor .right').insertAdjacentHTML('afterbegin', ` <button id="schedule">
<span>
<i class="material-icons">alarm</i>
</span>
<span>Schedule</span>
</button>`);
document.getElementById('schedule').addEventListener('click', event => {
event.preventDefault();
});
}
document.getElementById('publish').addEventListener('click', event => {
console.log("Hey")
event.preventDefault();
if (document.getElementById('draft')) {
document.getElementById('block-draft').remove();
}
let container = document.getElementById('editor');
let kind = container.dataset.kind;
let button = document.querySelector('#publish span:first-child');
let data = form2js(document.querySelector('form'));
let html = button.changeToLoading();
let request = new XMLHttpRequest();
request.open("PUT", window.location);
request.setRequestHeader('Kind', kind);
request.setRequestHeader('Regenerate', "true");
request.send(JSON.stringify(data));
request.onreadystatechange = function() {
if (request.readyState == 4) {
button.changeToDone((request.status != 200), html);
}
}
});
});

View File

@ -74,8 +74,12 @@ func (h Hugo) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
if directory.CanBeEdited(r.URL.Path) && r.Method == http.MethodPut {
code, err := h.FileManager.ServeHTTP(w, r)
if err != nil {
return code, err
}
if r.Header.Get("Regenerate") == "true" {
go RunHugo(h.Config, false)
RunHugo(h.Config, false)
}
if r.Header.Get("Schedule") != "" {