diff --git a/assets/public/css/styles.css b/assets/public/css/styles.css index e69de29b..79e570aa 100644 --- a/assets/public/css/styles.css +++ b/assets/public/css/styles.css @@ -0,0 +1,97 @@ +.editor input[type="text"], .editor input[type="datetime-local"], .editor textarea { + background-color: #f5f3f3; + border-radius: .5em; + border: 1px solid #ccc; + outline: none; + padding: .5em; + line-height: 1.2em; + width: 100%; + font-size: 1rem; + margin: 0; + transition: all 0.3s; +} +input[type="text"]:focus { + border-bottom: 1px solid #26a69a; +} +.editor .block { + margin-bottom: 1em; +} +.editor fieldset { + border: 0; + margin: 0; + padding: 0; +} +.editor h1 textarea { + font-size: 2em; + font-weight: 400; + resize: none; + overflow: hidden; + padding: 0; + line-height: 1em; + height: 1em; + background-color: transparent; + border: 0; +} +.editor fieldset h3 { + display: inline-block +} +.editor label { + font-size: .8em; + color: #8b8b8b; + font-weight: 500; +} +.editor .options { + column-count: 2; + column-gap: 1em; +} +.editor .block { + break-inside: avoid; + position: relative; + z-index: 0; +} +.editor .block .delete { + position: absolute; + right: 0; + bottom: 1px; + height: 2.5em; + padding: 0 .7em; + background: transparent; + color: rgba(0, 0, 0, 0.5); +} + +/* BUTTONS */ + +.editor button, .editor input[type="submit"] { + box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12); + border: none; + border-radius: 2px; + height: 36px; + line-height: 36px; + outline: 0; + padding: 0 2rem; + text-transform: uppercase; + text-decoration: none; + color: #fff; + background-color: #26a69a; + text-align: center; + letter-spacing: .5px; + position: relative; + cursor: pointer; + display: inline-block; + overflow: hidden; + vertical-align: middle; + transition: all .3s ease-out; +} + +/* TOOLBAR */ + +.editor #actions { + display: flex; + margin: 1em 0; +} +.editor #actions> div { + flex-basis: 50%; +} +.editor #actions div:nth-child(2) { + text-align: right; +} diff --git a/assets/public/js/application.js b/assets/public/js/application.js index 8e556af2..d1e6eb60 100644 --- a/assets/public/js/application.js +++ b/assets/public/js/application.js @@ -1,20 +1,5 @@ "use strict"; -var deleteHandler = function(event) { - event.preventDefault(); - let name = this.dataset.delete; - - let element = document.getElementById(name); - document.removeChild(element); - - //$('label[for="' + name + '"]').fadeOut().remove(); -// $('#' + name).fadeOut().remove(); - - return false; -} - -document.addEventListener("DOMContentLoaded", function(event) { - //alert("hugo is working"); - - return false; -}); +var ace = document.createElement('script'); +ace.src = 'https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.3/ace.js'; +document.head.appendChild(ace); diff --git a/assets/templates/editor.tmpl b/assets/templates/editor.tmpl index 337194de..b2e4ae91 100644 --- a/assets/templates/editor.tmpl +++ b/assets/templates/editor.tmpl @@ -1,61 +1,62 @@ {{ define "content" }} - - +
+{{ if eq .Class "complete" }} +

+ +

-
- {{ if eq .Class "complete" }} -

- {{ end }} -
-
- {{ if not (eq .Class "complete") }} -

{{ .Name }}

- {{ end }} - - {{ if eq .Class "frontmatter-only" }} -
- {{ template "options" .FrontMatter }} -

- -

-
- {{ else if eq .Class "content-only" }} -
-
- -
- {{ else }} -
-
- {{ template "options" .FrontMatter}} -
- -

- -

-
- -
- {{ if eq .Mode "markdown" }} - - {{ end}} -
- -
-
- {{ end }} - -

- - - {{ if and (eq .Class "complete") ( .IsPost ) }} {{ end }} - - -

-
-
+
+
+{{ template "frontmatter" .FrontMatter }} +
+ +
+{{ if eq .Mode "markdown" }} + +{{ end}} + +
+ +
+ +{{ else if eq .Class "content-only" }} +
+

{{ .Name }}

+ +
+
+ +
+
+{{ else }} +
+

{{ .Name }}

+ +
+{{ template "frontmatter" .FrontMatter }} + +
+
+{{ end }} + +
+
+ +
+
+{{ if and (eq .Class "complete") ( .IsPost ) }} +{{ end }} + +
+
+
+ {{ end }} diff --git a/assets/templates/frontmatter.tmpl b/assets/templates/frontmatter.tmpl deleted file mode 100644 index e37f9244..00000000 --- a/assets/templates/frontmatter.tmpl +++ /dev/null @@ -1,40 +0,0 @@ -{{ define "options" }} -{{ range $key, $value := . }} - - {{ if or (eq $value.Type "object") (eq $value.Type "array") }} -
-

{{ SplitCapitalize $value.Title }}

- - - {{ template "options" $value.Content }} -
- {{ else }} - - {{ if not (eq $value.Parent.Type "array") }} -
- - - - {{ end }} - - {{ if eq $value.Parent.Type "array" }} -
- {{ end }} - - {{ if eq $value.HTMLType "textarea" }} - - {{ else if eq $value.HTMLType "datetime" }} - - {{ else }} - - {{ end }} - - {{ if not (eq $value.Parent.Type "array") }}
{{ end }} - - {{ if eq $value.Parent.Type "array" }} -
- {{ end }} - -{{ end }} -{{ end }} -{{ end }} diff --git a/assets/templates/options.tmpl b/assets/templates/options.tmpl new file mode 100644 index 00000000..e10b039b --- /dev/null +++ b/assets/templates/options.tmpl @@ -0,0 +1,50 @@ +{{ define "frontmatter" }} + {{ range $key, $value := . }} + + {{ if or (eq $value.Type "object") (eq $value.Type "array") }} +
+
+

{{ SplitCapitalize $value.Title }}

+ + +
+ +
+ {{ template "frontmatter" $value.Content }} + +
+ +
+ {{ else }} + + {{ if not (eq $value.Parent.Type "array") }} +
+ + + + {{ end }} + + {{ if eq $value.Parent.Type "array" }} +
+ {{ end }} + + {{ if eq $value.HTMLType "textarea" }} + + {{ else if eq $value.HTMLType "datetime" }} + + {{ else }} + + {{ end }} + + {{ if not (eq $value.Parent.Type "array") }} +
+ {{ end }} + + {{ if eq $value.Parent.Type "array" }} + +
+ {{ end }} + + {{ end }} + {{ end }} +{{ end }} diff --git a/binary.go b/binary.go index d3b091a6..e8011866 100644 --- a/binary.go +++ b/binary.go @@ -3,7 +3,7 @@ // assets/public/css/styles.css // assets/public/js/application.js // assets/templates/editor.tmpl -// assets/templates/frontmatter.tmpl +// assets/templates/options.tmpl // DO NOT EDIT! package hugo @@ -84,10 +84,10 @@ func templatesEditorTmpl() (*asset, error) { return a, err } -// templatesFrontmatterTmpl reads file data from disk. It returns an error on failure. -func templatesFrontmatterTmpl() (*asset, error) { - path := "D:\\Code\\Go\\src\\github.com\\hacdias\\caddy-hugo\\assets\\templates\\frontmatter.tmpl" - name := "templates/frontmatter.tmpl" +// templatesOptionsTmpl reads file data from disk. It returns an error on failure. +func templatesOptionsTmpl() (*asset, error) { + path := "D:\\Code\\Go\\src\\github.com\\hacdias\\caddy-hugo\\assets\\templates\\options.tmpl" + name := "templates/options.tmpl" bytes, err := bindataRead(path, name) if err != nil { return nil, err @@ -157,7 +157,7 @@ var _bindata = map[string]func() (*asset, error){ "public/css/styles.css": publicCssStylesCss, "public/js/application.js": publicJsApplicationJs, "templates/editor.tmpl": templatesEditorTmpl, - "templates/frontmatter.tmpl": templatesFrontmatterTmpl, + "templates/options.tmpl": templatesOptionsTmpl, } // AssetDir returns the file names below a certain @@ -210,7 +210,7 @@ var _bintree = &bintree{nil, map[string]*bintree{ }}, "templates": &bintree{nil, map[string]*bintree{ "editor.tmpl": &bintree{templatesEditorTmpl, map[string]*bintree{}}, - "frontmatter.tmpl": &bintree{templatesFrontmatterTmpl, map[string]*bintree{}}, + "options.tmpl": &bintree{templatesOptionsTmpl, map[string]*bintree{}}, }}, }} diff --git a/get.go b/get.go index 44c8f55e..ac799485 100644 --- a/get.go +++ b/get.go @@ -2,6 +2,7 @@ package hugo import ( "bytes" + "fmt" "html/template" "io/ioutil" "net/http" @@ -42,14 +43,6 @@ func (h Hugo) GET(w http.ResponseWriter, r *http.Request, filename string) (int, return http.StatusInternalServerError, err } - page := &filemanager.Page{ - Info: &filemanager.PageInfo{ - IsDir: false, - Config: &h.FileManager.Configs[0], - Name: strings.Replace(filename, h.Config.Root, "", 1), - }, - } - // Create a new editor variable and set the extension data := new(editor) data.Mode = strings.TrimPrefix(filepath.Ext(filename), ".") @@ -114,9 +107,16 @@ func (h Hugo) GET(w http.ResponseWriter, r *http.Request, filename string) (int, var code int - page.Info.Data = data + page := &filemanager.Page{ + Info: &filemanager.PageInfo{ + IsDir: false, + Config: &h.FileManager.Configs[0], + Name: data.Name, + Data: data, + }, + } - templates := []string{"frontmatter", "editor"} + templates := []string{"options", "editor"} for _, t := range templates { code, err = page.AddTemplate(t, Asset, functions) if err != nil { @@ -132,7 +132,9 @@ func (h Hugo) GET(w http.ResponseWriter, r *http.Request, filename string) (int, } } - return page.PrintAsHTML(w) + code, err = page.PrintAsHTML(w) + fmt.Println(err) + return code, err } func hasFrontMatterRune(file []byte) bool {