Make updates

pull/82/head
Henrique Dias 2016-06-23 17:44:04 +01:00
parent 67f475ce42
commit 1675403010
7 changed files with 228 additions and 133 deletions

View File

@ -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;
}

View File

@ -1,20 +1,5 @@
"use strict"; "use strict";
var deleteHandler = function(event) { var ace = document.createElement('script');
event.preventDefault(); ace.src = 'https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.3/ace.js';
let name = this.dataset.delete; document.head.appendChild(ace);
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;
});

View File

@ -1,61 +1,62 @@
{{ define "content" }} {{ define "content" }}
<link rel="stylesheet" href="{{ .BaseURL }}/_hugointernal/css/styles.css"> <div class="container editor {{ .Class }}">
<script src="{{ .BaseURL }}/_hugointernal/js/application.js"></script> {{ if eq .Class "complete" }}
<h1>
<textarea id="site-title">{{ .Name }}</textarea>
</h1>
<div class="editor container {{ .Class }}"> <form method="POST" action=".">
{{ if eq .Class "complete" }} <div class="options">
<h1><textarea id="site-title">{{ .Name }}</textarea></h1> {{ template "frontmatter" .FrontMatter }}
{{ end }} <button id="add-field">Add field</button>
<form method="POST" action="">
<main>
{{ if not (eq .Class "complete") }}
<h1 id="site-title">{{ .Name }}</h1>
{{ end }}
{{ if eq .Class "frontmatter-only" }}
<div class="frontmatter blocks">
{{ template "options" .FrontMatter }}
<p class="actions">
<button class="add">Add field</button>
</p>
</div>
{{ else if eq .Class "content-only" }}
<div class="content">
<div id="editor-source" data-mode="{{ .Mode }}"></div>
<textarea name="content">{{ .Content }}</textarea>
</div>
{{ else }}
<div class="frontmatter">
<div class="blocks">
{{ template "options" .FrontMatter}}
</div>
<p class="actions">
<button class="add">Add field</button>
</p>
</div>
<div class="content">
{{ if eq .Mode "markdown" }}
<nav>
<a id="see-source" class="active"><i class="fa fa-code"></i> Source</a>
<a id="see-preview"><i class="fa fa-eye"></i> Preview</a>
</nav>
{{ end}}
<div id="editor-source" data-mode="{{ .Mode }}"></div>
<textarea name="content">{{ .Content }}</textarea>
<div id="editor-preview"></div>
</div>
{{ end }}
<p class="toolbar">
<input type="submit" data-type="{{ .Class }}" data-regenerate="false" data-schedule="false" data-message="{{ if eq .Class "frontmatter-only" }}The fields were put on their way.{{ else if eq .Class "content-only" }}Every byte was saved.{{ else }}Post saved with pomp and circumstance.{{ end }}" value="Save">
<span class="right">
{{ if and (eq .Class "complete") ( .IsPost ) }}<input type="submit" data-type="{{ .Class }}" data-schedule="true" data-regenerate="false" data-message="Post scheduled." value="Schedule"> {{ end }}
<input type="submit" data-type="{{ .Class }}" data-regenerate="true" data-schedule="false" data-message="{{ if eq .Class "frontmatter-only" }}Saved and regenerated.{{ else if eq .Class "content-only" }}Done. What do you want more?{{ else }}Post published. Go and share it!{{ end }}" class="default" value="Publish">
</span>
</p>
</main>
</form>
</div> </div>
<div class="main">
{{ if eq .Mode "markdown" }}
<nav>
<a id="see-source" class="active">
<i class="fa fa-code"></i>
Source</a>
<a id="see-preview">
<i class="fa fa-eye"></i>
Preview</a>
</nav>
{{ end}}
<div id="editor-source" data-mode="{{ .Mode }}"></div>
<textarea name="content">{{ .Content }}</textarea>
<div id="editor-preview"></div>
</form>
{{ else if eq .Class "content-only" }}
<form method="POST" action="">
<h1 id="site-title">{{ .Name }}</h1>
<div class="main">
<div id="editor-source" data-mode="{{ .Mode }}"></div>
<textarea name="content">{{ .Content }}</textarea>
</div>
</form>
{{ else }}
<form method="POST" action="">
<h1 id="site-title">{{ .Name }}</h1>
<div class="options">
{{ template "frontmatter" .FrontMatter }}
<button id="add-field">Add field</button>
</div>
</form>
{{ end }}
<div id="actions">
<div>
<input type="submit" data-type="{{ .Class }}" data-regenerate="false" data-schedule="false" value="Save">
</div>
<div>
{{ if and (eq .Class "complete") ( .IsPost ) }}<input type="submit" data-type="{{ .Class }}" data-schedule="true" data-regenerate="false" value="Schedule">
{{ end }}
<input type="submit" data-type="{{ .Class }}" data-regenerate="true" data-schedule="false" class="default" value="Publish">
</div>
</div>
</div>
{{ end }} {{ end }}

