mirror of
https://github.com/filebrowser/filebrowser.git
synced 2025-05-08 19:22:57 +00:00
update frontmatter
This commit is contained in:
parent
d061c26caf
commit
8f31f5896c
@ -67,11 +67,12 @@ module.exports = function(grunt) {
|
|||||||
uglify: {
|
uglify: {
|
||||||
target: {
|
target: {
|
||||||
files: {
|
files: {
|
||||||
'assets/js/app.min.js': ['node_modules/jquery/dist/jquery.js',
|
'assets/js/app.min.js': ['node_modules/jquery/dist/jquery.min.js',
|
||||||
'node_modules/perfect-scrollbar/dist/js/perfect-scrollbar.jquery.js',
|
'node_modules/perfect-scrollbar/dist/js/min/perfect-scrollbar.jquery.min.js',
|
||||||
'node_modules/showdown/dist/showdown.js',
|
'node_modules/showdown/dist/showdown.min.js',
|
||||||
'node_modules/noty/js/noty/packaged/jquery.noty.packaged.js',
|
'node_modules/noty/js/noty/packaged/jquery.noty.packaged.min.js',
|
||||||
'node_modules/jquery-pjax/jquery.pjax.js',
|
'node_modules/jquery-pjax/jquery.pjax.js',
|
||||||
|
'node_modules/jquery-serializejson/jquery.serializejson.min.js',
|
||||||
'assets/js/src/**/*.js'
|
'assets/js/src/**/*.js'
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
8
assets/css/main.min.css
vendored
8
assets/css/main.min.css
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
12
assets/js/app.min.js
vendored
12
assets/js/app.min.js
vendored
File diff suppressed because one or more lines are too long
@ -38,12 +38,16 @@ $(document).ready(function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$('form').submit(function(event) {
|
$('form').submit(function(event) {
|
||||||
var data = JSON.stringify($(this).serializeForm()),
|
event.preventDefault();
|
||||||
|
|
||||||
|
var data = $(this).serializeJSON(),
|
||||||
url = $(this).attr('action'),
|
url = $(this).attr('action'),
|
||||||
button = $(this).find("input[type=submit]:focus"),
|
button = $(this).find("input[type=submit]:focus"),
|
||||||
action = button.val();
|
action = button.val();
|
||||||
|
|
||||||
$.ajax({
|
console.log(data);
|
||||||
|
|
||||||
|
/*$.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: url,
|
url: url,
|
||||||
data: data,
|
data: data,
|
||||||
@ -64,9 +68,7 @@ $(document).ready(function() {
|
|||||||
type: 'error'
|
type: 'error'
|
||||||
});
|
});
|
||||||
console.log(data);
|
console.log(data);
|
||||||
});
|
}); */
|
||||||
|
|
||||||
event.preventDefault();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#logout").click(function(e) {
|
$("#logout").click(function(e) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package frontmatter
|
package frontmatter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/hacdias/caddy-hugo/utils"
|
"github.com/hacdias/caddy-hugo/utils"
|
||||||
@ -16,18 +17,210 @@ func Pretty(content []byte) (interface{}, error) {
|
|||||||
return []string{}, err
|
return []string{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return rawToPretty(front, "", ""), nil
|
object := new(frontmatter)
|
||||||
|
object.Type = "object"
|
||||||
|
|
||||||
|
return rawToPretty(front, object), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type frontmatter struct {
|
type frontmatter struct {
|
||||||
Name string
|
Name string
|
||||||
|
Title string
|
||||||
Content interface{}
|
Content interface{}
|
||||||
Parent string
|
|
||||||
Type string
|
Type string
|
||||||
|
Parent *frontmatter
|
||||||
}
|
}
|
||||||
|
|
||||||
func rawToPretty(config interface{}, master string, parent string) interface{} {
|
func sortByTitle(config []*frontmatter) {
|
||||||
if utils.IsSlice(config) {
|
keys := make([]string, len(config))
|
||||||
|
positionByTitle := make(map[string]int)
|
||||||
|
|
||||||
|
for index, element := range config {
|
||||||
|
keys[index] = element.Title
|
||||||
|
positionByTitle[element.Title] = index
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Strings(keys)
|
||||||
|
cnf := make([]*frontmatter, len(config))
|
||||||
|
|
||||||
|
for index, title := range keys {
|
||||||
|
cnf[index] = config[positionByTitle[title]]
|
||||||
|
}
|
||||||
|
|
||||||
|
for index := range config {
|
||||||
|
config[index] = cnf[index]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func rawToPretty(config interface{}, parent *frontmatter) interface{} {
|
||||||
|
objects := []*frontmatter{}
|
||||||
|
arrays := []*frontmatter{}
|
||||||
|
fields := []*frontmatter{}
|
||||||
|
|
||||||
|
if parent.Type == "array" {
|
||||||
|
for index, element := range config.([]interface{}) {
|
||||||
|
c := new(frontmatter)
|
||||||
|
c.Parent = parent
|
||||||
|
|
||||||
|
if utils.IsMap(element) {
|
||||||
|
c.Type = "object"
|
||||||
|
|
||||||
|
if parent.Name == "" {
|
||||||
|
c.Name = c.Title
|
||||||
|
} else {
|
||||||
|
c.Name = parent.Name + "[" + c.Name + "]"
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Content = rawToPretty(config.([]interface{})[index], c)
|
||||||
|
objects = append(objects, c)
|
||||||
|
} else if utils.IsSlice(element) {
|
||||||
|
c.Type = "array"
|
||||||
|
c.Name = parent.Name + "[" + c.Name + "]"
|
||||||
|
c.Content = rawToPretty(config.([]interface{})[index], c)
|
||||||
|
|
||||||
|
arrays = append(arrays, c)
|
||||||
|
} else {
|
||||||
|
// TODO: add string, boolean, number
|
||||||
|
c.Type = "string"
|
||||||
|
c.Name = parent.Name + "[]"
|
||||||
|
c.Title = element.(string)
|
||||||
|
c.Content = config.([]interface{})[index]
|
||||||
|
fields = append(fields, c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if parent.Type == "object" {
|
||||||
|
for name, element := range config.(map[string]interface{}) {
|
||||||
|
c := new(frontmatter)
|
||||||
|
c.Title = name
|
||||||
|
c.Parent = parent
|
||||||
|
|
||||||
|
if utils.IsMap(element) {
|
||||||
|
c.Type = "object"
|
||||||
|
|
||||||
|
if parent.Name == "" {
|
||||||
|
c.Name = c.Title
|
||||||
|
} else {
|
||||||
|
c.Name = parent.Name + "[" + c.Title + "]"
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Content = rawToPretty(config.(map[string]interface{})[name], c)
|
||||||
|
objects = append(objects, c)
|
||||||
|
} else if utils.IsSlice(element) {
|
||||||
|
c.Type = "array"
|
||||||
|
|
||||||
|
if parent.Name == "" {
|
||||||
|
c.Name = name
|
||||||
|
} else {
|
||||||
|
c.Name = parent.Name + "[" + c.Name + "]"
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Content = rawToPretty(config.(map[string]interface{})[c.Title], c)
|
||||||
|
|
||||||
|
arrays = append(arrays, c)
|
||||||
|
} else {
|
||||||
|
// TODO: add string, boolean, number
|
||||||
|
c.Type = "string"
|
||||||
|
|
||||||
|
if parent.Name == "" {
|
||||||
|
c.Name = name
|
||||||
|
} else {
|
||||||
|
c.Name = parent.Name + "[" + name + "]"
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Content = element
|
||||||
|
fields = append(fields, c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.Panic("Parent type not allowed.")
|
||||||
|
}
|
||||||
|
|
||||||
|
sortByTitle(objects)
|
||||||
|
sortByTitle(arrays)
|
||||||
|
sortByTitle(fields)
|
||||||
|
|
||||||
|
settings := []*frontmatter{}
|
||||||
|
settings = append(settings, fields...)
|
||||||
|
settings = append(settings, arrays...)
|
||||||
|
settings = append(settings, objects...)
|
||||||
|
|
||||||
|
return settings
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
objects := make([]interface{}, len(objectsNames))
|
||||||
|
|
||||||
|
for index := range objectsNames {
|
||||||
|
c := new(frontmatter)
|
||||||
|
c.Type = "object"
|
||||||
|
c.Title = objectsNames[index]
|
||||||
|
|
||||||
|
if parent.Name == "" {
|
||||||
|
c.Name = c.Title
|
||||||
|
} else {
|
||||||
|
c.Name = parent.Name + "[" + c.Name + "]"
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Content = rawToPretty(config.(map[string]interface{})[c.Title], c)
|
||||||
|
log.Print("\n\nObject Name:\n")
|
||||||
|
log.Print(c.Name)
|
||||||
|
objects[index] = c
|
||||||
|
}
|
||||||
|
|
||||||
|
arrays := make([]interface{}, len(arraysNames))
|
||||||
|
|
||||||
|
for index := range arraysNames {
|
||||||
|
c := new(frontmatter)
|
||||||
|
c.Type = "array"
|
||||||
|
c.Title = arraysNames[index]
|
||||||
|
c.Name = parent.Name + c.Title + "[]"
|
||||||
|
c.Content = rawToPretty(config.(map[string]interface{})[c.Title], c)
|
||||||
|
log.Print("\n\nArray Name:\n")
|
||||||
|
log.Print(c.Name)
|
||||||
|
arrays[index] = c
|
||||||
|
}
|
||||||
|
|
||||||
|
/*strings := make([]interface{}, len(stringsNames))*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
for index := range stringsNames {
|
||||||
|
c := new(frontmatter)
|
||||||
|
c.Title = stringsNames[index]
|
||||||
|
c.Name = giveName(c.Title, parent)
|
||||||
|
|
||||||
|
log.Print(c.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* names := append(stringsNames, mapsNames...)
|
||||||
|
|
||||||
|
settings := make([]interface{}, len(names))
|
||||||
|
|
||||||
|
for index := range names {
|
||||||
|
c := new(frontmatter)
|
||||||
|
c.Name = names[index]
|
||||||
|
c.Parent = parent
|
||||||
|
|
||||||
|
i := config.(map[string]interface{})[names[index]]
|
||||||
|
|
||||||
|
if utils.IsMap(i) {
|
||||||
|
c.Type = "object"
|
||||||
|
c.Content = rawToPretty(i, c.Name, "object")
|
||||||
|
} else if utils.IsSlice(i) {
|
||||||
|
c.Type = "array"
|
||||||
|
c.Content = rawToPretty(i, c.Name, "array")
|
||||||
|
} else {
|
||||||
|
c.Type = "text"
|
||||||
|
c.Content = i
|
||||||
|
}
|
||||||
|
|
||||||
|
settings[index] = c
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
// settings := append(strings, slices..., maps...)
|
||||||
|
|
||||||
|
/*if utils.IsSlice(config) {
|
||||||
settings := make([]interface{}, len(config.([]interface{})))
|
settings := make([]interface{}, len(config.([]interface{})))
|
||||||
|
|
||||||
// TODO: improve this function
|
// TODO: improve this function
|
||||||
@ -54,43 +247,5 @@ func rawToPretty(config interface{}, master string, parent string) interface{} {
|
|||||||
return settings
|
return settings
|
||||||
}
|
}
|
||||||
|
|
||||||
var mapsNames []string
|
*/
|
||||||
var stringsNames []string
|
|
||||||
|
|
||||||
for index, element := range config.(map[string]interface{}) {
|
|
||||||
if utils.IsMap(element) || utils.IsSlice(element) {
|
|
||||||
mapsNames = append(mapsNames, index)
|
|
||||||
} else {
|
|
||||||
stringsNames = append(stringsNames, index)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sort.Strings(mapsNames)
|
|
||||||
sort.Strings(stringsNames)
|
|
||||||
names := append(stringsNames, mapsNames...)
|
|
||||||
|
|
||||||
settings := make([]interface{}, len(names))
|
|
||||||
|
|
||||||
for index := range names {
|
|
||||||
c := new(frontmatter)
|
|
||||||
c.Name = names[index]
|
|
||||||
c.Parent = parent
|
|
||||||
|
|
||||||
i := config.(map[string]interface{})[names[index]]
|
|
||||||
|
|
||||||
if utils.IsMap(i) {
|
|
||||||
c.Type = "object"
|
|
||||||
c.Content = rawToPretty(i, c.Name, "object")
|
|
||||||
} else if utils.IsSlice(i) {
|
|
||||||
c.Type = "array"
|
|
||||||
c.Content = rawToPretty(i, c.Name, "array")
|
|
||||||
} else {
|
|
||||||
c.Type = "text"
|
|
||||||
c.Content = i
|
|
||||||
}
|
|
||||||
|
|
||||||
settings[index] = c
|
|
||||||
}
|
|
||||||
|
|
||||||
return settings
|
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
"animate.css": "^3.4.0",
|
"animate.css": "^3.4.0",
|
||||||
"font-awesome": "^4.4.0",
|
"font-awesome": "^4.4.0",
|
||||||
"jquery": "^2.1.4",
|
"jquery": "^2.1.4",
|
||||||
|
"jquery-serializejson": "^2.5.0",
|
||||||
"normalize.css": "^3.0.3",
|
"normalize.css": "^3.0.3",
|
||||||
"noty": "^2.3.6",
|
"noty": "^2.3.6",
|
||||||
"perfect-scrollbar": "^0.6.4",
|
"perfect-scrollbar": "^0.6.4",
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
{{ define "frontmatter" }}
|
{{ define "frontmatter" }}
|
||||||
{{ range $key, $value := . }}
|
{{ range $key, $value := . }}
|
||||||
{{ if or (eq $value.Type "object") (eq $value.Type "array") }}
|
{{ if or (eq $value.Type "object") (eq $value.Type "array") }}
|
||||||
<fieldset name="{{ $value.Name }}" type="{{ $value.Type }}">
|
<fieldset>
|
||||||
<h3>{{ splitCapitalize $value.Name }} <button class="add"><i class="fa fa-plus"></i></button></h3>
|
<h3>{{ splitCapitalize $value.Title }} <button class="add"><i class="fa fa-plus"></i></button></h3>
|
||||||
{{ template "frontmatter" $value.Content }}
|
{{ template "frontmatter" $value.Content }}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
{{ else }}
|
{{ else }}
|
||||||
{{ if not (eq $value.Parent "array") }}
|
{{ if not (eq $value.Parent.Type "array") }}
|
||||||
<label for="{{ $value.Name }}">{{ splitCapitalize $value.Name }}</label>
|
<label for="{{ $value.Name }}">{{ splitCapitalize $value.Title }}</label>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
<input name="{{ $value.Name }}" id="{{ $value.Name }}" value="{{ $value.Content }}"></input><br>
|
<input name="{{ $value.Name }}" id="{{ $value.Name }}" value="{{ $value.Content }}"></input><br>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
@ -36,6 +36,22 @@ func IsArray(sth interface{}) bool {
|
|||||||
return reflect.ValueOf(sth).Kind() == reflect.Array
|
return reflect.ValueOf(sth).Kind() == reflect.Array
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsString(sth interface{}) bool {
|
||||||
|
return reflect.ValueOf(sth).Kind() == reflect.String
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsInt(sth interface{}) bool {
|
||||||
|
return reflect.ValueOf(sth).Kind() == reflect.Int
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsBool(sth interface{}) bool {
|
||||||
|
return reflect.ValueOf(sth).Kind() == reflect.Bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsInterface(sth interface{}) bool {
|
||||||
|
return reflect.ValueOf(sth).Kind() == reflect.Interface
|
||||||
|
}
|
||||||
|
|
||||||
func SplitCapitalize(name string) string {
|
func SplitCapitalize(name string) string {
|
||||||
var words []string
|
var words []string
|
||||||
l := 0
|
l := 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user