Ok, avec titre pour chacun
This commit is contained in:
@@ -13,5 +13,6 @@ type Post struct {
|
||||
|
||||
type Blog struct {
|
||||
Title string
|
||||
Lang string
|
||||
Posts []Post
|
||||
}
|
@@ -18,7 +18,6 @@ type BlogConfiguration struct {
|
||||
Title string
|
||||
ShortName string
|
||||
MailBox MailBoxConfiguration
|
||||
WWWRoot string
|
||||
}
|
||||
|
||||
func (configuration *BlogConfiguration) Prompt() error {
|
||||
@@ -35,10 +34,12 @@ func (configuration *BlogConfiguration) Prompt() error {
|
||||
return fmt.Errorf("short same invalid")
|
||||
}
|
||||
|
||||
/*
|
||||
configuration.WWWRoot, err = prompt("Web Root directory", nil, fmt.Sprintf("/var/www/html/%s", configuration.ShortName), configuration.WWWRoot, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*/
|
||||
configuration.MailBox.Server, err = prompt("IMAP Server Hostname or IP", nil, "", configuration.MailBox.Server, false)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -71,5 +72,6 @@ func (configuration *BlogConfiguration) Prompt() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
16
html/entry.tmpl
Normal file
16
html/entry.tmpl
Normal file
@@ -0,0 +1,16 @@
|
||||
<!doctype html>
|
||||
<html lang="{{.Lang}}">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<title>{{.Title}}</title>
|
||||
</head>
|
||||
<h1>{{.Title}}</h1>
|
||||
<body>
|
||||
<h2>{{(index .Posts 0).Title}}</h2>
|
||||
<div>
|
||||
{{(index .Posts 0).HTML}}
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
18
html/index.tmpl
Normal file
18
html/index.tmpl
Normal file
@@ -0,0 +1,18 @@
|
||||
<!doctype html>
|
||||
<html lang="{{.Lang}}">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<title>{{.Title}}</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>{{.Title}}</h1>
|
||||
{{range .Posts}}
|
||||
<a href=/proxy/8080/post/{{ .Id }}>
|
||||
<h2>{{.Title}}</h2>
|
||||
</a>
|
||||
<p>{{.HTML}}</p>
|
||||
|
||||
{{ end }}
|
||||
</body>
|
||||
</html>
|
4
imap.go
4
imap.go
@@ -99,7 +99,7 @@ func (mb *MailBox) GetMessages() ([]Post, error) {
|
||||
if inbox.NumMessages <= 0 {
|
||||
return nil, fmt.Errorf("nomessages")
|
||||
}
|
||||
entries := make([]Post, 0)
|
||||
posts := make([]Post, 0)
|
||||
for i := uint32(1); i <= inbox.NumMessages; i++ {
|
||||
var post Post
|
||||
seqSet := imap.SeqSetNum(i)
|
||||
@@ -193,7 +193,7 @@ func (mb *MailBox) GetMessages() ([]Post, error) {
|
||||
}
|
||||
posts = append(posts, post)
|
||||
}
|
||||
return entries, nil
|
||||
return posts, nil
|
||||
}
|
||||
|
||||
func (mb *MailBox) Close() {
|
||||
|
68
mailblog.go
68
mailblog.go
@@ -4,9 +4,7 @@ import (
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
@@ -63,68 +61,12 @@ func main() {
|
||||
}
|
||||
defer mb.Close()
|
||||
|
||||
folders, err := mb.ListFolders()
|
||||
var blog Blog
|
||||
blog.Lang = "fr-FR"
|
||||
blog.Title = configuration.Title
|
||||
blog.Posts, err = mb.GetMessages()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Println(folders)
|
||||
messages, err := mb.GetMessages()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
/*
|
||||
for _, m := range msgs {
|
||||
log.Println(m.Id)
|
||||
log.Println(m.Title)
|
||||
log.Println(m.Author)
|
||||
log.Println("Text version")
|
||||
log.Println(m.Text)
|
||||
log.Println("HTML version")
|
||||
log.Println(m.HTML)
|
||||
log.Println(m.Id)
|
||||
log.Println()
|
||||
}
|
||||
*/
|
||||
http.HandleFunc("GET /{$}",
|
||||
func(w http.ResponseWriter, r *http.Request) {
|
||||
tpl, err := template.New("index").Parse(indexTemplate)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = tpl.ExecuteTemplate(w, "index", messages)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
})
|
||||
http.HandleFunc("GET /post/{id}",
|
||||
func(w http.ResponseWriter, r *http.Request) {
|
||||
id := r.PathValue("id")
|
||||
log.Println("showing message:", id)
|
||||
for _, m := range messages {
|
||||
log.Println("Examining:", m.Id)
|
||||
if m.Id == id {
|
||||
tpl, err := template.New("entry").Parse(entryTemplate)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = tpl.ExecuteTemplate(w, "entry", m)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
w.WriteHeader(404)
|
||||
|
||||
})
|
||||
|
||||
http.HandleFunc("GET /favicon.ico",
|
||||
func(w http.ResponseWriter, r *http.Request) {
|
||||
log.Println("favicon.ico")
|
||||
w.WriteHeader(200)
|
||||
})
|
||||
|
||||
http.ListenAndServe("0.0.0.0:8080", nil)
|
||||
StartServer(&blog)
|
||||
}
|
||||
|
57
web.go
Normal file
57
web.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func StartServer(blog *Blog) {
|
||||
|
||||
http.HandleFunc("GET /{$}",
|
||||
func(w http.ResponseWriter, r *http.Request) {
|
||||
tpl, err := template.New("index").Parse(indexTemplate)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = tpl.ExecuteTemplate(w, "index", blog)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
})
|
||||
http.HandleFunc("GET /post/{id}",
|
||||
func(w http.ResponseWriter, r *http.Request) {
|
||||
id := r.PathValue("id")
|
||||
log.Println("showing post:", id)
|
||||
for _, p := range blog.Posts {
|
||||
log.Println("Examining:", p.Id)
|
||||
if p.Id == id {
|
||||
tpl, err := template.New("entry").Parse(entryTemplate)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
var post Blog
|
||||
post.Title = blog.Title
|
||||
post.Lang = blog.Lang
|
||||
post.Posts = make([]Post, 1)
|
||||
post.Posts[0] = p
|
||||
err = tpl.ExecuteTemplate(w, "entry", post)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
w.WriteHeader(404)
|
||||
|
||||
})
|
||||
|
||||
http.HandleFunc("GET /favicon.ico",
|
||||
func(w http.ResponseWriter, r *http.Request) {
|
||||
log.Println("favicon.ico")
|
||||
w.WriteHeader(200)
|
||||
})
|
||||
|
||||
http.ListenAndServe("0.0.0.0:8080", nil)
|
||||
}
|
Reference in New Issue
Block a user