close #71; fix bugs
parent
acc4c92b15
commit
4cd72ca58d
File diff suppressed because one or more lines are too long
|
@ -1,10 +1,14 @@
|
||||||
|
var basePath = "/";
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
basePath += window.location.pathname.split('/')[0];
|
||||||
|
|
||||||
// Log out the user sending bad credentials to the server
|
// Log out the user sending bad credentials to the server
|
||||||
$("#logout").click(function(event) {
|
$("#logout").click(function(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "GET",
|
type: "GET",
|
||||||
url: "/admin",
|
url: basePath + "",
|
||||||
async: false,
|
async: false,
|
||||||
username: "username",
|
username: "username",
|
||||||
password: "password",
|
password: "password",
|
||||||
|
|
|
@ -247,7 +247,7 @@ $(document).on('page:browse', function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filename.substring(0, 1) != "/") {
|
if (filename.substring(0, 1) != "/") {
|
||||||
filename = window.location.pathname.replace("/admin/browse/", "") + '/' + filename;
|
filename = window.location.pathname.replace(basePath + "/browse/", "") + '/' + filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
var content = {
|
var content = {
|
||||||
|
@ -323,7 +323,7 @@ $(document).on('page:browse', function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
var request = new XMLHttpRequest();
|
var request = new XMLHttpRequest();
|
||||||
request.open("POST", "/admin/git");
|
request.open("POST", basePath + "/git");
|
||||||
request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
||||||
request.send(JSON.stringify({
|
request.send(JSON.stringify({
|
||||||
command: value
|
command: value
|
||||||
|
|
|
@ -103,6 +103,8 @@ $(document).on('page:editor', function() {
|
||||||
regenerate: button.data("regenerate")
|
regenerate: button.data("regenerate")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(JSON.stringify(data));
|
||||||
|
|
||||||
var request = new XMLHttpRequest();
|
var request = new XMLHttpRequest();
|
||||||
request.open("POST", window.location);
|
request.open("POST", window.location);
|
||||||
request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
||||||
|
@ -155,7 +157,6 @@ $(document).on('page:editor', function() {
|
||||||
input = input.replace(/\[/, '\\[');
|
input = input.replace(/\[/, '\\[');
|
||||||
input = input.replace(/\]/, '\\]');
|
input = input.replace(/\]/, '\\]');
|
||||||
block.append('<div id="' + newID + '-' + $('#' + input + ' > div').length + '" data-type="array-item"><input name="' + newID + ':auto" id="' + newID + '"></input><span class="actions"> <button class="delete">−</button></span></div></div>');
|
block.append('<div id="' + newID + '-' + $('#' + input + ' > div').length + '" data-type="array-item"><input name="' + newID + ':auto" id="' + newID + '"></input><span class="actions"> <button class="delete">−</button></span></div></div>');
|
||||||
console.log('New array item added.');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main add button, after all blocks
|
// Main add button, after all blocks
|
||||||
|
@ -241,8 +242,6 @@ $(document).on('page:editor', function() {
|
||||||
template = template.replace("${type}", type);
|
template = template.replace("${type}", type);
|
||||||
newItem.after(template);
|
newItem.after(template);
|
||||||
newItem.remove();
|
newItem.remove();
|
||||||
|
|
||||||
console.log('"' + blockID + '" block of type "' + type + '" added.');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -260,7 +259,6 @@ $(document).on('page:editor', function() {
|
||||||
name = button.parent().parent().attr("for") || button.parent().parent().attr("id") || button.parent().parent().parent().attr("id");
|
name = button.parent().parent().attr("for") || button.parent().parent().attr("id") || button.parent().parent().parent().attr("id");
|
||||||
name = name.replace(/\[/, '\\[');
|
name = name.replace(/\[/, '\\[');
|
||||||
name = name.replace(/\]/, '\\]');
|
name = name.replace(/\]/, '\\]');
|
||||||
console.log(name)
|
|
||||||
|
|
||||||
$('label[for="' + name + '"]').fadeOut().remove();
|
$('label[for="' + name + '"]').fadeOut().remove();
|
||||||
$('#' + name).fadeOut().remove();
|
$('#' + name).fadeOut().remove();
|
||||||
|
|
|
@ -9,23 +9,21 @@
|
||||||
<title>{{ if Defined . "Name" }}{{ .Name }}{{ end }}</title>
|
<title>{{ if Defined . "Name" }}{{ .Name }}{{ end }}</title>
|
||||||
|
|
||||||
<link href='https://fonts.googleapis.com/css?family=Roboto:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
|
<link href='https://fonts.googleapis.com/css?family=Roboto:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
|
||||||
<link rel="stylesheet" href="/admin/assets/css/main.min.css">
|
<link rel="stylesheet" href="{{ if and (Defined . "User") }}{{ .User.Admin }}{{ else }}{{ .Config.Admin }}{{ end }}/assets/css/main.min.css">
|
||||||
{{ if and (Defined . "Config")}}{{ if not (eq .Config.Styles "") }}<link rel="stylesheet" href="{{ .Config.Styles }}">{{ end }}{{ end }}
|
{{ if not (eq .Config.Styles "") }}<link rel="stylesheet" href="{{ .Config.Styles }}">{{ end }}
|
||||||
{{ if and (Defined . "User") }}{{ if not (eq .User.Styles "") }}<link rel="stylesheet" href="{{ .User.Styles }}">{{ end }}{{ end }}
|
|
||||||
|
|
||||||
|
<script src="{{ if and (Defined . "User") }}{{ .User.Admin }}{{ else }}{{ .Config.Admin }}{{ end }}/assets/js/plugins.min.js"></script>
|
||||||
<script src="/admin/assets/js/plugins.min.js"></script>
|
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.3/ace.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.3/ace.js"></script>
|
||||||
<script src="/admin/assets/js/app.min.js"></script>
|
<script src="{{ if and (Defined . "User") }}{{ .User.Admin }}{{ else }}{{ .Config.Admin }}{{ end }}/assets/js/app.min.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<nav>
|
<nav>
|
||||||
<ul class="container">
|
<ul class="container">
|
||||||
<li><a href="/"><i class="fa fa-home fa-lg"></i><span> Go to website</span></a></li>
|
<li><a href="/"><i class="fa fa-home fa-lg"></i><span> Go to website</span></a></li>
|
||||||
<li><a data-pjax href="/admin/browse/content/"><i class="fa fa-newspaper-o"></i><span> Content</span></a></li>
|
<li><a data-pjax href="{{ if and (Defined . "User") }}{{ .User.Admin }}{{ else }}{{ .Config.Admin }}{{ end }}/browse/content/"><i class="fa fa-newspaper-o"></i><span> Content</span></a></li>
|
||||||
<li><a data-pjax href="/admin/browse/"><i class="fa fa-folder-o"></i><span> Browse</span></a></li>
|
<li><a data-pjax href="{{ if and (Defined . "User") }}{{ .User.Admin }}{{ else }}{{ .Config.Admin }}{{ end }}/browse/"><i class="fa fa-folder-o"></i><span> Browse</span></a></li>
|
||||||
<li><a data-pjax href="/admin/settings/"><i class="fa fa-cog"></i><span> Settings</span></a></li>
|
<li><a data-pjax href="{{ if and (Defined . "User") }}{{ .User.Admin }}{{ else }}{{ .Config.Admin }}{{ end }}/settings/"><i class="fa fa-cog"></i><span> Settings</span></a></li>
|
||||||
<li><a data-pjax id="logout" href="#logout"><i class="fa fa-sign-out"></i><span> Logout</span></a></li>
|
<li><a data-pjax id="logout" href="#logout"><i class="fa fa-sign-out"></i><span> Logout</span></a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
{{ define "content" }}{{ $path := .Path }}
|
{{ define "content" }}
|
||||||
|
{{ $path := .Path }}
|
||||||
|
{{ $admin := .User.Admin }}
|
||||||
|
|
||||||
<main class="browse">
|
<main class="browse">
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
|
@ -42,12 +44,12 @@
|
||||||
<td>
|
<td>
|
||||||
{{if .IsDir}}
|
{{if .IsDir}}
|
||||||
<i class="fa fa-folder"></i> <a data-pjax class="filename" href="{{.URL}}">{{.Name}}</a> {{else}} {{ if CanBeEdited .URL }}
|
<i class="fa fa-folder"></i> <a data-pjax class="filename" href="{{.URL}}">{{.Name}}</a> {{else}} {{ if CanBeEdited .URL }}
|
||||||
<i class="fa fa-file"></i> <a data-pjax class="file filename" href="/admin/edit{{ $path }}{{.URL}}">{{.Name}}</a> {{ else }}
|
<i class="fa fa-file"></i> <a data-pjax class="file filename" href="{{ $admin }}/edit{{ $path }}{{.URL}}">{{.Name}}</a> {{ else }}
|
||||||
<i class="fa fa-file"></i> <span class="filename">{{.Name}}</span> {{ end }} {{ end }}
|
<i class="fa fa-file"></i> <span class="filename">{{.Name}}</span> {{ end }} {{ end }}
|
||||||
</td>
|
</td>
|
||||||
<td class="right hideable">{{.HumanSize}}</td>
|
<td class="right hideable">{{.HumanSize}}</td>
|
||||||
<td class="right hideable">{{.HumanModTime "01/02/2006 3:04:05 PM"}}</td>
|
<td class="right hideable">{{.HumanModTime "01/02/2006 3:04:05 PM"}}</td>
|
||||||
<td class="right"><button data-file="/admin/browse{{ $path }}{{.URL}}" data-message="File renamed." class="rename">✎</button> <button data-file="/admin/browse{{ $path }}{{.URL}}" data-message="File deleted." class="delete">✖</button></td>
|
<td class="right"><button data-file="{{ $admin }}/browse{{ $path }}{{.URL}}" data-message="File renamed." class="rename">✎</button> <button data-file="{{ $admin }}/browse{{ $path }}{{.URL}}" data-message="File deleted." class="delete">✖</button></td>
|
||||||
</tr>
|
</tr>
|
||||||
{{end}}
|
{{end}}
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -21,13 +21,13 @@ type response struct {
|
||||||
func ServeHTTP(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) {
|
func ServeHTTP(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) {
|
||||||
conf = c
|
conf = c
|
||||||
// Removes the page main path from the URL
|
// Removes the page main path from the URL
|
||||||
r.URL.Path = strings.Replace(r.URL.Path, "/admin/browse", "", 1)
|
r.URL.Path = strings.Replace(r.URL.Path, c.Admin+"/browse", "", 1)
|
||||||
|
|
||||||
switch r.Method {
|
switch r.Method {
|
||||||
case "DELETE":
|
case "DELETE":
|
||||||
return DELETE(w, r)
|
return DELETE(w, r)
|
||||||
case "POST":
|
case "POST":
|
||||||
return POST(w, r)
|
return POST(w, r, c)
|
||||||
case "GET":
|
case "GET":
|
||||||
return GET(w, r)
|
return GET(w, r)
|
||||||
case "PUT":
|
case "PUT":
|
||||||
|
|
|
@ -10,13 +10,14 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/hacdias/caddy-hugo/config"
|
||||||
"github.com/hacdias/caddy-hugo/tools/commands"
|
"github.com/hacdias/caddy-hugo/tools/commands"
|
||||||
s "github.com/hacdias/caddy-hugo/tools/server"
|
s "github.com/hacdias/caddy-hugo/tools/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
// POST handles the POST method on browse page. It's used to create new files,
|
// POST handles the POST method on browse page. It's used to create new files,
|
||||||
// folders and upload content.
|
// folders and upload content.
|
||||||
func POST(w http.ResponseWriter, r *http.Request) (int, error) {
|
func POST(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) {
|
||||||
// Remove prefix slash
|
// Remove prefix slash
|
||||||
r.URL.Path = strings.TrimPrefix(r.URL.Path, "/")
|
r.URL.Path = strings.TrimPrefix(r.URL.Path, "/")
|
||||||
|
|
||||||
|
@ -47,7 +48,7 @@ func POST(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||||
filename := info["filename"].(string)
|
filename := info["filename"].(string)
|
||||||
filename = strings.TrimPrefix(filename, "/")
|
filename = strings.TrimPrefix(filename, "/")
|
||||||
filename = strings.TrimSuffix(filename, "/")
|
filename = strings.TrimSuffix(filename, "/")
|
||||||
url := "/admin/edit/" + r.URL.Path + filename
|
url := c.Admin + "/edit/" + r.URL.Path + filename
|
||||||
filename = conf.Path + r.URL.Path + filename
|
filename = conf.Path + r.URL.Path + filename
|
||||||
|
|
||||||
if strings.HasPrefix(filename, conf.Path+"content/") &&
|
if strings.HasPrefix(filename, conf.Path+"content/") &&
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"github.com/hacdias/caddy-hugo/tools/server"
|
"github.com/hacdias/caddy-hugo/tools/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
// PUT handles the HTTP PUT request for all /admin/browse related requests.
|
// PUT handles the HTTP PUT request for all /{admin}/browse related requests.
|
||||||
// Renames a file and/or a folder.
|
// Renames a file and/or a folder.
|
||||||
func PUT(w http.ResponseWriter, r *http.Request) (int, error) {
|
func PUT(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||||
// Remove both beginning and trailing slashes
|
// Remove both beginning and trailing slashes
|
||||||
|
|
|
@ -16,7 +16,7 @@ var (
|
||||||
// ServeHTTP serves the editor page
|
// ServeHTTP serves the editor page
|
||||||
func ServeHTTP(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) {
|
func ServeHTTP(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) {
|
||||||
conf = c
|
conf = c
|
||||||
filename = strings.Replace(r.URL.Path, "/admin/edit/", "", 1)
|
filename = strings.Replace(r.URL.Path, c.Admin+"/edit/", "", 1)
|
||||||
filename = c.Path + filename
|
filename = c.Path + filename
|
||||||
|
|
||||||
switch r.Method {
|
switch r.Method {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -17,8 +18,6 @@ import (
|
||||||
"github.com/spf13/hugo/parser"
|
"github.com/spf13/hugo/parser"
|
||||||
)
|
)
|
||||||
|
|
||||||
var data info
|
|
||||||
|
|
||||||
type info struct {
|
type info struct {
|
||||||
ContentType string
|
ContentType string
|
||||||
Schedule bool
|
Schedule bool
|
||||||
|
@ -32,11 +31,15 @@ type response struct {
|
||||||
|
|
||||||
// POST handles the POST method on editor page
|
// POST handles the POST method on editor page
|
||||||
func POST(w http.ResponseWriter, r *http.Request) (int, error) {
|
func POST(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||||
|
var data info
|
||||||
|
|
||||||
// Get the JSON information sent using a buffer
|
// Get the JSON information sent using a buffer
|
||||||
rawBuffer := new(bytes.Buffer)
|
rawBuffer := new(bytes.Buffer)
|
||||||
rawBuffer.ReadFrom(r.Body)
|
rawBuffer.ReadFrom(r.Body)
|
||||||
err := json.Unmarshal(rawBuffer.Bytes(), &data)
|
err := json.Unmarshal(rawBuffer.Bytes(), &data)
|
||||||
|
|
||||||
|
fmt.Println(string(rawBuffer.Bytes()))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return server.RespondJSON(w, &response{"Error decrypting json."}, http.StatusInternalServerError, err)
|
return server.RespondJSON(w, &response{"Error decrypting json."}, http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
|
@ -46,7 +49,7 @@ func POST(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||||
|
|
||||||
switch data.ContentType {
|
switch data.ContentType {
|
||||||
case "frontmatter-only":
|
case "frontmatter-only":
|
||||||
f, code, err := parseFrontMatterOnlyFile()
|
f, code, err := parseFrontMatterOnlyFile(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return server.RespondJSON(w, &response{err.Error()}, code, err)
|
return server.RespondJSON(w, &response{err.Error()}, code, err)
|
||||||
}
|
}
|
||||||
|
@ -59,7 +62,7 @@ func POST(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||||
|
|
||||||
file = []byte(mainContent)
|
file = []byte(mainContent)
|
||||||
case "complete":
|
case "complete":
|
||||||
f, code, err := parseCompleteFile()
|
f, code, err := parseCompleteFile(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return server.RespondJSON(w, &response{err.Error()}, code, err)
|
return server.RespondJSON(w, &response{err.Error()}, code, err)
|
||||||
}
|
}
|
||||||
|
@ -83,7 +86,7 @@ func POST(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||||
return server.RespondJSON(w, nil, http.StatusOK, nil)
|
return server.RespondJSON(w, nil, http.StatusOK, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseFrontMatterOnlyFile() ([]byte, int, error) {
|
func parseFrontMatterOnlyFile(data info) ([]byte, int, error) {
|
||||||
frontmatter := strings.TrimPrefix(filepath.Ext(filename), ".")
|
frontmatter := strings.TrimPrefix(filepath.Ext(filename), ".")
|
||||||
var mark rune
|
var mark rune
|
||||||
|
|
||||||
|
@ -121,7 +124,7 @@ func parseFrontMatterOnlyFile() ([]byte, int, error) {
|
||||||
return f, http.StatusOK, nil
|
return f, http.StatusOK, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseCompleteFile() ([]byte, int, error) {
|
func parseCompleteFile(data info) ([]byte, int, error) {
|
||||||
// The main content of the file
|
// The main content of the file
|
||||||
mainContent := data.Content["content"].(string)
|
mainContent := data.Content["content"].(string)
|
||||||
mainContent = "\n\n" + strings.TrimSpace(mainContent) + "\n"
|
mainContent = "\n\n" + strings.TrimSpace(mainContent) + "\n"
|
||||||
|
|
Loading…
Reference in New Issue