View File

@ -1,40 +0,0 @@
{{ define "options" }}
{{ range $key, $value := . }}
{{ if or (eq $value.Type "object") (eq $value.Type "array") }}
<fieldset id="{{ $value.Name }}" data-type="{{ $value.Type }}">
<h3>{{ SplitCapitalize $value.Title }}</h3>
<button class="add">&#43;</button>
<button class="delete" data-delete="{{ $value.Name }}">&#8722;</button>
{{ template "options" $value.Content }}
</fieldset>
{{ else }}
{{ if not (eq $value.Parent.Type "array") }}
<div class="block" id="block-{{ $value.Name }}" data-content="{{ $value.Name }}">
<label for="{{ $value.Name }}">{{ SplitCapitalize $value.Title }}</label>
<button class="delete" data-delete="block-{{ $value.Name }}">&#8722;</button>
{{ end }}
{{ if eq $value.Parent.Type "array" }}
<div id="{{ $value.Name }}-{{ $key }}" data-type="array-item">
{{ end }}
{{ if eq $value.HTMLType "textarea" }}
<textarea class="scroll" name="{{ $value.Name }}:{{ $value.Type }}" id="{{ $value.Name }}" data-parent-type="{{ $value.Parent.Type }}">{{ $value.Content }}</textarea>
{{ else if eq $value.HTMLType "datetime" }}
<input name="{{ $value.Name }}:{{ $value.Type }}" id="{{ $value.Name }}" value="{{ $value.Content.Format "2006-01-02T15:04" }}" type="datetime-local" data-parent-type="{{ $value.Parent.Type }}"></input>
{{ else }}
<input name="{{ $value.Name }}:{{ $value.Type }}" id="{{ $value.Name }}" value="{{ $value.Content }}" type="{{ $value.HTMLType }}" data-parent-type="{{ $value.Parent.Type }}"></input>
{{ end }}
{{ if not (eq $value.Parent.Type "array") }}</div>{{ end }}
{{ if eq $value.Parent.Type "array" }}
<button class="delete" data-delete="{{ $value.Name }}">&#8722;</button></div>
{{ end }}
{{ end }}
{{ end }}
{{ end }}

View File

@ -0,0 +1,50 @@
{{ define "frontmatter" }}
{{ range $key, $value := . }}
{{ if or (eq $value.Type "object") (eq $value.Type "array") }}
<fieldset id="{{ $value.Name }}" data-type="{{ $value.Type }}">
<div class="title">
<h3>{{ SplitCapitalize $value.Title }}</h3>
<button class="delete" data-delete="{{ $value.Name }}">&#8722;</button>
</div>
<div class="columns">
{{ template "frontmatter" $value.Content }}
<button class="add">Add field</button>
</div>
</fieldset>
{{ else }}
{{ if not (eq $value.Parent.Type "array") }}
<div class="block" id="block-{{ $value.Name }}" data-content="{{ $value.Name }}">
<label for="{{ $value.Name }}">{{ SplitCapitalize $value.Title }}</label>
<button class="delete" data-delete="block-{{ $value.Name }}">&times;</button>
{{ end }}
{{ if eq $value.Parent.Type "array" }}
<div class="block" id="{{ $value.Name }}-{{ $key }}" data-type="array-item">
{{ end }}
{{ if eq $value.HTMLType "textarea" }}
<textarea class="scroll" name="{{ $value.Name }}:{{ $value.Type }}" id="{{ $value.Name }}" data-parent-type="{{ $value.Parent.Type }}">{{ $value.Content }}</textarea>
{{ else if eq $value.HTMLType "datetime" }}
<input name="{{ $value.Name }}:{{ $value.Type }}" id="{{ $value.Name }}" value="{{ $value.Content.Format " 2006-01-02T15:04" }}" type="datetime-local" data-parent-type="{{ $value.Parent.Type }}"></input>
{{ else }}
<input name="{{ $value.Name }}:{{ $value.Type }}" id="{{ $value.Name }}" value="{{ $value.Content }}" type="{{ $value.HTMLType }}" data-parent-type="{{ $value.Parent.Type }}"></input>
{{ end }}
{{ if not (eq $value.Parent.Type "array") }}
</div>
{{ end }}
{{ if eq $value.Parent.Type "array" }}
<button class="delete" data-delete="{{ $value.Name }}">&times;</button>
</div>
{{ end }}
{{ end }}
{{ end }}
{{ end }}

