pull/60/merge
Henrique Dias 2017-01-03 21:21:40 +00:00
parent af8dbc2180
commit b192da1982
5 changed files with 167 additions and 141 deletions

18
.editorconfig Normal file
View File

@ -0,0 +1,18 @@
# EditorConfig is awesome: http://EditorConfig.org
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
# 4 space indentation
[*.go]
indent_style = tab
indent_size = 4

22
.jsbeautifyrc Normal file
View File

@ -0,0 +1,22 @@
{
"html": {
"brace_style": "collapse",
"indent_scripts": "normal",
"max_preserve_newlines": 1,
"preserve_newlines": true,
"unformatted": ["a", "sub", "sup", "b", "i", "u"],
"wrap_line_length": 0
},
"css": {
"end_with_newline": false,
"newline_between_rules": true,
"selector_separator": " ",
"selector_separator_newline": true
},
"js": {
"indent_with_tabs": false,
"preserve_newlines": true,
"max_preserve_newlines": 2,
"jslint_happy": true
}
}

View File

@ -1,32 +0,0 @@
{
"js": {
"allowed_file_extensions": ["js", "json", "jshintrc", "jsbeautifyrc"],
// Set brace_style
// collapse: (old default) Put braces on the same line as control statements
// collapse-preserve-inline: (new default) Same as collapse but better support for ES6 destructuring and other features. https://github.com/victorporof/Sublime-HTMLPrettify/issues/231
// expand: Put braces on own line (Allman / ANSI style)
// end-expand: Put end braces on own line
// none: Keep them where they are
"brace_style": "collapse-preserve-inline",
"break_chained_methods": false, // Break chained method calls across subsequent lines
"e4x": false, // Pass E4X xml literals through untouched
"end_with_newline": false, // End output with newline
"indent_char": " ", // Indentation character
"indent_level": 0, // Initial indentation level
"indent_size": 4, // Indentation size
"indent_with_tabs": false, // Indent with tabs, overrides `indent_size` and `indent_char`
"jslint_happy": false, // If true, then jslint-stricter mode is enforced
"keep_array_indentation": false, // Preserve array indentation
"keep_function_indentation": false, // Preserve function indentation
"max_preserve_newlines": 0, // Maximum number of line breaks to be preserved in one chunk (0 disables)
"preserve_newlines": true, // Whether existing line breaks should be preserved
"space_after_anon_function": false, // Should the space before an anonymous function's parens be added, "function()" vs "function ()"
"space_before_conditional": true, // Should the space before conditional statement be added, "if(true)" vs "if (true)"
"space_in_empty_paren": false, // Add padding spaces within empty paren, "f()" vs "f( )"
"space_in_paren": false, // Add padding spaces within paren, ie. f( a, b )
"unescape_strings": false, // Should printable characters in strings encoded in \xNN notation be unescaped, "example" vs "\x65\x78\x61\x6d\x70\x6c\x65"
"wrap_line_length": 0 // Lines should wrap at next opportunity after this number of characters (0 disables)
}
}

View File

