This commit is contained in:
Henrique Dias 2015-09-17 21:26:06 +01:00
parent edf0a453a3
commit d847909da8
10 changed files with 236 additions and 81 deletions

File diff suppressed because one or more lines are too long

View File

@ -2540,6 +2540,22 @@ header h1 {
margin: 0; margin: 0;
} }
footer {
background-color: #ddd;
padding: 1.5em 0;
text-align: center;
color: rgba(0, 0, 0, 0.5);
}
footer a {
text-decoration: none;
color: inherit;
}
footer p {
margin: 0;
}
.content { .content {
margin: 1.5em auto; margin: 1.5em auto;
width: 80%; width: 80%;
@ -2678,6 +2694,10 @@ form legend {
font-size: 1.5em; font-size: 1.5em;
} }
input[type="file"] {
display: none;
}
button, button,
input[type="submit"] { input[type="submit"] {
border: 0; border: 0;
@ -2736,6 +2756,48 @@ h3:hover > button.add {
opacity: 1; opacity: 1;
} }
/* BROWSE */
.left {
text-align: left;
}
.right {
text-align: right;
}
.browse a {
color: inherit;
text-decoration: none;
}
.browse table {
width: 100%;
}
.browse .actions {
background-color: #455a64;
color: #fff;
padding: 1.5em 0;
}
.actions .content {
margin: 0 auto;
display: flex;
}
.actions .fa {
vertical-align: middle;
}
.actions .go-right {
margin-left: auto;
}
.browse tr {
line-height: 2em;
border-bottom: 1px solid rgba(0, 0, 0, 0.03);
}
/* perfect-scrollbar v0.6.5 */ /* perfect-scrollbar v0.6.5 */
.ps-container { .ps-container {
-ms-touch-action: none; -ms-touch-action: none;

View File

@ -82,6 +82,22 @@ header h1 {
margin: 0; margin: 0;
} }
footer {
background-color: #ddd;
padding : 1.5em 0;
text-align : center;
color : rgba(0,0,0,0.5);
}
footer a {
text-decoration: none;
color : inherit;
}
footer p {
margin: 0;
}
.content { .content {
margin : 1.5em auto; margin : 1.5em auto;
width : 80%; width : 80%;
@ -220,6 +236,10 @@ form legend {
font-size: 1.5em; font-size: 1.5em;
} }
input[type="file"] {
display: none;
}
button, button,
input[type="submit"] { input[type="submit"] {
border : 0; border : 0;
@ -277,5 +297,47 @@ button.add {
h3:hover > button.add { h3:hover > button.add {
opacity: 1; opacity: 1;
} }
/* BROWSE */
.left {
text-align: left;
}
.right {
text-align: right;
}
.browse a {
color : inherit;
text-decoration: none;
}
.browse table {
width: 100%;
}
.browse .actions {
background-color: #455a64;
color : #fff;
padding : 1.5em 0;
}
.actions .content {
margin : 0 auto;
display: flex;
}
.actions .fa {
vertical-align: middle;
}
.actions .go-right {
margin-left: auto;
}
.browse tr {
line-height : 2em;
border-bottom: 1px solid rgba(0,0,0,0.03);
}
@import "scrollbar"; @import "scrollbar";
@import "notifications"; @import "notifications";

File diff suppressed because one or more lines are too long

View File

@ -3,10 +3,12 @@ $(document).ready(function() {
}); });
$(document).on('ready pjax:success', function() { $(document).on('ready pjax:success', function() {
// Starts the perfect scroolbar plugin
$('.scroll').perfectScrollbar(); $('.scroll').perfectScrollbar();
$("#preview").click(function(e) { // Toggles between preview and editing mode
e.preventDefault(); $("#preview").click(function(event) {
event.preventDefault();
var preview = $("#preview-area"), var preview = $("#preview-area"),
editor = $('.editor textarea'); editor = $('.editor textarea');
@ -40,6 +42,7 @@ $(document).on('ready pjax:success', function() {
return false; return false;
}); });
// Submites any form in the page in JSON format
$('form').submit(function(event) { $('form').submit(function(event) {
event.preventDefault(); event.preventDefault();
@ -51,8 +54,8 @@ $(document).on('ready pjax:success', function() {
type: 'POST', type: 'POST',
url: url, url: url,
data: data, data: data,
beforeSend: function(xhr) { headers: {
xhr.setRequestHeader('X-Regenerate', button.data("regenerate")); 'X-Regenerate': button.data("regenerate")
}, },
dataType: 'json', dataType: 'json',
encode: true, encode: true,
@ -71,24 +74,27 @@ $(document).on('ready pjax:success', function() {
}); });
}); });
// Log out the user sending bad credentials to the server
$("#logout").click(function(e) { $("#logout").click(function(e) {
e.preventDefault(); e.preventDefault();
jQuery.ajax({ $.ajax({
type: "GET", type: "GET",
url: "/admin", url: "/admin",
async: false, async: false,
username: "logmeout", username: "username",
password: "123456", password: "password",
headers: { headers: {
"Authorization": "Basic xxx" "Authorization": "Basic xxx"
} }
}) }).fail(function() {
.fail(function() { window.location = "/";
window.location = "/"; });
});
return false; return false;
}); });
// Adds one more field to the current group
// TODO: improve this function. add group/field/array/obj
$(".add").click(function(e) { $(".add").click(function(e) {
e.preventDefault(); e.preventDefault();
fieldset = $(this).closest("fieldset"); fieldset = $(this).closest("fieldset");

21
hugo.go
View File

@ -32,9 +32,16 @@ type handler struct{ Next middleware.Handler }
func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) { func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
if middleware.Path(r.URL.Path).Matches("/admin") { if middleware.Path(r.URL.Path).Matches("/admin") {
page := utils.ParseComponents(r)[1] page := utils.ParseComponents(r)[1]
code := 400 code := 404
var err error var err error
if page != "assets" && page != "edit" {
if r.URL.Path[len(r.URL.Path)-1] != '/' {
http.Redirect(w, r, r.URL.Path+"/", http.StatusTemporaryRedirect)
return 0, nil
}
}
if page == "assets" { if page == "assets" {
filename := strings.Replace(r.URL.Path, "/admin/", "", 1) filename := strings.Replace(r.URL.Path, "/admin/", "", 1)
file, err := assets.Asset(filename) file, err := assets.Asset(filename)
@ -51,11 +58,17 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)
w.Write(file) w.Write(file)
return 200, nil return 200, nil
} else if page == "browse" { }
if page == "browse" {
code, err = browse.Execute(w, r) code, err = browse.Execute(w, r)
} else if page == "edit" { }
if page == "edit" {
code, err = edit.Execute(w, r) code, err = edit.Execute(w, r)
} else if page == "settings" { }
if r.URL.Path == "/admin/settings/" {
code, err = settings.Execute(w, r) code, err = settings.Execute(w, r)
} }

View File

@ -15,6 +15,7 @@ const (
var funcMap = template.FuncMap{ var funcMap = template.FuncMap{
"splitCapitalize": utils.SplitCapitalize, "splitCapitalize": utils.SplitCapitalize,
"isMarkdown": utils.IsMarkdownFile,
} }
// Page type // Page type

View File

@ -26,8 +26,7 @@
<div class="main" id="container"> <div class="main" id="container">
{{ template "content" . }} {{ template "content" . }}
</div> </div>
<footer>
</footer>
</body> </body>
</html> </html>

View File

@ -1,61 +1,69 @@
{{ define "content" }} {{ define "content" }}{{ $path := .Path }}
<header> <header>
<div class="content"> <div class="content">
<h1>{{.Path}}</h1> <h1>{{ $path }}</h1>
{{ $path := .Path }} </div>
</div>
</header> </header>
<main> <main class="browse">
<div class="content"> <div class="actions">
{{if .CanGoUp}} <div class="content">
<a href=".." class="up" title="Up one level">&#11025;</a> {{if .CanGoUp}}<a href=".." class="up" title="Up one level"><i class="fa fa-arrow-left fa-lg"></i></a>{{end}}
{{else}} <div class="go-right"><input type="file" value="Upload">
<div class="up">&nbsp;</div> <button id="upload">Upload <i class="fa fa-cloud-upload"></i></button>
{{end}} <button class="default">New <i class="fa fa-plus"></i></button></div>
</div>
</div>
<table> <div class="content">
<tr> <table>
<th> <tr>
{{if and (eq .Sort "name") (ne .Order "desc")}} <th class="left">
<a href="?sort=name&order=desc">Name &#9650;</a> {{if and (eq .Sort "name") (ne .Order "desc")}}
{{else if and (eq .Sort "name") (ne .Order "asc")}} <a href="?sort=name&order=desc">Name <i class="fa fa-arrow-up"></i></a>
<a href="?sort=name&order=asc">Name &#9660;</a> {{else if and (eq .Sort "name") (ne .Order "asc")}}
{{else}} <a href="?sort=name&order=asc">Name <i class="fa fa-arrow-down"></i></a>
<a href="?sort=name&order=asc">Name</a> {{else}}
{{end}} <a href="?sort=name&order=asc">Name</a>
</th> {{end}}
<th> </th>
{{if and (eq .Sort "size") (ne .Order "desc")}} <th class="right">
<a href="?sort=size&order=desc">Size &#9650;</a> {{if and (eq .Sort "size") (ne .Order "desc")}}
{{else if and (eq .Sort "size") (ne .Order "asc")}} <a href="?sort=size&order=desc">Size <i class="fa fa-arrow-up"></i></a>
<a href="?sort=size&order=asc">Size &#9660;</a> {{else if and (eq .Sort "size") (ne .Order "asc")}}
{{else}} <a href="?sort=size&order=asc">Size <i class="fa fa-arrow-down"></i></a>
<a href="?sort=size&order=asc">Size</a> {{else}}
{{end}} <a href="?sort=size&order=asc">Size</a>
</th> {{end}}
<th class="hideable"> </th>
{{if and (eq .Sort "time") (ne .Order "desc")}} <th class="hideable right">
<a href="?sort=time&order=desc">Modified &#9650;</a> {{if and (eq .Sort "time") (ne .Order "desc")}}
{{else if and (eq .Sort "time") (ne .Order "asc")}} <a href="?sort=time&order=desc">Modified <i class="fa fa-arrow-up"></i></a>
<a href="?sort=time&order=asc">Modified &#9660;</a> {{else if and (eq .Sort "time") (ne .Order "asc")}}
{{else}} <a href="?sort=time&order=asc">Modified <i class="fa fa-arrow-down"></i></a>
<a href="?sort=time&order=asc">Modified</a> {{else}}
{{end}} <a href="?sort=time&order=asc">Modified</a>
</th> {{end}}
</tr> </th>
{{range .Items}} </tr>
<tr> {{range .Items}}
<td> <tr>
{{if .IsDir}}&#128194;<a href="{{.URL}}">{{.Name}}</a>{{else}} <td>
&#128196;<a href="/admin/edit{{ $path }}{{.URL}}">{{.Name}}</a>{{end}} {{if .IsDir}}
<i class="fa fa-folder"></i> <a href="{{.URL}}">{{.Name}}</a>
</td> {{else}}
<td>{{.HumanSize}}</td> {{ if isMarkdown .URL }}
<td class="hideable">{{.HumanModTime "01/02/2006 3:04:05 PM -0700"}}</td> <i class="fa fa-file"></i> <a class="file" href="/admin/edit{{ $path }}{{.URL}}">{{.Name}}</a>
</tr> {{ else }}
{{end}} <i class="fa fa-file"></i> {{.Name}}
</table> {{ end }}
</div> {{ end }}
</td>
<td class="right">{{.HumanSize}}</td>
<td class="right hideable">{{.HumanModTime "01/02/2006 3:04:05 PM -0700"}}</td>
</tr>
{{end}}
</table>
</div>
</main> </main>
{{ end }} {{ end }}

View File

@ -52,6 +52,10 @@ func IsInterface(sth interface{}) bool {
return reflect.ValueOf(sth).Kind() == reflect.Interface return reflect.ValueOf(sth).Kind() == reflect.Interface
} }
func IsMarkdownFile(filename string) bool {
return strings.HasSuffix(filename, ".markdown") || strings.HasSuffix(filename, ".md")
}
func SplitCapitalize(name string) string { func SplitCapitalize(name string) string {
var words []string var words []string
l := 0 l := 0