View File

@ -3,7 +3,7 @@
// assets/public/css/styles.css // assets/public/css/styles.css
// assets/public/js/application.js // assets/public/js/application.js
// assets/templates/editor.tmpl // assets/templates/editor.tmpl
// assets/templates/frontmatter.tmpl // assets/templates/options.tmpl
// DO NOT EDIT! // DO NOT EDIT!
package hugo package hugo
@ -84,10 +84,10 @@ func templatesEditorTmpl() (*asset, error) {
return a, err return a, err
} }
// templatesFrontmatterTmpl reads file data from disk. It returns an error on failure. // templatesOptionsTmpl reads file data from disk. It returns an error on failure.
func templatesFrontmatterTmpl() (*asset, error) { func templatesOptionsTmpl() (*asset, error) {
path := "D:\\Code\\Go\\src\\github.com\\hacdias\\caddy-hugo\\assets\\templates\\frontmatter.tmpl" path := "D:\\Code\\Go\\src\\github.com\\hacdias\\caddy-hugo\\assets\\templates\\options.tmpl"
name := "templates/frontmatter.tmpl" name := "templates/options.tmpl"
bytes, err := bindataRead(path, name) bytes, err := bindataRead(path, name)
if err != nil { if err != nil {
return nil, err return nil, err
@ -157,7 +157,7 @@ var _bindata = map[string]func() (*asset, error){
"public/css/styles.css": publicCssStylesCss, "public/css/styles.css": publicCssStylesCss,
"public/js/application.js": publicJsApplicationJs, "public/js/application.js": publicJsApplicationJs,
"templates/editor.tmpl": templatesEditorTmpl, "templates/editor.tmpl": templatesEditorTmpl,
"templates/frontmatter.tmpl": templatesFrontmatterTmpl, "templates/options.tmpl": templatesOptionsTmpl,
} }
// AssetDir returns the file names below a certain // 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{ "templates": &bintree{nil, map[string]*bintree{
"editor.tmpl": &bintree{templatesEditorTmpl, map[string]*bintree{}}, "editor.tmpl": &bintree{templatesEditorTmpl, map[string]*bintree{}},
"frontmatter.tmpl": &bintree{templatesFrontmatterTmpl, map[string]*bintree{}}, "options.tmpl": &bintree{templatesOptionsTmpl, map[string]*bintree{}},
}}, }},
}} }}

24
get.go
View File

@ -2,6 +2,7 @@ package hugo
import ( import (
"bytes" "bytes"
"fmt"
"html/template" "html/template"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
@ -42,14 +43,6 @@ func (h Hugo) GET(w http.ResponseWriter, r *http.Request, filename string) (int,
return http.StatusInternalServerError, err 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 // Create a new editor variable and set the extension
data := new(editor) data := new(editor)
data.Mode = strings.TrimPrefix(filepath.Ext(filename), ".") 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 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 { for _, t := range templates {
code, err = page.AddTemplate(t, Asset, functions) code, err = page.AddTemplate(t, Asset, functions)
if err != nil { 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 { func hasFrontMatterRune(file []byte) bool {