diff --git a/edit/edit.go b/edit/edit.go index 0b3d0d7f..9716ccd1 100644 --- a/edit/edit.go +++ b/edit/edit.go @@ -50,7 +50,7 @@ func Execute(w http.ResponseWriter, r *http.Request) (int, error) { page := new(page.Page) page.Title = "Edit" page.Body = inf - return page.Render(w, "edit") + return page.Render(w, r, "edit") } return 200, nil diff --git a/frontmatter/frontmatter.go b/frontmatter/frontmatter.go index 2cfb5117..f4e97012 100644 --- a/frontmatter/frontmatter.go +++ b/frontmatter/frontmatter.go @@ -24,12 +24,12 @@ func Pretty(content []byte, language string) (interface{}, error) { return []string{}, err } + //log.Print(c) return rawToPretty(c, ""), nil } type frontmatter struct { Name string - Tag string Content interface{} SubContent bool } @@ -55,7 +55,6 @@ func rawToPretty(config interface{}, master string) interface{} { for index := range names { c := new(frontmatter) c.Name = names[index] - c.Tag = master + "_" + names[index] c.SubContent = false i := config.(map[string]interface{})[names[index]] diff --git a/hugo.go b/hugo.go index ea2b1f4a..d3d3e6f3 100644 --- a/hugo.go +++ b/hugo.go @@ -1,4 +1,4 @@ -//go:generate go-bindata -pkg assets -o assets/assets.go static/css/ static/js/ templates/ +//go:generate go-bindata -pkg assets -o assets/assets.go static/css/ static/js/ templates/ static/ package hugo @@ -31,8 +31,8 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) if middleware.Path(r.URL.Path).Matches("/admin") { page := parseComponents(r)[1] - if page == "assets" { - filename := strings.Replace(r.URL.Path, "/admin/assets", "static", 1) + if page == "static" { + filename := strings.Replace(r.URL.Path, "/admin/", "", 1) file, err := assets.Asset(filename) if err != nil { diff --git a/page/page.go b/page/page.go index c8be31cc..cffb5fd5 100644 --- a/page/page.go +++ b/page/page.go @@ -24,8 +24,13 @@ type Page struct { } // Render the page -func (p *Page) Render(w http.ResponseWriter, templates ...string) (int, error) { - templates = append(templates, "base_full") +func (p *Page) Render(w http.ResponseWriter, r *http.Request, templates ...string) (int, error) { + if r.URL.Query().Get("minimal") == "true" { + templates = append(templates, "base_minimal") + } else { + templates = append(templates, "base_full") + } + var tpl *template.Template for i, t := range templates { diff --git a/settings/settings.go b/settings/settings.go index 66280ea0..1727db99 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -1,6 +1,8 @@ package settings import ( + "bytes" + "encoding/json" "io/ioutil" "log" "net/http" @@ -8,20 +10,46 @@ import ( "github.com/hacdias/caddy-hugo/frontmatter" "github.com/hacdias/caddy-hugo/page" + "github.com/spf13/hugo/commands" ) +type test struct { + Test string +} + // Execute the page func Execute(w http.ResponseWriter, r *http.Request) (int, error) { + language := getConfigFrontMatter() + + if language == "" { + log.Print("Configuration frontmatter can't be defined") + return 500, nil + } + if r.Method == "POST" { + err := os.Remove("config." + language) - } else { - language := getConfigFrontMatter() - - if language == "" { - log.Print("Configuration frontmatter can't be defined") + if err != nil { + log.Print(err) return 500, nil } + buf := new(bytes.Buffer) + buf.ReadFrom(r.Body) + raw := buf.Bytes() + + content := new(bytes.Buffer) + json.Indent(content, raw, "", " ") + + err = ioutil.WriteFile("config.json", content.Bytes(), 0666) + + if err != nil { + log.Print(err) + return 500, err + } + + commands.Execute() + } else { content, err := ioutil.ReadFile("config." + language) if err != nil { @@ -39,7 +67,7 @@ func Execute(w http.ResponseWriter, r *http.Request) (int, error) { page := new(page.Page) page.Title = "Settings" page.Body = f - return page.Render(w, "settings", "frontmatter") + return page.Render(w, r, "settings", "frontmatter") } return 200, nil } diff --git a/static/css/main.css b/static/css/main.css index b4073cc7..57839442 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -1,36 +1,76 @@ body { - font-family: 'Roboto', sans-serif; - padding-top: 3em; + font-family: 'Roboto', sans-serif; + color: #212121; + height: 100%; + width: 100%; } - -/* SITE HEADER */ - -.site-header { - height: 3em; - width: 100%; - background-color: #263238; - color: #fff; - padding: 0 2em; - box-sizing: border-box; - position: fixed; - top: 0; - left: 0; +header { + position: fixed; + top: 0; + left: 0; + height: 3em; + width: 100%; + background-color: #212121; + padding: 0 2em; + box-sizing: border-box; + z-index: 999; + color: #fff; +} +header nav {} header nav ul { + margin: 0; + padding: 0; +} +header nav ul li { + list-style-type: none; + display: inline-block; + vertical-align: middle; +} +header nav img { + height: 2em; +} +header nav ul li a { + padding: 0.5em 0.5em; + line-height: 2em; + display: block; + text-decoration: none; + color: inherit; + transition: .5s ease background-color; +} +header nav ul li a:hover { + background-color: rgba(255, 255, 255, 0.3); +} +main { + top: 3em; + position: relative; } - .content { - margin: 1.5em auto; - width: 80%; - max-width: 960px; + margin: 1.5em auto; + width: 80%; + max-width: 800px; } - textarea { - width: 100%; - min-height: 50em; - resize: vertical; - border: 0; - font-family: inherit; + width: 100%; + min-height: 50em; + resize: vertical; + border: 0; + font-family: inherit; } -.block { - margin: 1em 0; +/* FORMS */ + +form { + } + +form input { + +color: rgba(0, 0, 0, 0.41);width: 15em;line-height: 1.25em;margin: .5em 0;border: 1px solid #fff;transition: .5s ease-out all;} + +form input:focus { + color: inherit; + outline: 0; + border-bottom: 1px solid #2196F3; +} + +form label { +width: 10.5em;display: inline-block;} diff --git a/static/hugo.png b/static/hugo.png new file mode 100644 index 00000000..aa15c5ed Binary files /dev/null and b/static/hugo.png differ diff --git a/static/js/app.js b/static/js/app.js index e69de29b..7375b563 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -0,0 +1,38 @@ +$(document).ready(function() { + $('form').submit(function(event) { + var data = JSON.stringify($(this).serializeField()) + var url = $(this).attr('action') + + $.ajax({ + type : 'POST', + url : url, + data : data, + dataType : 'json', + encode : true + }).done(function(data) { + console.log(data); + }); + + event.preventDefault(); + }); +}); + +$.fn.serializeField = function() { + var result = {}; + this.each(function() { + $(this).find("> *").each(function() { + var $this = $(this); + var name = $this.attr("name"); + + if ($this.is("fieldset") && name) { + result[name] = $this.serializeField(); + } + else { + $.each($this.serializeArray(), function() { + result[this.name] = this.value; + }); + } + }); + }); + return result; +}; diff --git a/templates/base_full.tmpl b/templates/base_full.tmpl index 8ffdf5d0..7e801a1a 100644 --- a/templates/base_full.tmpl +++ b/templates/base_full.tmpl @@ -1,28 +1,37 @@ -
- - - - -