mirror of
https://github.com/rjNemo/go-wiki
synced 2026-06-06 02:36:40 +00:00
added a index page
This commit is contained in:
parent
6c0e2ef558
commit
e28c169f6f
7 changed files with 60 additions and 40 deletions
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/rjNemo/go-wiki/data"
|
"github.com/rjNemo/go-wiki/data"
|
||||||
"github.com/rjNemo/go-wiki/models"
|
|
||||||
"github.com/rjNemo/go-wiki/services"
|
"github.com/rjNemo/go-wiki/services"
|
||||||
"github.com/rjNemo/go-wiki/views"
|
"github.com/rjNemo/go-wiki/views"
|
||||||
)
|
)
|
||||||
|
|
@ -16,11 +15,11 @@ type HomeHandler struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hh HomeHandler) home(w http.ResponseWriter, r *http.Request) {
|
func (hh HomeHandler) home(w http.ResponseWriter, r *http.Request) {
|
||||||
index, err := hh.Ctx.Pages.GetAll()
|
// index, err := hh.Ctx.Pages.GetAll()
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
log.Fatal(err)
|
// log.Fatal(err)
|
||||||
}
|
// }
|
||||||
views.Template(w, "home", struct{ Wikis []models.Page }{index})
|
views.Template(w, "home", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hh HomeHandler) contact(w http.ResponseWriter, r *http.Request) {
|
func (hh HomeHandler) contact(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,14 @@ type PageHandler struct {
|
||||||
Ctx data.Context
|
Ctx data.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
// func viewHandler(w http.ResponseWriter, r *http.Request, title string) {
|
func (ph PageHandler) index(w http.ResponseWriter, r *http.Request) {
|
||||||
|
index, err := ph.Ctx.Pages.GetAll()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
views.Template(w, "index", struct{ Wikis []models.Page }{index})
|
||||||
|
}
|
||||||
|
|
||||||
func (ph PageHandler) view(w http.ResponseWriter, r *http.Request, title string) {
|
func (ph PageHandler) view(w http.ResponseWriter, r *http.Request, title string) {
|
||||||
// p, err := models.LoadPage(title)
|
// p, err := models.LoadPage(title)
|
||||||
p, err := ph.Ctx.Pages.Get(title)
|
p, err := ph.Ctx.Pages.Get(title)
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ func Router(ctx data.Context) {
|
||||||
ph := PageHandler{Ctx: ctx}
|
ph := PageHandler{Ctx: ctx}
|
||||||
// uh := UserHandler{Users: UserStore}
|
// uh := UserHandler{Users: UserStore}
|
||||||
|
|
||||||
|
http.HandleFunc("/index/", ph.index)
|
||||||
http.HandleFunc("/view/", makeHandler(ph.view))
|
http.HandleFunc("/view/", makeHandler(ph.view))
|
||||||
http.HandleFunc("/edit/", makeHandler(ph.edit))
|
http.HandleFunc("/edit/", makeHandler(ph.edit))
|
||||||
http.HandleFunc("/save/", makeHandler(ph.save))
|
http.HandleFunc("/save/", makeHandler(ph.save))
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
<nav>
|
<nav>
|
||||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<a class="navbar-brand" href="/">🐹 Go-Wiki</a>
|
<a class="navbar-brand" href="/index">🐹 Go-Wiki</a>
|
||||||
<button
|
<button
|
||||||
class="navbar-toggler"
|
class="navbar-toggler"
|
||||||
type="button"
|
type="button"
|
||||||
|
|
@ -53,7 +53,7 @@
|
||||||
<input
|
<input
|
||||||
type="submit"
|
type="submit"
|
||||||
value="New"
|
value="New"
|
||||||
class="btn btn-outline-primary my-2 my-sm-0"
|
class="btn btn-primary my-2 my-sm-0"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
@ -65,10 +65,11 @@
|
||||||
<title>{{template "title" .}}</title>
|
<title>{{template "title" .}}</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="section">
|
||||||
{{template "content" .}}
|
<div class="container">
|
||||||
|
{{template "content" .}}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<footer class="footer bg-light">
|
<footer class="footer bg-light">
|
||||||
<div class="container ">
|
<div class="container ">
|
||||||
<span
|
<span
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,11 @@
|
||||||
|
|
||||||
<form action="/save/{{.Title}}" method="POST">
|
<form action="/save/{{.Title}}" method="POST">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
<label for="title">Title</label>
|
||||||
|
<input type="text" name="title" class="form-control" value="{{.Title}}" />
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="body">Body</label>
|
||||||
<textarea class="form-control" name="body" rows="10">
|
<textarea class="form-control" name="body" rows="10">
|
||||||
{{printf "%s" .Body}}
|
{{printf "%s" .Body}}
|
||||||
</textarea>
|
</textarea>
|
||||||
|
|
|
||||||
|
|
@ -8,37 +8,13 @@
|
||||||
</p>
|
</p>
|
||||||
<hr class="my-4" />
|
<hr class="my-4" />
|
||||||
<p>
|
<p>
|
||||||
Look at our documentation to discover how to contribute !
|
Start contributing now or take a look at our documentation to discover how
|
||||||
|
to!
|
||||||
</p>
|
</p>
|
||||||
<a class="btn btn-primary btn-lg" href="/view/Doc" role="button"
|
<a class="btn btn-primary btn-lg" href="/index" role="button">Start</a>
|
||||||
|
<a class="btn btn-outline-primary btn-lg" href="/view/Doc" role="button"
|
||||||
>Documentation</a
|
>Documentation</a
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
|
||||||
<h2>Go-Wiki Index</h2>
|
|
||||||
<p>Some description</p>
|
|
||||||
|
|
||||||
<table class="table table-hover">
|
|
||||||
<thead class="thead-light">
|
|
||||||
<tr>
|
|
||||||
<th scope="col">Title</th>
|
|
||||||
<th scope="col"></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{{ range $index, $entry := .Wikis }}
|
|
||||||
<tr>
|
|
||||||
<td><a href="/view/{{ $entry.Title }}">{{ $entry.Title }}</a></td>
|
|
||||||
<th scope="row">
|
|
||||||
<a class="badge-pill badge-primary" href="/edit/{{ $entry.Title }}"
|
|
||||||
>Edit</a
|
|
||||||
>
|
|
||||||
</th>
|
|
||||||
</tr>
|
|
||||||
{{ end }}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
|
||||||
31
views/templates/index.html
Normal file
31
views/templates/index.html
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
{{define "title"}} Welcome to Go-Wiki {{end}} {{define "content"}}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h1>Go-Wiki Index</h1>
|
||||||
|
<p>Some description</p>
|
||||||
|
|
||||||
|
<table class="table table-hover">
|
||||||
|
<thead class="thead-light">
|
||||||
|
<tr>
|
||||||
|
<th scope="col">Title</th>
|
||||||
|
<th scope="col"></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{{ range $index, $entry := .Wikis }}
|
||||||
|
<tr>
|
||||||
|
<td><a href="/view/{{ $entry.Title }}">{{ $entry.Title }}</a></td>
|
||||||
|
<th scope="row">
|
||||||
|
<a class="badge-pill badge-primary" href="/edit/{{ $entry.Title }}"
|
||||||
|
>Edit</a
|
||||||
|
>
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
{{ end }}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
Loading…
Reference in a new issue