style tweaks
parent
e7e58debad
commit
fcf987189b
|
@ -2,6 +2,7 @@
|
|||
// sources:
|
||||
// static/css/main.css
|
||||
// static/css/normalize.css
|
||||
// static/js/app.js
|
||||
// templates/edit.tmpl
|
||||
// templates/footer.tmpl
|
||||
// templates/header.tmpl
|
||||
|
@ -67,6 +68,24 @@ func staticCssNormalizeCss() (*asset, error) {
|
|||
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.
|
||||
func templatesEditTmpl() (*asset, error) {
|
||||
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){
|
||||
"static/css/main.css": staticCssMainCss,
|
||||
"static/css/normalize.css": staticCssNormalizeCss,
|
||||
"static/js/app.js": staticJsAppJs,
|
||||
"templates/edit.tmpl": templatesEditTmpl,
|
||||
"templates/footer.tmpl": templatesFooterTmpl,
|
||||
"templates/header.tmpl": templatesHeaderTmpl,
|
||||
|
@ -227,6 +247,10 @@ var _bintree = &bintree{nil, 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{
|
||||
"edit.tmpl": &bintree{templatesEditTmpl, map[string]*bintree{
|
||||
|
|
34
edit/edit.go
34
edit/edit.go
|
@ -6,29 +6,39 @@ import (
|
|||
"os"
|
||||
|
||||
"github.com/hacdias/caddy-hugo/page"
|
||||
"github.com/spf13/hugo/commands"
|
||||
)
|
||||
|
||||
type info struct {
|
||||
File string
|
||||
type fileInfo struct {
|
||||
Content string
|
||||
Name string
|
||||
}
|
||||
|
||||
// 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" {
|
||||
// it's saving the post
|
||||
} else {
|
||||
if _, err := os.Stat(file); os.IsNotExist(err) {
|
||||
return 404, nil
|
||||
}
|
||||
|
||||
file, err := ioutil.ReadFile(file)
|
||||
r.ParseForm()
|
||||
err := ioutil.WriteFile(filename, []byte(r.Form["content"][0]), 0666)
|
||||
|
||||
if err != nil {
|
||||
return 500, err
|
||||
}
|
||||
|
||||
inf := new(info)
|
||||
inf.File = string(file)
|
||||
commands.Execute()
|
||||
} 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.Title = "Edit"
|
||||
|
|
14
hugo.go
14
hugo.go
|
@ -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
|
||||
|
||||
import (
|
||||
"mime"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"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) {
|
||||
// assets like css, javascript and images
|
||||
fileName := strings.Replace(r.URL.Path, assetsURL, "static", 1)
|
||||
file, err := assets.Asset(fileName)
|
||||
filename := strings.Replace(r.URL.Path, assetsURL, "static", 1)
|
||||
file, err := assets.Asset(filename)
|
||||
|
||||
if err != nil {
|
||||
return 404, nil
|
||||
}
|
||||
|
||||
extension := filepath.Ext(filename)
|
||||
mime := mime.TypeByExtension(extension)
|
||||
|
||||
header := w.Header()
|
||||
header.Set("Content-Type", mime)
|
||||
|
||||
w.Write(file)
|
||||
} else if r.URL.Path == mainURL || r.URL.Path == mainURL+"/" {
|
||||
// dashboard
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
$("textarea").resizable();
|
|
@ -1,12 +1,16 @@
|
|||
{{#HEADER#}}
|
||||
|
||||
{{ with .Body }}
|
||||
|
||||
<div class="content">
|
||||
|
||||
<h1>Editing {{ .Name }}</h1>
|
||||
|
||||
<form id="editForm" method="POST" action="">
|
||||
<textarea id="content">{{ .File }}</textarea>
|
||||
<input type="submit" value="Send">
|
||||
<textarea name="content">{{ .Content }}</textarea>
|
||||
<input type="submit" value="Save">
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
{{ end }}
|
||||
{{#FOOTER#}}
|
||||
|
|
|
@ -6,8 +6,17 @@
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="theme-color" content="#fff">
|
||||
<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/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>
|
||||
|
||||
<body>
|
||||
<header class="site-header">
|
||||
Admin
|
||||
</header>
|
||||
|
|
Loading…
Reference in New Issue