updates :)
parent
30f077803b
commit
15e48bfad9
|
@ -1,6 +1,8 @@
|
|||
// Code generated by go-bindata.
|
||||
// sources:
|
||||
// assets/.jsbeautifyrc
|
||||
// assets/assets.go
|
||||
// assets/binary.go
|
||||
// assets/public/css/styles.css
|
||||
// assets/public/js/application.js
|
||||
// assets/public/js/form2js.js
|
||||
|
@ -9,6 +11,7 @@
|
|||
// assets/templates/editor.tmpl
|
||||
// assets/templates/frontmatter.tmpl
|
||||
// assets/templates/listing.tmpl
|
||||
// assets/templates/minimal.tmpl
|
||||
// assets/templates/single.tmpl
|
||||
// DO NOT EDIT!
|
||||
|
||||
|
@ -54,6 +57,42 @@ func Jsbeautifyrc() (*asset, error) {
|
|||
return a, err
|
||||
}
|
||||
|
||||
// assetsGo reads file data from disk. It returns an error on failure.
|
||||
func assetsGo() (*asset, error) {
|
||||
path := "D:\\Code\\Go\\src\\github.com\\hacdias\\caddy-filemanager\\assets\\assets.go"
|
||||
name := "assets.go"
|
||||
bytes, err := bindataRead(path, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fi, err := os.Stat(path)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Error reading asset info %s at %s: %v", name, path, err)
|
||||
}
|
||||
|
||||
a := &asset{bytes: bytes, info: fi}
|
||||
return a, err
|
||||
}
|
||||
|
||||
// binaryGo reads file data from disk. It returns an error on failure.
|
||||
func binaryGo() (*asset, error) {
|
||||
path := "D:\\Code\\Go\\src\\github.com\\hacdias\\caddy-filemanager\\assets\\binary.go"
|
||||
name := "binary.go"
|
||||
bytes, err := bindataRead(path, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fi, err := os.Stat(path)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Error reading asset info %s at %s: %v", name, path, err)
|
||||
}
|
||||
|
||||
a := &asset{bytes: bytes, info: fi}
|
||||
return a, err
|
||||
}
|
||||
|
||||
// publicCssStylesCss reads file data from disk. It returns an error on failure.
|
||||
func publicCssStylesCss() (*asset, error) {
|
||||
path := "D:\\Code\\Go\\src\\github.com\\hacdias\\caddy-filemanager\\assets\\public\\css\\styles.css"
|
||||
|
@ -198,6 +237,24 @@ func templatesListingTmpl() (*asset, error) {
|
|||
return a, err
|
||||
}
|
||||
|
||||
// templatesMinimalTmpl reads file data from disk. It returns an error on failure.
|
||||
func templatesMinimalTmpl() (*asset, error) {
|
||||
path := "D:\\Code\\Go\\src\\github.com\\hacdias\\caddy-filemanager\\assets\\templates\\minimal.tmpl"
|
||||
name := "templates/minimal.tmpl"
|
||||
bytes, err := bindataRead(path, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fi, err := os.Stat(path)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Error reading asset info %s at %s: %v", name, path, err)
|
||||
}
|
||||
|
||||
a := &asset{bytes: bytes, info: fi}
|
||||
return a, err
|
||||
}
|
||||
|
||||
// templatesSingleTmpl reads file data from disk. It returns an error on failure.
|
||||
func templatesSingleTmpl() (*asset, error) {
|
||||
path := "D:\\Code\\Go\\src\\github.com\\hacdias\\caddy-filemanager\\assets\\templates\\single.tmpl"
|
||||
|
@ -268,16 +325,19 @@ func AssetNames() []string {
|
|||
|
||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||
var _bindata = map[string]func() (*asset, error){
|
||||
".jsbeautifyrc": Jsbeautifyrc,
|
||||
"public/css/styles.css": publicCssStylesCss,
|
||||
"public/js/application.js": publicJsApplicationJs,
|
||||
"public/js/form2js.js": publicJsForm2jsJs,
|
||||
"templates/actions.tmpl": templatesActionsTmpl,
|
||||
"templates/base.tmpl": templatesBaseTmpl,
|
||||
"templates/editor.tmpl": templatesEditorTmpl,
|
||||
".jsbeautifyrc": Jsbeautifyrc,
|
||||
"assets.go": assetsGo,
|
||||
"binary.go": binaryGo,
|
||||
"public/css/styles.css": publicCssStylesCss,
|
||||
"public/js/application.js": publicJsApplicationJs,
|
||||
"public/js/form2js.js": publicJsForm2jsJs,
|
||||
"templates/actions.tmpl": templatesActionsTmpl,
|
||||
"templates/base.tmpl": templatesBaseTmpl,
|
||||
"templates/editor.tmpl": templatesEditorTmpl,
|
||||
"templates/frontmatter.tmpl": templatesFrontmatterTmpl,
|
||||
"templates/listing.tmpl": templatesListingTmpl,
|
||||
"templates/single.tmpl": templatesSingleTmpl,
|
||||
"templates/listing.tmpl": templatesListingTmpl,
|
||||
"templates/minimal.tmpl": templatesMinimalTmpl,
|
||||
"templates/single.tmpl": templatesSingleTmpl,
|
||||
}
|
||||
|
||||
// AssetDir returns the file names below a certain
|
||||
|
@ -319,25 +379,27 @@ type bintree struct {
|
|||
Func func() (*asset, error)
|
||||
Children map[string]*bintree
|
||||
}
|
||||
|
||||
var _bintree = &bintree{nil, map[string]*bintree{
|
||||
".jsbeautifyrc": &bintree{Jsbeautifyrc, map[string]*bintree{}},
|
||||
"assets.go": &bintree{assetsGo, map[string]*bintree{}},
|
||||
"binary.go": &bintree{binaryGo, map[string]*bintree{}},
|
||||
"public": &bintree{nil, map[string]*bintree{
|
||||
"css": &bintree{nil, map[string]*bintree{
|
||||
"styles.css": &bintree{publicCssStylesCss, map[string]*bintree{}},
|
||||
}},
|
||||
"js": &bintree{nil, map[string]*bintree{
|
||||
"application.js": &bintree{publicJsApplicationJs, map[string]*bintree{}},
|
||||
"form2js.js": &bintree{publicJsForm2jsJs, map[string]*bintree{}},
|
||||
"form2js.js": &bintree{publicJsForm2jsJs, map[string]*bintree{}},
|
||||
}},
|
||||
}},
|
||||
"templates": &bintree{nil, map[string]*bintree{
|
||||
"actions.tmpl": &bintree{templatesActionsTmpl, map[string]*bintree{}},
|
||||
"base.tmpl": &bintree{templatesBaseTmpl, map[string]*bintree{}},
|
||||
"editor.tmpl": &bintree{templatesEditorTmpl, map[string]*bintree{}},
|
||||
"actions.tmpl": &bintree{templatesActionsTmpl, map[string]*bintree{}},
|
||||
"base.tmpl": &bintree{templatesBaseTmpl, map[string]*bintree{}},
|
||||
"editor.tmpl": &bintree{templatesEditorTmpl, map[string]*bintree{}},
|
||||
"frontmatter.tmpl": &bintree{templatesFrontmatterTmpl, map[string]*bintree{}},
|
||||
"listing.tmpl": &bintree{templatesListingTmpl, map[string]*bintree{}},
|
||||
"single.tmpl": &bintree{templatesSingleTmpl, map[string]*bintree{}},
|
||||
"listing.tmpl": &bintree{templatesListingTmpl, map[string]*bintree{}},
|
||||
"minimal.tmpl": &bintree{templatesMinimalTmpl, map[string]*bintree{}},
|
||||
"single.tmpl": &bintree{templatesSingleTmpl, map[string]*bintree{}},
|
||||
}},
|
||||
}}
|
||||
|
||||
|
@ -387,3 +449,4 @@ func _filePath(dir, name string) string {
|
|||
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
|
||||
}
|
||||
|
||||
|
|
|
@ -555,24 +555,30 @@ header #search div {
|
|||
opacity: 0;
|
||||
}
|
||||
|
||||
header #search ::-webkit-input-placeholder {
|
||||
header #search.active div i {
|
||||
color: #ccc;
|
||||
display: block;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
header #search::-webkit-input-placeholder {
|
||||
/* WebKit, Blink, Edge */
|
||||
color: rgba(255, 255, 255, .5);
|
||||
}
|
||||
|
||||
header #search :-moz-placeholder {
|
||||
header #search:-moz-placeholder {
|
||||
opacity: 1;
|
||||
/* Mozilla Firefox 4 to 18 */
|
||||
color: rgba(255, 255, 255, .5);
|
||||
}
|
||||
|
||||
header #search ::-moz-placeholder {
|
||||
header #search::-moz-placeholder {
|
||||
opacity: 1;
|
||||
/* Mozilla Firefox 19+ */
|
||||
color: rgba(255, 255, 255, .5);
|
||||
}
|
||||
|
||||
header #search :-ms-input-placeholder {
|
||||
header #search:-ms-input-placeholder {
|
||||
/* Internet Explorer 10-11 */
|
||||
color: rgba(255, 255, 255, .5);
|
||||
}
|
||||
|
|
|
@ -171,6 +171,23 @@ var RemoveLastDirectoryPartOf = function(url) {
|
|||
* *
|
||||
* * * * * * * * * * * * * * * */
|
||||
|
||||
var reloadListing = function() {
|
||||
let request = new XMLHttpRequest();
|
||||
request.open('GET', window.location);
|
||||
request.setRequestHeader('Minimal', 'true');
|
||||
request.send();
|
||||
request.onreadystatechange = function() {
|
||||
if (request.readyState == 4) {
|
||||
if (request.status == 200) {
|
||||
document.querySelector('body main').innerHTML = request.responseText;
|
||||
// Handle date times
|
||||
let timeList = document.getElementsByTagName("time");
|
||||
Array.from(timeList).forEach(localizeDatetime);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Rename file event
|
||||
var renameEvent = function(event) {
|
||||
if (this.classList.contains('disabled') || !selectedItems.length) {
|
||||
|
@ -261,7 +278,7 @@ var handleFiles = function(files) {
|
|||
request.onreadystatechange = function() {
|
||||
if (request.readyState == 4) {
|
||||
if (request.status == 200) {
|
||||
history.go(0);
|
||||
reloadListing();
|
||||
}
|
||||
|
||||
button.changeToDone((request.status != 200), html);
|
||||
|
@ -370,7 +387,7 @@ var newDirEvent = function(event) {
|
|||
request.onreadystatechange = function() {
|
||||
if (request.readyState == 4) {
|
||||
button.changeToDone((request.status != 200), html);
|
||||
history.go(0);
|
||||
reloadListing();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -422,6 +439,8 @@ var searchEvent = function(event) {
|
|||
box.innerHTML = "Press enter to continue."
|
||||
|
||||
if (event.keyCode == 13) {
|
||||
box.innerHTML = '<i class="material-icons spin">autorenew</i>';
|
||||
|
||||
let request = new XMLHttpRequest();
|
||||
request.open('POST', window.location);
|
||||
request.setRequestHeader('Command', value);
|
||||
|
@ -441,6 +460,7 @@ var searchEvent = function(event) {
|
|||
text = text.substring(1, text.length - 1);
|
||||
text = text.replace('\\n', "\n");
|
||||
box.innerHTML = text;
|
||||
reloadListing();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -769,4 +789,4 @@ document.addEventListener("DOMContentLoaded", function(event) {
|
|||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
});
|
|
@ -0,0 +1 @@
|
|||
{{ template "content" .Data }}
|
|
@ -235,6 +235,10 @@ func (i *Info) serveListing(w http.ResponseWriter, r *http.Request, c *config.Co
|
|||
},
|
||||
}
|
||||
|
||||
if r.Header.Get("Minimal") == "true" {
|
||||
page.Minimal = true
|
||||
}
|
||||
|
||||
return page.PrintAsHTML(w, "listing")
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ import (
|
|||
// Page contains the informations and functions needed to show the page
|
||||
type Page struct {
|
||||
*Info
|
||||
Minimal bool
|
||||
}
|
||||
|
||||
// Info contains the information of a page
|
||||
|
@ -78,7 +79,12 @@ func (p Page) PrintAsHTML(w http.ResponseWriter, templates ...string) (int, erro
|
|||
"Defined": variables.Defined,
|
||||
}
|
||||
|
||||
templates = append(templates, "actions", "base")
|
||||
if p.Minimal {
|
||||
templates = append(templates, "actions", "minimal")
|
||||
} else {
|
||||
templates = append(templates, "actions", "base")
|
||||
}
|
||||
|
||||
var tpl *template.Template
|
||||
|
||||
// For each template, add it to the the tpl variable
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
// Run executes an external command
|
||||
func Run(command string, args []string, path string) error {
|
||||
cmd := exec.Command(command, args...)
|
||||
cmd.Dir = path
|
||||
cmd.Stdout = os.Stderr
|
||||
cmd.Stderr = os.Stderr
|
||||
return cmd.Run()
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package files
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
// CopyFile is used to copy a file
|
||||
func CopyFile(old, new string) error {
|
||||
// Open the file and create a new one
|
||||
r, err := os.Open(old)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer r.Close()
|
||||
|
||||
w, err := os.Create(new)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer w.Close()
|
||||
|
||||
// Copy the content
|
||||
_, err = io.Copy(w, r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package files
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestCopyFile(t *testing.T) {
|
||||
err := CopyFile("test_data/file_to_copy.txt", "test_data/copied_file.txt")
|
||||
|
||||
if err != nil {
|
||||
t.Error("Can't copy the file.")
|
||||
}
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin faucibus augue vel ex auctor molestie. Sed id lorem quis velit eleifend vestibulum. Etiam tincidunt nulla et metus dictum imperdiet. Suspendisse ac auctor risus. Donec tempus eros quis erat interdum fringilla. Duis ac tristique lorem, quis vulputate enim. In ut est elementum, dignissim tellus quis, ultrices diam. Aenean in efficitur velit, ut imperdiet felis. Suspendisse aliquet accumsan ligula, a iaculis sem luctus vel. Integer sagittis, orci viverra lacinia efficitur, eros magna sodales sapien, in tristique ante arcu ut nunc. Maecenas odio dolor, semper quis vehicula ut, malesuada sollicitudin massa. Integer dolor ligula, hendrerit convallis quam at, luctus dignissim nibh. Fusce interdum congue justo, at imperdiet lorem maximus in.
|
||||
|
||||
Curabitur dignissim id turpis ut eleifend. Pellentesque vehicula et purus et consectetur. Nulla facilisis vehicula nunc in imperdiet. Nam eget porta libero, vel dapibus leo. Maecenas iaculis, arcu quis vehicula sollicitudin, massa tortor mattis tortor, vitae venenatis erat neque et dui. Mauris eleifend vel urna ac interdum. Sed convallis, arcu et scelerisque suscipit, nulla urna laoreet mauris, quis aliquam dolor elit id mauris. Pellentesque ac pulvinar nibh. Duis vestibulum ligula orci, et mattis turpis facilisis mattis. Vivamus feugiat neque sed aliquet aliquet. Sed consequat augue sagittis eros imperdiet, ac lacinia erat tempor. Cras gravida mi a orci euismod feugiat. Mauris condimentum turpis id quam vulputate, et maximus dolor hendrerit.
|
||||
|
||||
Ut nisi urna, sollicitudin ac facilisis eu, rhoncus sed urna. Interdum et malesuada fames ac ante ipsum primis in faucibus. Nulla eu maximus mi, sed commodo diam. Nunc scelerisque tincidunt ipsum eget mattis. Fusce id finibus nisi, sit amet tempus tortor. Fusce accumsan lectus at dignissim volutpat. Nullam nisl nulla, rhoncus id arcu vitae, eleifend posuere libero. Aliquam dictum bibendum bibendum. Integer non mattis neque. Phasellus fermentum et ex vel vehicula.
|
||||
|
||||
Proin eget ligula lorem. Ut vehicula quis augue sed aliquet. Nulla viverra turpis nulla. Morbi et ipsum odio. Nulla in nisi suscipit justo blandit tristique ac vitae ipsum. Donec viverra dictum arcu. Duis est elit, ultrices a massa non, lobortis maximus eros. Nulla porttitor rhoncus lectus in finibus. Duis convallis sapien porta, fringilla orci nec, ultricies nisl. Morbi pulvinar quam in nulla rutrum euismod.
|
||||
|
||||
Donec et accumsan lectus, consectetur posuere nunc. Quisque et quam hendrerit, vestibulum quam eget, luctus enim. In hac habitasse platea dictumst. Nunc et est scelerisque, bibendum neque quis, ornare elit. Aliquam erat volutpat. Nulla maximus nibh vitae ex interdum, a efficitur lacus eleifend. Nam vestibulum blandit aliquet. In hac habitasse platea dictumst. Maecenas interdum quam et lorem posuere interdum. Mauris id feugiat augue. Etiam vestibulum pharetra cursus.
|
|
@ -1,173 +0,0 @@
|
|||
package frontmatter
|
||||
|
||||
import (
|
||||
"log"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/hacdias/caddy-hugo/tools/variables"
|
||||
"github.com/spf13/cast"
|
||||
"github.com/spf13/hugo/parser"
|
||||
)
|
||||
|
||||
const (
|
||||
mainName = "#MAIN#"
|
||||
objectType = "object"
|
||||
arrayType = "array"
|
||||
)
|
||||
|
||||
var mainTitle = ""
|
||||
|
||||
// Pretty creates a new FrontMatter object
|
||||
func Pretty(content []byte) (interface{}, string, error) {
|
||||
frontType := parser.DetectFrontMatter(rune(content[0]))
|
||||
front, err := frontType.Parse(content)
|
||||
|
||||
if err != nil {
|
||||
return []string{}, mainTitle, err
|
||||
}
|
||||
|
||||
object := new(frontmatter)
|
||||
object.Type = objectType
|
||||
object.Name = mainName
|
||||
|
||||
return rawToPretty(front, object), mainTitle, nil
|
||||
}
|
||||
|
||||
type frontmatter struct {
|
||||
Name string
|
||||
Title string
|
||||
Content interface{}
|
||||
Type string
|
||||
HTMLType string
|
||||
Parent *frontmatter
|
||||
}
|
||||
|
||||
func rawToPretty(config interface{}, parent *frontmatter) interface{} {
|
||||
objects := []*frontmatter{}
|
||||
arrays := []*frontmatter{}
|
||||
fields := []*frontmatter{}
|
||||
|
||||
cnf := map[string]interface{}{}
|
||||
|
||||
if reflect.TypeOf(config) == reflect.TypeOf(map[interface{}]interface{}{}) {
|
||||
for key, value := range config.(map[interface{}]interface{}) {
|
||||
cnf[key.(string)] = value
|
||||
}
|
||||
} else if reflect.TypeOf(config) == reflect.TypeOf([]interface{}{}) {
|
||||
for key, value := range config.([]interface{}) {
|
||||
cnf[string(key)] = value
|
||||
}
|
||||
} else {
|
||||
cnf = config.(map[string]interface{})
|
||||
}
|
||||
|
||||
for name, element := range cnf {
|
||||
if variables.IsMap(element) {
|
||||
objects = append(objects, handleObjects(element, parent, name))
|
||||
} else if variables.IsSlice(element) {
|
||||
arrays = append(arrays, handleArrays(element, parent, name))
|
||||
} else {
|
||||
if name == "title" && parent.Name == mainName {
|
||||
mainTitle = element.(string)
|
||||
}
|
||||
|
||||
fields = append(fields, handleFlatValues(element, parent, name))
|
||||
}
|
||||
}
|
||||
|
||||
sort.Sort(sortByTitle(objects))
|
||||
sort.Sort(sortByTitle(arrays))
|
||||
sort.Sort(sortByTitle(fields))
|
||||
|
||||
settings := []*frontmatter{}
|
||||
settings = append(settings, fields...)
|
||||
settings = append(settings, arrays...)
|
||||
settings = append(settings, objects...)
|
||||
return settings
|
||||
}
|
||||
|
||||
type sortByTitle []*frontmatter
|
||||
|
||||
func (f sortByTitle) Len() int { return len(f) }
|
||||
func (f sortByTitle) Swap(i, j int) { f[i], f[j] = f[j], f[i] }
|
||||
func (f sortByTitle) Less(i, j int) bool {
|
||||
return strings.ToLower(f[i].Name) < strings.ToLower(f[j].Name)
|
||||
}
|
||||
|
||||
func handleObjects(content interface{}, parent *frontmatter, name string) *frontmatter {
|
||||
c := new(frontmatter)
|
||||
c.Parent = parent
|
||||
c.Type = objectType
|
||||
c.Title = name
|
||||
|
||||
if parent.Name == mainName {
|
||||
c.Name = c.Title
|
||||
} else if parent.Type == arrayType {
|
||||
c.Name = parent.Name + "[]"
|
||||
} else {
|
||||
c.Name = parent.Name + "[" + c.Title + "]"
|
||||
}
|
||||
|
||||
c.Content = rawToPretty(content, c)
|
||||
return c
|
||||
}
|
||||
|
||||
func handleArrays(content interface{}, parent *frontmatter, name string) *frontmatter {
|
||||
c := new(frontmatter)
|
||||
c.Parent = parent
|
||||
c.Type = arrayType
|
||||
c.Title = name
|
||||
|
||||
if parent.Name == mainName {
|
||||
c.Name = name
|
||||
} else {
|
||||
c.Name = parent.Name + "[" + name + "]"
|
||||
}
|
||||
|
||||
c.Content = rawToPretty(content, c)
|
||||
return c
|
||||
}
|
||||
|
||||
func handleFlatValues(content interface{}, parent *frontmatter, name string) *frontmatter {
|
||||
c := new(frontmatter)
|
||||
c.Parent = parent
|
||||
|
||||
switch reflect.ValueOf(content).Kind() {
|
||||
case reflect.Bool:
|
||||
c.Type = "boolean"
|
||||
case reflect.Int, reflect.Float32, reflect.Float64:
|
||||
c.Type = "number"
|
||||
default:
|
||||
c.Type = "string"
|
||||
}
|
||||
|
||||
c.Content = content
|
||||
|
||||
switch strings.ToLower(name) {
|
||||
case "description":
|
||||
c.HTMLType = "textarea"
|
||||
case "date", "publishdate":
|
||||
c.HTMLType = "datetime"
|
||||
c.Content = cast.ToTime(content)
|
||||
default:
|
||||
c.HTMLType = "text"
|
||||
}
|
||||
|
||||
if parent.Type == arrayType {
|
||||
c.Name = parent.Name + "[]"
|
||||
c.Title = content.(string)
|
||||
} else if parent.Type == objectType {
|
||||
c.Title = name
|
||||
c.Name = parent.Name + "[" + name + "]"
|
||||
|
||||
if parent.Name == mainName {
|
||||
c.Name = name
|
||||
}
|
||||
} else {
|
||||
log.Panic("Parent type not allowed in handleFlatValues.")
|
||||
}
|
||||
|
||||
return c
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
package hugo
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/hacdias/caddy-hugo/config"
|
||||
"github.com/hacdias/caddy-hugo/tools/commands"
|
||||
)
|
||||
|
||||
// Run is used to run the static website generator
|
||||
func Run(c *config.Config.Config, force bool) {
|
||||
os.RemoveAll(c.Path + "public")
|
||||
|
||||
// Prevent running if watching is enabled
|
||||
if b, pos := stringInSlice("--watch", c.Args); b && !force {
|
||||
if len(c.Args) > pos && c.Args[pos+1] != "false" {
|
||||
return
|
||||
}
|
||||
|
||||
if len(c.Args) == pos+1 {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if err := commands.Run(c.Hugo, c.Args, c.Path); err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
package installer
|
||||
|
||||
var (
|
||||
sha256Hash = map[string]string{
|
||||
"hugo_0.16_darwin-arm32.tgz": "683d5d4b4e0ac03a183ca5eb9019981ba696569445c7d6d1efc7e6706bd273a5",
|
||||
"hugo_0.16_dragonfly-64bit.tgz": "63a3ee9a36d4d2166c77b96bb8bf39b2239affe118e44a83b3d0a44374a8921d",
|
||||
"hugo_0.16_freebsd-32bit.tgz": "ea3f84900feeeb9d89573dea49a4349753116e70de561eeec4858f7ffc74f8f9",
|
||||
"hugo_0.16_freebsd-64bit.tgz": "8d9320bb660090a77a4f922ca30b1582593bc6d87c3fd8bd6f5ecbe49cf1d2f2",
|
||||
"hugo_0.16_freebsd-arm32.tgz": "b4c21296e01ea68709ac50d7eb1d314b738f1c8408ff2be223d06ae76604dbea",
|
||||
"hugo_0.16_linux-32bit.tgz": "aed82d156f01a4562c39bd1af41aa81699009140da965e0369c370ba874725c9",
|
||||
"hugo_0.16_linux-64bit.tgz": "13e299dc45bea4fad5bdf8c2640305a5926e2acd02c3aa03b7864403e513920e",
|
||||
"hugo_0.16_linux-arm32.tgz": "bc836def127d93e2457da9994f9c09b0100523e46d61074cd724ef092b11714f",
|
||||
"hugo_0.16_linux-arm64.tgz": "d04486918f43f89f1e0359eebedd8a05d96f7ca40f93e7fd8d7c3f2dac115a8d",
|
||||
"hugo_0.16_netbsd-32bit.tgz": "cb578eebec5b6364b0afd5bb208d94317acab0a3e033b81f04b1511af0669b63",
|
||||
"hugo_0.16_netbsd-64bit.tgz": "d3c766d9800d7fdd268ffd2f28b7af451f13a4de63901bfdae2ee5c96528b8cc",
|
||||
"hugo_0.16_netbsd-arm32.tgz": "51162b2637e71b786582af715a44b778f62bdc62a9a354ccc4a7c8384afe194c",
|
||||
"hugo_0.16_openbsd-32bit.tgz": "2d1e112a7346850897ea77da868c0d987ef90efb7f49c917659437a5a67f89f8",
|
||||
"hugo_0.16_openbsd-64bit.tgz": "7b33ff2565df5a6253c3e4308813d947e34af04c633fb4e01cac83751066e16e",
|
||||
"hugo_0.16_osx-32bit.tgz": "6155dda548bbd1e26c26a4a00472e4c0e55fad9fcd46991ce90987385bd5fd0a",
|
||||
"hugo_0.16_osx-64bit.tgz": "b0cba8f6996946ef34a664184d6461567d79fc2a3e793145d34379902eda0ad9",
|
||||
"hugo_0.16_solaris-64bit.tgz": "af9557403af5e16eb7faf965c04540417a70699efbbbc4e0a7ae4c4703ad1ae8",
|
||||
"hugo_0.16_windows-32bit.zip": "1c72d06843fe02cb62348660d87a523c885ed684a683271fc8762e7234c4210b",
|
||||
"hugo_0.16_windows-64bit.zip": "a3fda0bd30592e4eb3bdde85c8a8ce23a7433073536466d16fd0e97bf7794067",
|
||||
}
|
||||
)
|
|
@ -1,216 +0,0 @@
|
|||
package installer
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
|
||||
"github.com/hacdias/caddy-hugo/tools/files"
|
||||
"github.com/mitchellh/go-homedir"
|
||||
"github.com/pivotal-golang/archiver/extractor"
|
||||
)
|
||||
|
||||
const (
|
||||
version = "0.16"
|
||||
baseurl = "https://github.com/spf13/hugo/releases/download/v" + version + "/"
|
||||
)
|
||||
|
||||
var caddy, bin, temp, hugo, tempfile, zipname, exename string
|
||||
|
||||
// GetPath retrives the Hugo path for the user or install it if it's not found
|
||||
func GetPath() string {
|
||||
initializeVariables()
|
||||
|
||||
var err error
|
||||
|
||||
// Check if Hugo is already on $PATH
|
||||
if hugo, err = exec.LookPath("hugo"); err == nil {
|
||||
if checkVersion() {
|
||||
return hugo
|
||||
}
|
||||
}
|
||||
|
||||
// Check if Hugo is on $HOME/.caddy/bin
|
||||
if _, err = os.Stat(hugo); err == nil {
|
||||
if checkVersion() {
|
||||
return hugo
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println("Unable to find Hugo on your computer.")
|
||||
|
||||
// Create the neccessary folders
|
||||
os.MkdirAll(caddy, 0774)
|
||||
os.Mkdir(bin, 0774)
|
||||
|
||||
if temp, err = ioutil.TempDir("", "caddy-hugo"); err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
downloadHugo()
|
||||
checkSHA256()
|
||||
|
||||
fmt.Print("Unzipping... ")
|
||||
|
||||
// Unzip or Ungzip the file
|
||||
switch runtime.GOOS {
|
||||
case "darwin", "windows":
|
||||
zp := extractor.NewZip()
|
||||
err = zp.Extract(tempfile, temp)
|
||||
default:
|
||||
gz := extractor.NewTgz()
|
||||
err = gz.Extract(tempfile, temp)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
fmt.Println("done.")
|
||||
|
||||
var exetorename string
|
||||
|
||||
err = filepath.Walk(temp, func(path string, f os.FileInfo, err error) error {
|
||||
if f.Name() == exename {
|
||||
exetorename = path
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
// Copy the file
|
||||
fmt.Print("Moving Hugo executable... ")
|
||||
err = files.CopyFile(exetorename, hugo)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
err = os.Chmod(hugo, 0755)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
fmt.Println("done.")
|
||||
fmt.Println("Hugo installed at " + hugo)
|
||||
defer os.RemoveAll(temp)
|
||||
return hugo
|
||||
}
|
||||
|
||||
func initializeVariables() {
|
||||
var arch string
|
||||
switch runtime.GOARCH {
|
||||
case "amd64":
|
||||
arch = "64bit"
|
||||
case "386":
|
||||
arch = "32bit"
|
||||
case "arm":
|
||||
arch = "arm32"
|
||||
default:
|
||||
arch = runtime.GOARCH
|
||||
}
|
||||
|
||||
var ops = runtime.GOOS
|
||||
if runtime.GOOS == "darwin" && runtime.GOARCH != "arm" {
|
||||
ops = "osx"
|
||||
}
|
||||
|
||||
exename = "hugo"
|
||||
zipname = "hugo_" + version + "_" + ops + "-" + arch
|
||||
|
||||
homedir, err := homedir.Dir()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
caddy = filepath.Join(homedir, ".caddy")
|
||||
bin = filepath.Join(caddy, "bin")
|
||||
hugo = filepath.Join(bin, "hugo")
|
||||
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
zipname += ".zip"
|
||||
exename += ".exe"
|
||||
hugo += ".exe"
|
||||
default:
|
||||
zipname += ".tgz"
|
||||
}
|
||||
}
|
||||
|
||||
func checkVersion() bool {
|
||||
out, _ := exec.Command("hugo", "version").Output()
|
||||
|
||||
r := regexp.MustCompile(`v\d\.\d{2}`)
|
||||
v := r.FindStringSubmatch(string(out))[0]
|
||||
v = v[1:len(v)]
|
||||
|
||||
return (v == version)
|
||||
}
|
||||
|
||||
func downloadHugo() {
|
||||
tempfile = filepath.Join(temp, zipname)
|
||||
|
||||
fmt.Print("Downloading Hugo from GitHub releases... ")
|
||||
|
||||
// Create the file
|
||||
out, err := os.Create(tempfile)
|
||||
out.Chmod(0774)
|
||||
if err != nil {
|
||||
defer os.RemoveAll(temp)
|
||||
fmt.Println(err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
// Get the data
|
||||
resp, err := http.Get(baseurl + zipname)
|
||||
if err != nil {
|
||||
fmt.Println("An error ocurred while downloading. If this error persists, try downloading Hugo from \"https://github.com/spf13/hugo/releases/\" and put the executable in " + bin + " and rename it to 'hugo' or 'hugo.exe' if you're on Windows.")
|
||||
fmt.Println(err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
// Writer the body to file
|
||||
_, err = io.Copy(out, resp.Body)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
fmt.Println("downloaded.")
|
||||
}
|
||||
|
||||
func checkSHA256() {
|
||||
fmt.Print("Checking SHA256...")
|
||||
|
||||
hasher := sha256.New()
|
||||
f, err := os.Open(tempfile)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer f.Close()
|
||||
if _, err := io.Copy(hasher, f); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if hex.EncodeToString(hasher.Sum(nil)) != sha256Hash[zipname] {
|
||||
fmt.Println("can't verify SHA256.")
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
fmt.Println("checked!")
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// RespondJSON used to send JSON responses to the web server
|
||||
func RespondJSON(w http.ResponseWriter, message interface{}, code int, err error) (int, error) {
|
||||
if message == nil {
|
||||
message = map[string]string{}
|
||||
}
|
||||
|
||||
msg, msgErr := json.Marshal(message)
|
||||
|
||||
if msgErr != nil {
|
||||
return 500, msgErr
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(code)
|
||||
w.Write(msg)
|
||||
return 0, err
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ParseURLComponents parses the components of an URL creating an array
|
||||
func ParseURLComponents(r *http.Request) []string {
|
||||
//The URL that the user queried.
|
||||
path := r.URL.Path
|
||||
path = strings.TrimSpace(path)
|
||||
//Cut off the leading and trailing forward slashes, if they exist.
|
||||
//This cuts off the leading forward slash.
|
||||
if strings.HasPrefix(path, "/") {
|
||||
path = path[1:]
|
||||
}
|
||||
//This cuts off the trailing forward slash.
|
||||
if strings.HasSuffix(path, "/") {
|
||||
cutOffLastCharLen := len(path) - 1
|
||||
path = path[:cutOffLastCharLen]
|
||||
}
|
||||
//We need to isolate the individual components of the path.
|
||||
components := strings.Split(path, "/")
|
||||
return components
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
package templates
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/hacdias/caddy-hugo/routes/assets"
|
||||
)
|
||||
|
||||
// CanBeEdited checks if the extension of a file is supported by the editor
|
||||
func CanBeEdited(filename string) bool {
|
||||
extensions := [...]string{
|
||||
"md", "markdown", "mdown", "mmark",
|
||||
"asciidoc", "adoc", "ad",
|
||||
"rst",
|
||||
".json", ".toml", ".yaml",
|
||||
".css", ".sass", ".scss",
|
||||
".js",
|
||||
".html",
|
||||
".txt",
|
||||
}
|
||||
|
||||
for _, extension := range extensions {
|
||||
if strings.HasSuffix(filename, extension) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// Get is used to get a ready to use template based on the url and on
|
||||
// other sent templates
|
||||
func Get(r *http.Request, functions template.FuncMap, templates ...string) (*template.Template, error) {
|
||||
// If this is a pjax request, use the minimal template to send only
|
||||
// the main content
|
||||
if r.Header.Get("X-PJAX") == "true" {
|
||||
templates = append(templates, "base_minimal")
|
||||
} else {
|
||||
templates = append(templates, "base_full")
|
||||
}
|
||||
|
||||
var tpl *template.Template
|
||||
|
||||
// For each template, add it to the the tpl variable
|
||||
for i, t := range templates {
|
||||
// Get the template from the assets
|
||||
page, err := assets.Asset("templates/" + t + ".tmpl")
|
||||
|
||||
// Check if there is some error. If so, the template doesn't exist
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return new(template.Template), err
|
||||
}
|
||||
|
||||
// If it's the first iteration, creates a new template and add the
|
||||
// functions map
|
||||
if i == 0 {
|
||||
tpl, err = template.New(t).Funcs(functions).Parse(string(page))
|
||||
} else {
|
||||
tpl, err = tpl.Parse(string(page))
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return new(template.Template), err
|
||||
}
|
||||
}
|
||||
|
||||
return tpl, nil
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
package templates
|
||||
|
||||
import "testing"
|
||||
|
||||
type canBeEdited struct {
|
||||
file string
|
||||
result bool
|
||||
}
|
||||
|
||||
var canBeEditedPairs = []canBeEdited{
|
||||
{"file.markdown", true},
|
||||
{"file.md", true},
|
||||
{"file.json", true},
|
||||
{"file.toml", true},
|
||||
{"file.yaml", true},
|
||||
{"file.css", true},
|
||||
{"file.sass", true},
|
||||
{"file.scss", true},
|
||||
{"file.js", true},
|
||||
{"file.html", true},
|
||||
{"file.git", false},
|
||||
{"file.log", false},
|
||||
{"file.sh", false},
|
||||
{"file.png", false},
|
||||
{"file.jpg", false},
|
||||
}
|
||||
|
||||
func TestCanBeEdited(t *testing.T) {
|
||||
for _, pair := range canBeEditedPairs {
|
||||
v := CanBeEdited(pair.file)
|
||||
if v != pair.result {
|
||||
t.Error(
|
||||
"For", pair.file,
|
||||
"expected", pair.result,
|
||||
"got", v,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue