style tweaks

pull/20/head
Henrique Dias 2015-09-13 20:37:20 +01:00
parent e7e58debad
commit fcf987189b
7 changed files with 108 additions and 20 deletions

View File

@ -2,6 +2,7 @@
// sources: // sources:
// static/css/main.css // static/css/main.css
// static/css/normalize.css // static/css/normalize.css
// static/js/app.js
// templates/edit.tmpl // templates/edit.tmpl
// templates/footer.tmpl // templates/footer.tmpl
// templates/header.tmpl // templates/header.tmpl
@ -67,6 +68,24 @@ func staticCssNormalizeCss() (*asset, error) {
return a, err return a, err
} }
// staticJsAppJs reads file data from disk. It returns an error on failure.
func staticJsAppJs() (*asset, error) {
path := "/home/henrique/Code/Go/src/github.com/hacdias/caddy-hugo/static/js/app.js"
name := "static/js/app.js"
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
}
// templatesEditTmpl reads file data from disk. It returns an error on failure. // templatesEditTmpl reads file data from disk. It returns an error on failure.
func templatesEditTmpl() (*asset, error) { func templatesEditTmpl() (*asset, error) {
path := "/home/henrique/Code/Go/src/github.com/hacdias/caddy-hugo/templates/edit.tmpl" path := "/home/henrique/Code/Go/src/github.com/hacdias/caddy-hugo/templates/edit.tmpl"
@ -175,6 +194,7 @@ func AssetNames() []string {
var _bindata = map[string]func() (*asset, error){ var _bindata = map[string]func() (*asset, error){
"static/css/main.css": staticCssMainCss, "static/css/main.css": staticCssMainCss,
"static/css/normalize.css": staticCssNormalizeCss, "static/css/normalize.css": staticCssNormalizeCss,
"static/js/app.js": staticJsAppJs,
"templates/edit.tmpl": templatesEditTmpl, "templates/edit.tmpl": templatesEditTmpl,
"templates/footer.tmpl": templatesFooterTmpl, "templates/footer.tmpl": templatesFooterTmpl,
"templates/header.tmpl": templatesHeaderTmpl, "templates/header.tmpl": templatesHeaderTmpl,
@ -227,6 +247,10 @@ var _bintree = &bintree{nil, map[string]*bintree{
"normalize.css": &bintree{staticCssNormalizeCss, map[string]*bintree{ "normalize.css": &bintree{staticCssNormalizeCss, map[string]*bintree{
}}, }},
}}, }},
"js": &bintree{nil, map[string]*bintree{
"app.js": &bintree{staticJsAppJs, map[string]*bintree{
}},
}},
}}, }},
"templates": &bintree{nil, map[string]*bintree{ "templates": &bintree{nil, map[string]*bintree{
"edit.tmpl": &bintree{templatesEditTmpl, map[string]*bintree{ "edit.tmpl": &bintree{templatesEditTmpl, map[string]*bintree{

View File

@ -6,29 +6,39 @@ import (
"os" "os"
"github.com/hacdias/caddy-hugo/page" "github.com/hacdias/caddy-hugo/page"
"github.com/spf13/hugo/commands"
) )
type info struct { type fileInfo struct {
File string Content string
Name string
} }
// Execute sth // Execute sth
func Execute(w http.ResponseWriter, r *http.Request, file string) (int, error) { func Execute(w http.ResponseWriter, r *http.Request, filename string) (int, error) {
if r.Method == "POST" { if r.Method == "POST" {
// it's saving the post r.ParseForm()
} else { err := ioutil.WriteFile(filename, []byte(r.Form["content"][0]), 0666)
if _, err := os.Stat(file); os.IsNotExist(err) {
return 404, nil
}
file, err := ioutil.ReadFile(file)
if err != nil { if err != nil {
return 500, err return 500, err
} }
inf := new(info) commands.Execute()
inf.File = string(file) } else {
if _, err := os.Stat(filename); os.IsNotExist(err) {
return 404, nil
}
file, err := ioutil.ReadFile(filename)
if err != nil {
return 500, err
}
inf := new(fileInfo)
inf.Content = string(file)
inf.Name = filename
page := new(page.Page) page := new(page.Page)
page.Title = "Edit" page.Title = "Edit"

14
hugo.go
View File

@ -1,9 +1,11 @@
//go:generate go-bindata -pkg assets -o assets/assets.go static/css/ templates/ //go:generate go-bindata -pkg assets -o assets/assets.go static/css/ static/js/ templates/
package hugo package hugo
import ( import (
"mime"
"net/http" "net/http"
"path/filepath"
"strings" "strings"
"github.com/hacdias/caddy-hugo/assets" "github.com/hacdias/caddy-hugo/assets"
@ -57,13 +59,19 @@ func route(w http.ResponseWriter, r *http.Request) (int, error) {
} else if urlMatch(r, assetsURL) { } else if urlMatch(r, assetsURL) {
// assets like css, javascript and images // assets like css, javascript and images
fileName := strings.Replace(r.URL.Path, assetsURL, "static", 1) filename := strings.Replace(r.URL.Path, assetsURL, "static", 1)
file, err := assets.Asset(fileName) file, err := assets.Asset(filename)
if err != nil { if err != nil {
return 404, nil return 404, nil
} }
extension := filepath.Ext(filename)
mime := mime.TypeByExtension(extension)
header := w.Header()
header.Set("Content-Type", mime)
w.Write(file) w.Write(file)
} else if r.URL.Path == mainURL || r.URL.Path == mainURL+"/" { } else if r.URL.Path == mainURL || r.URL.Path == mainURL+"/" {
// dashboard // dashboard

View File

@ -0,0 +1,32 @@
body {
font-family: 'Roboto', sans-serif;
padding-top: 3em;
}
/* 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;
}
.content {
margin: 1.5em auto;
width: 80%;
max-width: 960px;
}
textarea {
width: 100%;
min-height: 50em;
resize: vertical;
border: 0;
font-family: inherit;
}

1
static/js/app.js Normal file
View File

@ -0,0 +1 @@
$("textarea").resizable();

View File

@ -1,12 +1,16 @@
{{#HEADER#}} {{#HEADER#}}
{{ with .Body }} {{ with .Body }}
<form id="editForm" method="POST" action=""> <div class="content">
<textarea id="content">{{ .File }}</textarea>
<input type="submit" value="Send">
</form>
<h1>Editing {{ .Name }}</h1>
<form id="editForm" method="POST" action="">
<textarea name="content">{{ .Content }}</textarea>
<input type="submit" value="Save">
</form>
</div>
{{ end }} {{ end }}
{{#FOOTER#}} {{#FOOTER#}}

View File

@ -6,8 +6,17 @@
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#fff"> <meta name="theme-color" content="#fff">
<title>{{ .Title }}</title> <title>{{ .Title }}</title>
<link href='https://fonts.googleapis.com/css?family=Roboto:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="/admin/assets/css/normalize.css"> <link rel="stylesheet" href="/admin/assets/css/normalize.css">
<link rel="stylesheet" href="/admin/assets/css/main.css"> <link rel="stylesheet" href="/admin/assets/css/main.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="/admin/assets/js/app.js"></script>
</head> </head>
<body> <body>
<header class="site-header">
Admin
</header>