'use strict';
document.addEventListener('DOMContentLoaded', event => {
document.querySelector('#top-bar > div > p:first-child').innerHTML = 'Hugo for Caddy'
document.querySelector('footer').innerHTML += ' With a flavour of Hugo.';
document.querySelector('#bottom-bar>*:first-child').style.maxWidth = "calc(100% - 27em)"
let link = baseURL + "/settings/"
document.getElementById('info').insertAdjacentHTML('beforebegin', `
file[:archetype]
.';
clone.querySelector('.ok').innerHTML = 'Create';
clone.querySelector('form').addEventListener('submit', hugo.newFilePrompt);
document.querySelector('body').appendChild(clone)
document.querySelector('.overlay').classList.add('active');
document.querySelector('.prompt').classList.add('active');
}
hugo.newFilePrompt = function (event) {
event.preventDefault();
buttons.setLoading('new');
let value = event.currentTarget.querySelector('input').value,
index = value.lastIndexOf(':'),
name = value.substring(0, index),
archetype = value.substring(index + 1, value.length);
if(name == "") name = archetype;
if(index == -1) archetype = "";
webdav.new(window.location.pathname + name, '', {
'Filename': name,
'Archetype': archetype
})
.then(() => {
buttons.setDone('new');
window.location = window.location.pathname + name;
})
.catch(e => {
console.log(e);
buttons.setDone('new', false);
});
closePrompt(event);
return false;
}
hugo.publish = function (event) {
event.preventDefault();
if(document.getElementById('draft')) {
document.getElementById('block-draft').remove();
}
buttons.setLoading('publish');
let data = JSON.stringify(form2js(document.querySelector('form'))),
headers = {
'Kind': document.getElementById('editor').dataset.kind,
'Regenerate': 'true'
};
webdav.put(window.location.pathname, data, headers)
.then(() => {
buttons.setDone('publish');
})
.catch(e => {
console.log(e);
buttons.setDone('publish', false)
})
}
hugo.schedule = function (event) {
event.preventDefault();
let date = document.getElementById('date').value;
if(document.getElementById('publishDate')) {
date = document.getElementById('publishDate').value;
}
buttons.setLoading('publish');
let data = JSON.stringify(form2js(document.querySelector('form'))),
headers = {
'Kind': document.getElementById('editor').dataset.kind,
'Schedule': 'true'
};
webdav.put(window.location.pathname, data, headers)
.then(() => {
buttons.setDone('publish');
})
.catch(e => {
console.log(e);
buttons.setDone('publish', false)
})
}