@ -1,88 +1,124 @@
'use strict'; 'use strict';
document.addEventListener('DOMContentLoaded', event => { document.addEventListener('DOMContentLoaded', event => {
document.querySelector('#top-bar > div > p:first-child').innerHTML = 'Hugo for Caddy'
document.querySelector('footer').innerHTML += ' With a flavour of <a rel="noopener noreferrer" href="https://github.com/hacdias/caddy-hugo">Hugo</a>.'; document.querySelector('footer').innerHTML += ' With a flavour of <a rel="noopener noreferrer" href="https://github.com/hacdias/caddy-hugo">Hugo</a>.';
document.querySelector('.only-side > p > a').innerHTML = "Hugo";
let link = document.querySelector('.only-side > p a:first-child').getAttribute('href') + "/settings/" document.querySelector('#bottom-bar>*:first-child').style.maxWidth = "calc(100% - 27em)"
document.getElementById('logout').insertAdjacentHTML('beforebegin', `<a href="${link}">
let link = baseURL + "/settings/"
document.getElementById('info').insertAdjacentHTML('beforebegin', `<a href="${link}">
<div class="action"> <div class="action">
<i class="material-icons">settings</i> <i class="material-icons">settings</i>
<span>Settings</span> <span>Settings</span>
</div> </div>
</a>`); </a>`);
});
document.addEventListener('listing', event => { if(buttons.new && window.location.pathname === baseURL + "/content/") {
if (window.location.pathname.includes('/content/')) { buttons.new.removeEventListener('click', listing.newFileButton);
document.getElementById('newdir').placeholder = "file[:archetype]..."; buttons.new.addEventListener('click', hugo.newFileButton);
document.getElementById('newdir').removeEventListener('keydown', newDirEvent);
document.getElementById('newdir').addEventListener('keydown', event => {
if (event.keyCode == 27) {
document.getElementById('newdir').classList.toggle('enabled');
setTimeout(() => {
document.getElementById('newdir').value = '';
}, 200);
} }
if (event.keyCode == 13) { if(buttons.save) {
event.preventDefault(); let box = document.getElementById('file-only');
box.insertAdjacentHTML('beforeend', `<div class="action" id="publish">
<i class="material-icons">send</i>
<span>Publish</span>
</div>`);
buttons.publish = document.getElementById('publish')
buttons.publish.addEventListener('click', hugo.publish)
if((document.getElementById('date') || document.getElementById('publishdate')) &&
document.getElementById('editor').dataset.kind == "complete") {
box.insertAdjacentHTML('beforeend', ` <div class="action" id="schedule">
<i class="material-icons">alarm</i>
<span>Schedule</span>
</div>`);
buttons.schedule = document.getElementById('schedule')
buttons.schedule.addEventListener('click', hugo.schedule)
}
document.querySelector('#bottom-bar>*:first-child').style.maxWidth = "calc(100% - 30em)"
}
});
var hugo = {};
hugo.newFileButton = function (event) {
event.preventDefault();
event.stopPropagation();
let clone = document.importNode(templates.question.content, true);
clone.querySelector('h3').innerHTML = 'New file';
clone.querySelector('p').innerHTML = 'End with a trailing slash to create a dir. To use an archetype, use <code>file[:archetype]</code>.';
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);
let value = document.getElementById('newdir').value;
let index = value.lastIndexOf(':');
let name = value.substring(0, index);
let archetype = value.substring(index + 1, value.length);
if(name == "") name = archetype; if(name == "") name = archetype;
if(index == -1) archetype = ""; if(index == -1) archetype = "";
let button = document.getElementById('new'); webdav.new(window.location.pathname + name, '', {
let html = button.changeToLoading(); 'Filename': name,
let request = new XMLHttpRequest(); 'Archetype': archetype
request.open("PUT", toWebDavURL(window.location.pathname + name)); })
request.setRequestHeader('Filename', name); .then(() => {
request.setRequestHeader('Archetype', archetype); buttons.setDone('new');
request.send();
request.onreadystatechange = function() {
if (request.readyState == 4) {
if (request.status != 200 && request.status != 201) {
button.changeToDone(true, html);
return;
}
button.changeToDone(false, html);
window.location = window.location.pathname + name; window.location = window.location.pathname + name;
} })
} .catch(e => {
} console.log(e);
}); buttons.setDone('new', false);
}
}); });
document.addEventListener('editor', event => { closePrompt(event);
let container = document.getElementById('editor'), return false;
kind = container.dataset.kind; }
document.getElementById('submit').insertAdjacentHTML('afterend', `<div class="right"> hugo.publish = function (event) {
<button id="publish"> event.preventDefault();
<span>
<i class="material-icons">send</i>
</span>
<span>publish</span>
</button>
</div>`);
if ((document.getElementById('date') || document.getElementById('publishdate')) && document.getElementById('editor').dataset.kind == "complete") { if(document.getElementById('draft')) {
document.querySelector('#editor .right').insertAdjacentHTML('afterbegin', ` <button id="schedule"> document.getElementById('block-draft').remove();
<span> }
<i class="material-icons">alarm</i>
</span>
<span>Schedule</span>
</button>`);
let button = document.querySelector('#schedule span:first-child'); buttons.setLoading('publish');
document.getElementById('schedule').addEventListener('click', event => { 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(); event.preventDefault();
let date = document.getElementById('date').value; let date = document.getElementById('date').value;
@ -90,41 +126,20 @@ document.addEventListener('editor', event => {
date = document.getElementById('publishDate').value; date = document.getElementById('publishDate').value;
} }
let data = form2js(document.querySelector('form')); buttons.setLoading('publish');
let html = button.changeToLoading();
let request = new XMLHttpRequest();
request.open("PUT", toWebDavURL(window.location.pathname));
request.setRequestHeader('Kind', kind);
request.setRequestHeader('Schedule', date);
request.send(JSON.stringify(data));
request.onreadystatechange = function() {
if (request.readyState == 4) {
button.changeToDone((request.status != 200 && request.status != 201), html);
}
}
});
}
document.getElementById('publish').addEventListener('click', event => { let data = JSON.stringify(form2js(document.querySelector('form'))),
event.preventDefault(); headers = {
'Kind': document.getElementById('editor').dataset.kind,
'Schedule': 'true'
};
if (document.getElementById('draft')) { webdav.put(window.location.pathname, data, headers)
document.getElementById('block-draft').remove(); .then(() => {
buttons.setDone('publish');
})
.catch(e => {
console.log(e);
buttons.setDone('publish', false)
})
} }
let button = document.querySelector('#publish span:first-child'),
data = form2js(document.querySelector('form')),
html = button.changeToLoading(),
request = new XMLHttpRequest();
request.open("PUT", toWebDavURL(window.location.pathname));
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 && request.status != 201), html);
}
}
});
});

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log" "log"
"net/http"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@ -94,6 +95,8 @@ func parse(c *caddy.Controller, root string) (*Config, *filemanager.FileManager,
cfg.Public = strings.Replace(root, "./", "", -1) cfg.Public = strings.Replace(root, "./", "", -1)
cfg.BaseURL = "/admin" cfg.BaseURL = "/admin"
cfg.Root = "./" cfg.Root = "./"
cfg.BeforePublish = func(r *http.Request, c *config.Config, u *config.User) error { return nil }
cfg.AfterPublish = func(r *http.Request, c *config.Config, u *config.User) error { return nil }
args := c.RemainingArgs() args := c.RemainingArgs()