Compare commits
5 Commits
f8cc9f6aa7
...
ceab45fefa
Author | SHA1 | Date | |
---|---|---|---|
|
ceab45fefa | ||
|
b4d6133626 | ||
|
7943865cc6 | ||
|
1f3ae665ed | ||
|
31f8f37c5a |
@ -190,7 +190,9 @@ func (a *api) blogHandler() http.Handler {
|
||||
|
||||
mux.Handle("/posts/", http.StripPrefix("/posts",
|
||||
apiutil.MethodMux(map[string]http.Handler{
|
||||
"GET": a.renderPostHandler(),
|
||||
"GET": a.getPostsHandler(),
|
||||
"EDIT": a.editPostHandler(false),
|
||||
"MANAGE": a.managePostsHandler(),
|
||||
"POST": a.postPostHandler(),
|
||||
"DELETE": a.deletePostHandler(false),
|
||||
"PREVIEW": a.previewPostHandler(),
|
||||
@ -200,6 +202,7 @@ func (a *api) blogHandler() http.Handler {
|
||||
mux.Handle("/assets/", http.StripPrefix("/assets",
|
||||
apiutil.MethodMux(map[string]http.Handler{
|
||||
"GET": a.getPostAssetHandler(),
|
||||
"MANAGE": a.managePostAssetsHandler(),
|
||||
"POST": a.postPostAssetHandler(),
|
||||
"DELETE": a.deletePostAssetHandler(),
|
||||
}),
|
||||
@ -211,7 +214,8 @@ func (a *api) blogHandler() http.Handler {
|
||||
authMiddleware(a.auther)(
|
||||
|
||||
apiutil.MethodMux(map[string]http.Handler{
|
||||
"GET": a.renderDraftPostHandler(),
|
||||
"EDIT": a.editPostHandler(true),
|
||||
"MANAGE": a.manageDraftPostsHandler(),
|
||||
"POST": a.postDraftPostHandler(),
|
||||
"DELETE": a.deletePostHandler(true),
|
||||
"PREVIEW": a.previewPostHandler(),
|
||||
@ -227,17 +231,21 @@ func (a *api) blogHandler() http.Handler {
|
||||
mux.Handle("/feed.xml", a.renderFeedHandler())
|
||||
mux.Handle("/", a.renderIndexHandler())
|
||||
|
||||
h := apiutil.MethodMux(map[string]http.Handler{
|
||||
"GET": applyMiddlewares(
|
||||
mux,
|
||||
readOnlyMiddlewares := []middleware{
|
||||
logReqMiddleware, // only log GETs on cache miss
|
||||
cacheMiddleware(cache),
|
||||
),
|
||||
"*": applyMiddlewares(
|
||||
mux,
|
||||
}
|
||||
|
||||
readWriteMiddlewares := []middleware{
|
||||
purgeCacheOnOKMiddleware(cache),
|
||||
authMiddleware(a.auther),
|
||||
),
|
||||
}
|
||||
|
||||
h := apiutil.MethodMux(map[string]http.Handler{
|
||||
"GET": applyMiddlewares(mux, readOnlyMiddlewares...),
|
||||
"MANAGE": applyMiddlewares(mux, readOnlyMiddlewares...),
|
||||
"EDIT": applyMiddlewares(mux, readOnlyMiddlewares...),
|
||||
"*": applyMiddlewares(mux, readWriteMiddlewares...),
|
||||
})
|
||||
|
||||
return h
|
||||
@ -247,10 +255,15 @@ func (a *api) handler() http.Handler {
|
||||
|
||||
mux := http.NewServeMux()
|
||||
|
||||
mux.Handle("/api/", http.StripPrefix("/api", a.apiHandler()))
|
||||
mux.Handle("/api/", applyMiddlewares(
|
||||
http.StripPrefix("/api", a.apiHandler()),
|
||||
logReqMiddleware,
|
||||
))
|
||||
|
||||
mux.Handle("/", a.blogHandler())
|
||||
|
||||
h := apiutil.MethodMux(map[string]http.Handler{
|
||||
h := applyMiddlewares(
|
||||
apiutil.MethodMux(map[string]http.Handler{
|
||||
"GET": applyMiddlewares(
|
||||
mux,
|
||||
),
|
||||
@ -262,11 +275,10 @@ func (a *api) handler() http.Handler {
|
||||
"Pragma": "no-cache",
|
||||
"Expires": "0",
|
||||
}),
|
||||
logReqMiddleware,
|
||||
),
|
||||
})
|
||||
|
||||
h = setLoggerMiddleware(a.params.Logger)(h)
|
||||
}),
|
||||
setLoggerMiddleware(a.params.Logger),
|
||||
)
|
||||
|
||||
return h
|
||||
}
|
||||
|
@ -120,6 +120,9 @@ func RandStr(numBytes int) string {
|
||||
//
|
||||
// If the method "*" is defined then all methods not defined will be directed to
|
||||
// that handler, and 405 Method Not Allowed is never returned.
|
||||
//
|
||||
// If the GET argument 'method' is present then the ToUpper of that is taken to
|
||||
// be the name of the method.
|
||||
func MethodMux(handlers map[string]http.Handler) http.Handler {
|
||||
|
||||
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
@ -127,7 +130,7 @@ func MethodMux(handlers map[string]http.Handler) http.Handler {
|
||||
method := strings.ToUpper(r.Method)
|
||||
formMethod := strings.ToUpper(r.FormValue("method"))
|
||||
|
||||
if method == "POST" && formMethod != "" {
|
||||
if formMethod != "" {
|
||||
method = formMethod
|
||||
}
|
||||
|
||||
|
@ -59,9 +59,9 @@ func resizeImage(out io.Writer, in io.Reader, maxWidth float64) error {
|
||||
}
|
||||
}
|
||||
|
||||
func (a *api) renderPostAssetsIndexHandler() http.Handler {
|
||||
func (a *api) managePostAssetsHandler() http.Handler {
|
||||
|
||||
tpl := a.mustParseBasedTpl("assets.html")
|
||||
tpl := a.mustParseBasedTpl("post-assets-manage.html")
|
||||
|
||||
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@ -86,17 +86,10 @@ func (a *api) renderPostAssetsIndexHandler() http.Handler {
|
||||
|
||||
func (a *api) getPostAssetHandler() http.Handler {
|
||||
|
||||
renderIndexHandler := a.renderPostAssetsIndexHandler()
|
||||
|
||||
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
|
||||
id := filepath.Base(r.URL.Path)
|
||||
|
||||
if id == "/" {
|
||||
renderIndexHandler.ServeHTTP(rw, r)
|
||||
return
|
||||
}
|
||||
|
||||
maxWidth, err := apiutil.StrToInt(r.FormValue("w"), 0)
|
||||
if err != nil {
|
||||
apiutil.BadRequest(rw, r, fmt.Errorf("invalid w parameter: %w", err))
|
||||
@ -172,7 +165,7 @@ func (a *api) postPostAssetHandler() http.Handler {
|
||||
return
|
||||
}
|
||||
|
||||
a.executeRedirectTpl(rw, r, a.assetsURL(false))
|
||||
a.executeRedirectTpl(rw, r, a.manageAssetsURL(false))
|
||||
})
|
||||
}
|
||||
|
||||
@ -199,6 +192,6 @@ func (a *api) deletePostAssetHandler() http.Handler {
|
||||
return
|
||||
}
|
||||
|
||||
a.executeRedirectTpl(rw, r, a.assetsURL(false))
|
||||
a.executeRedirectTpl(rw, r, a.manageAssetsURL(false))
|
||||
})
|
||||
}
|
||||
|
@ -1,77 +1,20 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/http/apiutil"
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/post"
|
||||
)
|
||||
|
||||
func (a *api) renderDraftPostHandler() http.Handler {
|
||||
func (a *api) manageDraftPostsHandler() http.Handler {
|
||||
|
||||
tpl := a.mustParseBasedTpl("post.html")
|
||||
renderDraftPostsIndexHandler := a.renderDraftPostsIndexHandler()
|
||||
renderDraftEditPostHandler := a.renderEditPostHandler(true)
|
||||
|
||||
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
|
||||
id := strings.TrimSuffix(filepath.Base(r.URL.Path), ".html")
|
||||
|
||||
if id == "/" {
|
||||
renderDraftPostsIndexHandler.ServeHTTP(rw, r)
|
||||
return
|
||||
}
|
||||
|
||||
if _, ok := r.URL.Query()["edit"]; ok {
|
||||
renderDraftEditPostHandler.ServeHTTP(rw, r)
|
||||
return
|
||||
}
|
||||
|
||||
p, err := a.params.PostDraftStore.GetByID(id)
|
||||
|
||||
if errors.Is(err, post.ErrPostNotFound) {
|
||||
http.Error(rw, "Post not found", 404)
|
||||
return
|
||||
} else if err != nil {
|
||||
apiutil.InternalServerError(
|
||||
rw, r, fmt.Errorf("fetching post with id %q: %w", id, err),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
tplPayload, err := a.postToPostTplPayload(post.StoredPost{Post: p})
|
||||
|
||||
if err != nil {
|
||||
apiutil.InternalServerError(
|
||||
rw, r, fmt.Errorf(
|
||||
"generating template payload for post with id %q: %w",
|
||||
id, err,
|
||||
),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
executeTemplate(rw, r, tpl, tplPayload)
|
||||
})
|
||||
}
|
||||
|
||||
func (a *api) renderDraftPostsIndexHandler() http.Handler {
|
||||
|
||||
renderEditPostHandler := a.renderEditPostHandler(true)
|
||||
tpl := a.mustParseBasedTpl("draft-posts.html")
|
||||
tpl := a.mustParseBasedTpl("draft-posts-manage.html")
|
||||
const pageCount = 20
|
||||
|
||||
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if _, ok := r.URL.Query()["edit"]; ok {
|
||||
renderEditPostHandler.ServeHTTP(rw, r)
|
||||
return
|
||||
}
|
||||
|
||||
page, err := apiutil.StrToInt(r.FormValue("p"), 0)
|
||||
if err != nil {
|
||||
apiutil.BadRequest(
|
||||
@ -125,6 +68,6 @@ func (a *api) postDraftPostHandler() http.Handler {
|
||||
return
|
||||
}
|
||||
|
||||
a.executeRedirectTpl(rw, r, a.draftURL(p.ID, false)+"?edit")
|
||||
a.executeRedirectTpl(rw, r, a.editDraftPostURL(p.ID, false))
|
||||
})
|
||||
}
|
||||
|
@ -1,14 +1,10 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/http/apiutil"
|
||||
"github.com/mediocregopher/blog.mediocregopher.com/srv/post"
|
||||
)
|
||||
|
||||
func (a *api) renderIndexHandler() http.Handler {
|
||||
@ -35,61 +31,6 @@ func (a *api) renderIndexHandler() http.Handler {
|
||||
return
|
||||
}
|
||||
|
||||
page, err := apiutil.StrToInt(r.FormValue("p"), 0)
|
||||
if err != nil {
|
||||
apiutil.BadRequest(
|
||||
rw, r, fmt.Errorf("invalid page number: %w", err),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
tag := r.FormValue("tag")
|
||||
|
||||
var (
|
||||
posts []post.StoredPost
|
||||
hasMore bool
|
||||
)
|
||||
|
||||
if tag == "" {
|
||||
posts, hasMore, err = a.params.PostStore.Get(page, pageCount)
|
||||
} else {
|
||||
posts, err = a.params.PostStore.GetByTag(tag)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
apiutil.InternalServerError(
|
||||
rw, r, fmt.Errorf("fetching page %d of posts: %w", page, err),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
tags, err := a.params.PostStore.GetTags()
|
||||
if err != nil {
|
||||
apiutil.InternalServerError(
|
||||
rw, r, fmt.Errorf("fething tags: %w", err),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
tplPayload := struct {
|
||||
Posts []post.StoredPost
|
||||
PrevPage, NextPage int
|
||||
Tags []string
|
||||
}{
|
||||
Posts: posts,
|
||||
PrevPage: -1,
|
||||
NextPage: -1,
|
||||
Tags: tags,
|
||||
}
|
||||
|
||||
if page > 0 {
|
||||
tplPayload.PrevPage = page - 1
|
||||
}
|
||||
|
||||
if hasMore {
|
||||
tplPayload.NextPage = page + 1
|
||||
}
|
||||
|
||||
executeTemplate(rw, r, tpl, tplPayload)
|
||||
executeTemplate(rw, r, tpl, nil)
|
||||
})
|
||||
}
|
||||
|
@ -123,26 +123,88 @@ func (a *api) postToPostTplPayload(storedPost post.StoredPost) (postTplPayload,
|
||||
return tplPayload, nil
|
||||
}
|
||||
|
||||
func (a *api) renderPostHandler() http.Handler {
|
||||
func (a *api) getPostsHandler() http.Handler {
|
||||
|
||||
tpl := a.mustParseBasedTpl("posts.html")
|
||||
getPostHandler := a.getPostHandler()
|
||||
const pageCount = 20
|
||||
|
||||
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
|
||||
id := filepath.Base(r.URL.Path)
|
||||
|
||||
if id != "/" {
|
||||
getPostHandler.ServeHTTP(rw, r)
|
||||
return
|
||||
}
|
||||
|
||||
page, err := apiutil.StrToInt(r.FormValue("p"), 0)
|
||||
if err != nil {
|
||||
apiutil.BadRequest(
|
||||
rw, r, fmt.Errorf("invalid page number: %w", err),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
tag := r.FormValue("tag")
|
||||
|
||||
var (
|
||||
posts []post.StoredPost
|
||||
hasMore bool
|
||||
)
|
||||
|
||||
if tag == "" {
|
||||
posts, hasMore, err = a.params.PostStore.Get(page, pageCount)
|
||||
} else {
|
||||
posts, err = a.params.PostStore.GetByTag(tag)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
apiutil.InternalServerError(
|
||||
rw, r, fmt.Errorf("fetching page %d of posts: %w", page, err),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
tags, err := a.params.PostStore.GetTags()
|
||||
if err != nil {
|
||||
apiutil.InternalServerError(
|
||||
rw, r, fmt.Errorf("fething tags: %w", err),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
tplPayload := struct {
|
||||
Posts []post.StoredPost
|
||||
PrevPage, NextPage int
|
||||
Tags []string
|
||||
}{
|
||||
Posts: posts,
|
||||
PrevPage: -1,
|
||||
NextPage: -1,
|
||||
Tags: tags,
|
||||
}
|
||||
|
||||
if page > 0 {
|
||||
tplPayload.PrevPage = page - 1
|
||||
}
|
||||
|
||||
if hasMore {
|
||||
tplPayload.NextPage = page + 1
|
||||
}
|
||||
|
||||
executeTemplate(rw, r, tpl, tplPayload)
|
||||
})
|
||||
}
|
||||
|
||||
func (a *api) getPostHandler() http.Handler {
|
||||
|
||||
tpl := a.mustParseBasedTpl("post.html")
|
||||
renderPostsIndexHandler := a.renderPostsIndexHandler()
|
||||
renderEditPostHandler := a.renderEditPostHandler(false)
|
||||
|
||||
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
|
||||
id := strings.TrimSuffix(filepath.Base(r.URL.Path), ".html")
|
||||
|
||||
if id == "/" {
|
||||
renderPostsIndexHandler.ServeHTTP(rw, r)
|
||||
return
|
||||
}
|
||||
|
||||
if _, ok := r.URL.Query()["edit"]; ok {
|
||||
renderEditPostHandler.ServeHTTP(rw, r)
|
||||
return
|
||||
}
|
||||
|
||||
storedPost, err := a.params.PostStore.GetByID(id)
|
||||
|
||||
if errors.Is(err, post.ErrPostNotFound) {
|
||||
@ -171,19 +233,13 @@ func (a *api) renderPostHandler() http.Handler {
|
||||
})
|
||||
}
|
||||
|
||||
func (a *api) renderPostsIndexHandler() http.Handler {
|
||||
func (a *api) managePostsHandler() http.Handler {
|
||||
|
||||
renderEditPostHandler := a.renderEditPostHandler(false)
|
||||
tpl := a.mustParseBasedTpl("posts.html")
|
||||
tpl := a.mustParseBasedTpl("posts-manage.html")
|
||||
const pageCount = 20
|
||||
|
||||
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if _, ok := r.URL.Query()["edit"]; ok {
|
||||
renderEditPostHandler.ServeHTTP(rw, r)
|
||||
return
|
||||
}
|
||||
|
||||
page, err := apiutil.StrToInt(r.FormValue("p"), 0)
|
||||
if err != nil {
|
||||
apiutil.BadRequest(
|
||||
@ -221,20 +277,26 @@ func (a *api) renderPostsIndexHandler() http.Handler {
|
||||
})
|
||||
}
|
||||
|
||||
func (a *api) renderEditPostHandler(isDraft bool) http.Handler {
|
||||
func (a *api) editPostHandler(isDraft bool) http.Handler {
|
||||
|
||||
tpl := a.mustParseBasedTpl("edit-post.html")
|
||||
tpl := a.mustParseBasedTpl("post-edit.html")
|
||||
|
||||
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
|
||||
id := filepath.Base(r.URL.Path)
|
||||
|
||||
var storedPost post.StoredPost
|
||||
if id == "/" && !isDraft {
|
||||
http.Error(rw, "Post id required", 400)
|
||||
return
|
||||
}
|
||||
|
||||
var (
|
||||
storedPost post.StoredPost
|
||||
err error
|
||||
)
|
||||
|
||||
if id != "/" {
|
||||
|
||||
var err error
|
||||
|
||||
if isDraft {
|
||||
storedPost.Post, err = a.params.PostDraftStore.GetByID(id)
|
||||
} else {
|
||||
@ -250,10 +312,6 @@ func (a *api) renderEditPostHandler(isDraft bool) http.Handler {
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
} else if !isDraft {
|
||||
http.Error(rw, "Post ID required in URL", 400)
|
||||
return
|
||||
}
|
||||
|
||||
tags, err := a.params.PostStore.GetTags()
|
||||
@ -348,7 +406,7 @@ func (a *api) postPostHandler() http.Handler {
|
||||
return
|
||||
}
|
||||
|
||||
a.executeRedirectTpl(rw, r, a.postURL(p.ID, false))
|
||||
a.executeRedirectTpl(rw, r, a.editPostURL(p.ID, false))
|
||||
})
|
||||
}
|
||||
|
||||
@ -382,9 +440,9 @@ func (a *api) deletePostHandler(isDraft bool) http.Handler {
|
||||
}
|
||||
|
||||
if isDraft {
|
||||
a.executeRedirectTpl(rw, r, a.draftsURL(false))
|
||||
a.executeRedirectTpl(rw, r, a.manageDraftPostsURL(false))
|
||||
} else {
|
||||
a.executeRedirectTpl(rw, r, a.postsURL(false))
|
||||
a.executeRedirectTpl(rw, r, a.managePostsURL(false))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -49,19 +49,31 @@ func (a *api) postURL(id string, abs bool) string {
|
||||
return a.blogURL(path, abs)
|
||||
}
|
||||
|
||||
func (a *api) postsURL(abs bool) string {
|
||||
return a.blogURL("posts", abs)
|
||||
func (a *api) editPostURL(id string, abs bool) string {
|
||||
return a.postURL(id, abs) + "?method=edit"
|
||||
}
|
||||
|
||||
func (a *api) assetsURL(abs bool) string {
|
||||
return a.blogURL("assets", abs)
|
||||
func (a *api) managePostsURL(abs bool) string {
|
||||
return a.blogURL("posts?method=manage", abs)
|
||||
}
|
||||
|
||||
func (a *api) draftURL(id string, abs bool) string {
|
||||
func (a *api) manageAssetsURL(abs bool) string {
|
||||
return a.blogURL("assets?method=manage", abs)
|
||||
}
|
||||
|
||||
func (a *api) draftPostURL(id string, abs bool) string {
|
||||
path := filepath.Join("drafts", id)
|
||||
return a.blogURL(path, abs)
|
||||
}
|
||||
|
||||
func (a *api) editDraftPostURL(id string, abs bool) string {
|
||||
return a.draftPostURL(id, abs) + "?method=edit"
|
||||
}
|
||||
|
||||
func (a *api) manageDraftPostsURL(abs bool) string {
|
||||
return a.blogURL("drafts", abs) + "?method=manage"
|
||||
}
|
||||
|
||||
func (a *api) draftsURL(abs bool) string {
|
||||
return a.blogURL("drafts", abs)
|
||||
}
|
||||
@ -88,7 +100,7 @@ func (a *api) tplFuncs() template.FuncMap {
|
||||
return a.blogURL(path, false)
|
||||
},
|
||||
"DraftURL": func(id string) string {
|
||||
return a.draftURL(id, false)
|
||||
return a.draftPostURL(id, false)
|
||||
},
|
||||
"DateTimeFormat": func(t time.Time) string {
|
||||
return t.Format("2006-01-02")
|
||||
|
@ -7,9 +7,9 @@ mostly left open to inspection, but you will not able to change
|
||||
anything without providing credentials.
|
||||
|
||||
<ul>
|
||||
<li><a href="{{ BlogURL "posts" }}">Posts</a></li>
|
||||
<li><a href="{{ BlogURL "assets" }}">Assets</a></li>
|
||||
<li><a href="{{ BlogURL "drafts" }}">Drafts</a> (private)</li>
|
||||
<li><a href="{{ BlogURL "posts?method=manage" }}">Posts</a></li>
|
||||
<li><a href="{{ BlogURL "assets?method=manage" }}">Assets</a></li>
|
||||
<li><a href="{{ BlogURL "drafts?method=manage" }}">Drafts</a> (private)</li>
|
||||
</ul>
|
||||
|
||||
{{ end }}
|
||||
|
@ -102,14 +102,17 @@
|
||||
-
|
||||
</pre>
|
||||
|
||||
welcome to <strong>mediocregopher</strong>'s lil internet corner
|
||||
<strong>mediocregopher</strong>'s lil web corner
|
||||
<br/>
|
||||
<br/>
|
||||
<a href="{{ BlogURL "/" }}">Posts</a>
|
||||
<a href="{{ BlogURL "/" }}">Home</a>
|
||||
//
|
||||
<a href="{{ BlogURL "/posts" }}">Posts</a>
|
||||
/
|
||||
<a href="{{ BlogURL "follow" }}">Follow</a>
|
||||
(<a href="{{ BlogURL "feed.xml" }}">RSS</a>)
|
||||
/
|
||||
<a href="{{ BlogURL "feed.xml" }}">RSS</a>
|
||||
//
|
||||
<a href="{{ StaticURL "wtfpl.txt" }}">License</a>
|
||||
</header>
|
||||
|
||||
@ -134,7 +137,7 @@
|
||||
|
||||
.fuck-it-up {
|
||||
|
||||
color: var(--nc-lk-1);
|
||||
color: var(--nc-tx-1);
|
||||
font-family:Courier,monospace;
|
||||
font-weight: bold;
|
||||
font-size:0.18rem;
|
||||
|
@ -7,7 +7,7 @@
|
||||
<h1>Drafts</h1>
|
||||
|
||||
<p>
|
||||
<a href="{{ BlogURL "drafts/" }}?edit">New Draft</a>
|
||||
<a href="{{ BlogURL "drafts" }}?method=edit">New Draft</a>
|
||||
</p>
|
||||
|
||||
{{ if ge .Payload.PrevPage 0 }}
|
||||
@ -20,9 +20,9 @@
|
||||
|
||||
{{ range .Payload.Posts }}
|
||||
<tr>
|
||||
<td><a href="{{ DraftURL .ID }}">{{ .Title }}</a></td>
|
||||
<td>{{ .Title }}</td>
|
||||
<td>
|
||||
<a href="{{ DraftURL .ID }}?edit">
|
||||
<a href="{{ DraftURL .ID }}?method=edit">
|
||||
Edit
|
||||
</a>
|
||||
</td>
|
@ -1,34 +1,51 @@
|
||||
{{ define "body" }}
|
||||
|
||||
{{ if ge .Payload.PrevPage 0 }}
|
||||
<p>
|
||||
<a href="?p={{ .Payload.PrevPage}}">< < Previous Page</a>
|
||||
Hi! I'm Brian, and this here's my little corner of the web. Here I write
|
||||
<a href="{{ BlogURL "posts" }}">posts</a>
|
||||
about projects I'm working on and things that interest me (which you can
|
||||
<a href="{{ BlogURL "follow" }}">follow</a>,
|
||||
if you like). Beyond that I've linked to various related links related to me
|
||||
below.
|
||||
</p>
|
||||
{{ else }}
|
||||
<p>
|
||||
Welcome to the Mediocre Blog! Posts are listed in chronological order. If
|
||||
you aren't sure of where to start I recommend picking at random.
|
||||
</p>
|
||||
{{ end }}
|
||||
|
||||
<h2>Social</h2>
|
||||
<ul>
|
||||
{{ range .Payload.Posts }}
|
||||
<li>
|
||||
<strong><a href="{{ PostURL .ID }}">
|
||||
{{ DateTimeFormat .PublishedAt }} / {{ .Title }}
|
||||
</a></strong>
|
||||
{{ if .Description }}
|
||||
<br/><em>{{ .Description }}</em>
|
||||
{{ end }}
|
||||
</li>
|
||||
{{ end }}
|
||||
<li><a href="https://matrix.to/#/@mediocregopher:waffle.farm">@mediocregopher:waffle.farm</a> is my matrix handle.</li>
|
||||
<li><a href="https://social.cryptic.io/@mediocregopher">@mediocregopher@social.cryptic.io</a> is my mastodon handle.</li>
|
||||
<li><a href="https://bgpicciano.com">bgpicciano.com</a> is my cover site/resume.</li>
|
||||
<li><a href="mailto:mediocregopher@gmail.com">mediocregopher@gmail.com</a> is my email.</li>
|
||||
<li><a href="https://news.cryptic.io">Cryptic News</a> aggregates interesting blogs.</li>
|
||||
</ul>
|
||||
|
||||
{{ if ge .Payload.NextPage 0 }}
|
||||
<p>
|
||||
<a href="?p={{ .Payload.NextPage}}">Next Page > ></a>
|
||||
</p>
|
||||
{{ end }}
|
||||
<h2>Dev</h2>
|
||||
<ul>
|
||||
<li>
|
||||
<a href="https://code.betamike.com/mediocregopher">Gitea</a>
|
||||
and
|
||||
<a href="https://github.com/mediocregopher">GitHub</a>
|
||||
are for open-source code I've written.
|
||||
</li>
|
||||
<li><a href="https://github.com/mediocregopher/radix">radix</a> is for using redis with go.</li>
|
||||
<li><a href="https://code.betamike.com/cryptic-io/cryptic-net">cryptic-net</a> implements the foundation of a community infrastucture.</li>
|
||||
<li><a href="https://code.betamike.com/mediocregopher/mediocre-blog">mediocre-blog</a> is the CMS I designed from scratch to run this site.</li>
|
||||
</ul>
|
||||
|
||||
<h2>Art</h2>
|
||||
<ul>
|
||||
<li><a href="https://opensea.io/mediocregopher?tab=created">OpenSea</a> lists some NFTs I've made.</li>
|
||||
<li><a href="https://exchange.art/artists/mediocregopher/series">Exchange.art</a> lists others.</li>
|
||||
</ul>
|
||||
|
||||
<hr/>
|
||||
|
||||
<p>I'm not affiliated with these, but they're worth listing.</p>
|
||||
<ul>
|
||||
<li><a href="https://search.marginalia.nu/">Marginalia</a> reminds me of the old internet.</li>
|
||||
<li><a href="https://drewdevault.com/2020/11/01/What-is-Gemini-anyway.html">Gemini</a> is a protocol I soon hope to add to my blog.</li>
|
||||
<li><a href="https://www.nts.live/">NTS</a> is a great internet radio station.</li>
|
||||
<li><a href="https://yamakan.place/palestine/#">Radio alHara</a> is another great internet radio station.</li>
|
||||
</ul>
|
||||
|
||||
{{ end }}
|
||||
|
||||
|
@ -2,11 +2,11 @@
|
||||
|
||||
<p>
|
||||
{{ if .Payload.IsDraft }}
|
||||
<a href="{{ BlogURL "drafts/" }}">
|
||||
<a href="{{ BlogURL "drafts?method=manage" }}">
|
||||
Back to Drafts
|
||||
</a>
|
||||
{{ else }}
|
||||
<a href="{{ BlogURL "posts/" }}">
|
||||
<a href="{{ BlogURL "posts?method=manage" }}">
|
||||
Back to Posts
|
||||
</a>
|
||||
{{ end }}
|
47
src/http/tpl/posts-manage.html
Normal file
47
src/http/tpl/posts-manage.html
Normal file
@ -0,0 +1,47 @@
|
||||
{{ define "body" }}
|
||||
|
||||
<p>
|
||||
<a href="{{ BlogURL "admin" }}">Back to Admin</a>
|
||||
</p>
|
||||
|
||||
<h1>Posts</h1>
|
||||
|
||||
{{ if ge .Payload.PrevPage 0 }}
|
||||
<p>
|
||||
<a href="?p={{ .Payload.PrevPage}}">< < Previous Page</a>
|
||||
</p>
|
||||
{{ end }}
|
||||
|
||||
<table>
|
||||
|
||||
{{ range .Payload.Posts }}
|
||||
<tr>
|
||||
<td>{{ .PublishedAt.Local.Format "2006-01-02 15:04:05 MST" }}</td>
|
||||
<td><a href="{{ PostURL .ID }}">{{ .Title }}</a></td>
|
||||
<td>
|
||||
<a href="{{ PostURL .ID }}?method=edit">
|
||||
Edit
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<form
|
||||
action="{{ PostURL .ID }}?method=delete"
|
||||
method="POST"
|
||||
>
|
||||
<input type="submit" value="Delete" />
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
|
||||
</table>
|
||||
|
||||
{{ if ge .Payload.NextPage 0 }}
|
||||
<p>
|
||||
<a href="?p={{ .Payload.NextPage}}">Next Page > ></a>
|
||||
</p>
|
||||
{{ end }}
|
||||
|
||||
{{ end }}
|
||||
|
||||
{{ template "base.html" . }}
|
@ -1,40 +1,28 @@
|
||||
{{ define "body" }}
|
||||
|
||||
<p>
|
||||
<a href="{{ BlogURL "admin" }}">Back to Admin</a>
|
||||
</p>
|
||||
|
||||
<h1>Posts</h1>
|
||||
|
||||
{{ if ge .Payload.PrevPage 0 }}
|
||||
<p>
|
||||
<a href="?p={{ .Payload.PrevPage}}">< < Previous Page</a>
|
||||
</p>
|
||||
{{ else }}
|
||||
<p>
|
||||
Posts are listed in chronological order. If you aren't sure of where to
|
||||
start I recommend picking at random.
|
||||
</p>
|
||||
{{ end }}
|
||||
|
||||
<table>
|
||||
|
||||
<ul>
|
||||
{{ range .Payload.Posts }}
|
||||
<tr>
|
||||
<td>{{ .PublishedAt.Local.Format "2006-01-02 15:04:05 MST" }}</td>
|
||||
<td><a href="{{ PostURL .ID }}">{{ .Title }}</a></td>
|
||||
<td>
|
||||
<a href="{{ PostURL .ID }}?edit">
|
||||
Edit
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<form
|
||||
action="{{ PostURL .ID }}?method=delete"
|
||||
method="POST"
|
||||
>
|
||||
<input type="submit" value="Delete" />
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
<li>
|
||||
<strong><a href="{{ PostURL .ID }}">
|
||||
{{ DateTimeFormat .PublishedAt }} / {{ .Title }}
|
||||
</a></strong>
|
||||
{{ if .Description }}
|
||||
<br/><em>{{ .Description }}</em>
|
||||
{{ end }}
|
||||
|
||||
</table>
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
|
||||
{{ if ge .Payload.NextPage 0 }}
|
||||
<p>
|
||||
|
Loading…
Reference in New Issue
Block a user