update.
parent
68aea511fa
commit
6bc5b881d6
|
@ -308,7 +308,24 @@ var itemClickEvent = function(event) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var localizeDatetime = function (e, index, ar) {
|
||||||
|
if (e.textContent === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var d = new Date(e.getAttribute('datetime'));
|
||||||
|
if (isNaN(d)) {
|
||||||
|
d = new Date(e.textContent);
|
||||||
|
if (isNaN(d)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
e.textContent = d.toLocaleString();
|
||||||
|
}
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", function (event) {
|
document.addEventListener("DOMContentLoaded", function (event) {
|
||||||
|
var timeList = Array.prototype.slice.call(document.getElementsByTagName("time"));
|
||||||
|
timeList.forEach(localizeDatetime);
|
||||||
|
|
||||||
var items = document.getElementsByClassName('item');
|
var items = document.getElementsByClassName('item');
|
||||||
Array.from(items).forEach(link => {
|
Array.from(items).forEach(link => {
|
||||||
link.addEventListener('click', itemClickEvent);
|
link.addEventListener('click', itemClickEvent);
|
||||||
|
@ -338,6 +355,5 @@ document.addEventListener("DOMContentLoaded", function(event) {
|
||||||
drop.style.backgroundColor = 'transparent';
|
drop.style.backgroundColor = 'transparent';
|
||||||
}; */
|
}; */
|
||||||
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
{{ define "actions" }}
|
{{ define "actions" }}
|
||||||
<div>
|
|
||||||
<div class="action" id="open"><i class="material-icons">open_in_new</i></div>
|
<div class="action" id="open"><i class="material-icons">open_in_new</i></div>
|
||||||
<div class="action" id="rename"><i class="material-icons">mode_edit</i></div>
|
{{ if .IsDir }}<div class="action" id="rename"><i class="material-icons">mode_edit</i></div>{{ end }}
|
||||||
<div class="action" id="download"><i class="material-icons">file_download</i></div>
|
<div class="action" id="download"><i class="material-icons">file_download</i></div>
|
||||||
<div class="action" id="delete"><i class="material-icons">delete</i></div>
|
<div class="action" id="delete"><i class="material-icons">delete</i></div>
|
||||||
</div>
|
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
|
@ -8,6 +8,11 @@
|
||||||
<link rel="stylesheet" href="{{ .Config.BaseURL }}/_filemanagerinternal/css/styles.css">
|
<link rel="stylesheet" href="{{ .Config.BaseURL }}/_filemanagerinternal/css/styles.css">
|
||||||
<script src="{{ .Config.BaseURL }}/_filemanagerinternal/js/application.js"></script>
|
<script src="{{ .Config.BaseURL }}/_filemanagerinternal/js/application.js"></script>
|
||||||
{{ if ne .Config.StyleSheet "" }}<style>{{ .Config.StyleSheet}}</style>{{ end }}
|
{{ if ne .Config.StyleSheet "" }}<style>{{ .Config.StyleSheet}}</style>{{ end }}
|
||||||
|
{{ if .Config.HugoEnabled }}
|
||||||
|
<!-- Hugo plugin stuff -->
|
||||||
|
<link rel="stylesheet" href="{{ .Config.BaseURL }}/_hugointernal/css/styles.css">
|
||||||
|
<script src="{{ .Config.BaseURL }}/_hugointernal/js/application.js"></script>
|
||||||
|
{{ end }}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header>
|
<header>
|
||||||
|
@ -17,17 +22,23 @@
|
||||||
<div class="action disabled" id="prev"><i class="material-icons">subdirectory_arrow_left</i></div>{{ end }}
|
<div class="action disabled" id="prev"><i class="material-icons">subdirectory_arrow_left</i></div>{{ end }}
|
||||||
<p><a href="{{ if eq .Config.BaseURL "" }}/{{ else }}{{ .Config.BaseURL }}{{ end }}">File Manager</a> {{ if ne .Name "/"}}<i class="material-icons">chevron_right</i> {{ .Name }}</p>{{ end }}
|
<p><a href="{{ if eq .Config.BaseURL "" }}/{{ else }}{{ .Config.BaseURL }}{{ end }}">File Manager</a> {{ if ne .Name "/"}}<i class="material-icons">chevron_right</i> {{ .Name }}</p>{{ end }}
|
||||||
</div>
|
</div>
|
||||||
{{ if .IsDir}}
|
|
||||||
<div>
|
<div>
|
||||||
|
{{ if .IsDir}}
|
||||||
<form>
|
<form>
|
||||||
<i class="material-icons">search</i> <input type="text" placeholder="Search">
|
<i class="material-icons">search</i> <input type="text" placeholder="Search">
|
||||||
</form>
|
</form>
|
||||||
<div class="action" id="view"><i class="material-icons">view_headline</i></div>
|
<div class="action" id="view"><i class="material-icons">view_headline</i></div>
|
||||||
<div class="action" id="upload"><i class="material-icons">file_upload</i></div>
|
<div class="action" id="upload"><i class="material-icons">file_upload</i></div>
|
||||||
</div>
|
|
||||||
{{ else }}
|
{{ else }}
|
||||||
{{ template "actions" . }}
|
{{ template "actions" . }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
{{ if .Config.HugoEnabled }}
|
||||||
|
<!-- Hugo plugin stuff -->
|
||||||
|
<div class="action" id="settings"><i class="material-icons">settings</i></div>
|
||||||
|
<div class="action" id="logout"><i class="material-icons">exit_to_app</i></div>
|
||||||
|
{{ end }}
|
||||||
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
{{ if .IsDir }}
|
{{ if .IsDir }}
|
||||||
|
@ -39,29 +50,11 @@
|
||||||
{{ template "actions" . }}
|
{{ template "actions" . }}
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
{{ template "content" .Data }}
|
{{ template "content" .Data }}
|
||||||
</main>
|
</main>
|
||||||
<footer>
|
<footer>
|
||||||
Served with <a rel="noopener noreferrer" href="https://caddyserver.com">Caddy</a> and <a rel="noopener noreferrer" href="https://github.com/hacdias/caddy-filemanager">File Manager</a>.
|
Served with <a rel="noopener noreferrer" href="https://caddyserver.com">Caddy</a> and <a rel="noopener noreferrer" href="https://github.com/hacdias/caddy-filemanager">File Manager</a>. {{ if .Config.HugoEnabled }}With a flavour of <a rel="noopener noreferrer" href="https://github.com/hacdias/caddy-filemanager">Hugo</a>.{{ end }}
|
||||||
</footer>
|
</footer>
|
||||||
<script type="text/javascript">
|
|
||||||
function localizeDatetime(e, index, ar) {
|
|
||||||
if (e.textContent === undefined) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var d = new Date(e.getAttribute('datetime'));
|
|
||||||
if (isNaN(d)) {
|
|
||||||
d = new Date(e.textContent);
|
|
||||||
if (isNaN(d)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
e.textContent = d.toLocaleString();
|
|
||||||
}
|
|
||||||
var timeList = Array.prototype.slice.call(document.getElementsByTagName("time"));
|
|
||||||
timeList.forEach(localizeDatetime);
|
|
||||||
</script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
14
page.go
14
page.go
|
@ -1,8 +1,6 @@
|
||||||
package filemanager
|
package filemanager
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
"log"
|
||||||
|
@ -102,16 +100,18 @@ func (p *Page) AddTemplate(name string, assets AssetFunc, functions template.Fun
|
||||||
|
|
||||||
// PrintAsHTML formats the page in HTML and executes the template
|
// PrintAsHTML formats the page in HTML and executes the template
|
||||||
func (p Page) PrintAsHTML(w http.ResponseWriter) (int, error) {
|
func (p Page) PrintAsHTML(w http.ResponseWriter) (int, error) {
|
||||||
var buffer bytes.Buffer
|
// var buffer bytes.Buffer
|
||||||
writer := bufio.NewWriter(&buffer)
|
//writer := bufio.NewWriter(&buffer)
|
||||||
err := p.Tpl.Execute(writer, p.Info)
|
err := p.Tpl.Execute(w, p.Info)
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
// _, err = buffer.WriteTo(w)
|
||||||
buffer.WriteTo(w)
|
// w.Write(buffer.Bytes())
|
||||||
return http.StatusOK, nil
|
return http.StatusOK, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
5
setup.go
5
setup.go
|
@ -36,7 +36,8 @@ type Config struct {
|
||||||
PathScope string
|
PathScope string
|
||||||
Root http.FileSystem
|
Root http.FileSystem
|
||||||
BaseURL string
|
BaseURL string
|
||||||
StyleSheet string
|
StyleSheet string // Costum stylesheet
|
||||||
|
HugoEnabled bool // This must be only used by Hugo plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseConfiguration parses the configuration set by the user so it can
|
// parseConfiguration parses the configuration set by the user so it can
|
||||||
|
@ -55,7 +56,7 @@ func parseConfiguration(c *caddy.Controller) ([]Config, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for c.Next() {
|
for c.Next() {
|
||||||
var cfg = Config{PathScope: ".", BaseURL: ""}
|
var cfg = Config{PathScope: ".", BaseURL: "", HugoEnabled: false}
|
||||||
for c.NextBlock() {
|
for c.NextBlock() {
|
||||||
switch c.Val() {
|
switch c.Val() {
|
||||||
case "show":
|
case "show":
|
||||||
|
|
Loading…
Reference in New Issue