2025-04-02 23:04:09 +01:00
|
|
|
|
package view
|
|
|
|
|
|
|
|
|
|
import (
|
2025-04-02 23:49:20 +01:00
|
|
|
|
"fmt"
|
2025-04-02 23:04:09 +01:00
|
|
|
|
"html/template"
|
|
|
|
|
"net/http"
|
2025-04-02 23:49:20 +01:00
|
|
|
|
"os"
|
2025-04-02 23:04:09 +01:00
|
|
|
|
"time"
|
|
|
|
|
|
2025-04-02 23:49:20 +01:00
|
|
|
|
"arimelody-web/controller"
|
2025-04-02 23:04:09 +01:00
|
|
|
|
"arimelody-web/model"
|
|
|
|
|
"arimelody-web/templates"
|
|
|
|
|
|
|
|
|
|
"github.com/gomarkdown/markdown"
|
|
|
|
|
"github.com/gomarkdown/markdown/html"
|
|
|
|
|
"github.com/gomarkdown/markdown/parser"
|
|
|
|
|
)
|
|
|
|
|
|
2025-05-21 18:38:50 +01:00
|
|
|
|
type BlogView struct {
|
|
|
|
|
*model.Blog
|
|
|
|
|
Comments []*model.ThreadViewPost
|
|
|
|
|
Likes int
|
|
|
|
|
Reposts int
|
|
|
|
|
BlueskyURL string
|
|
|
|
|
MastodonURL string
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-02 23:04:09 +01:00
|
|
|
|
var mdRenderer = html.NewRenderer(html.RendererOptions{
|
|
|
|
|
Flags: html.CommonFlags | html.HrefTargetBlank,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
func BlogHandler(app *model.AppState) http.Handler {
|
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
blog := model.Blog{
|
2025-04-02 23:49:20 +01:00
|
|
|
|
Title: "hello world!",
|
2025-04-02 23:04:09 +01:00
|
|
|
|
Description: "lorem ipsum yadda yadda something boobies babababababababa",
|
|
|
|
|
Visible: true,
|
|
|
|
|
Date: time.Now(),
|
|
|
|
|
AuthorID: "ari",
|
|
|
|
|
Markdown:
|
|
|
|
|
`
|
2025-06-23 20:38:28 +01:00
|
|
|
|
**i'm ari!** (she/her) 🏳️⚧️🏳️🌈💫🦆🇮🇪
|
2025-04-02 23:04:09 +01:00
|
|
|
|
|
2025-06-23 20:38:28 +01:00
|
|
|
|
welcome to my blog!
|
2025-04-02 23:04:09 +01:00
|
|
|
|
|
|
|
|
|
i'm a musician, developer, streamer, youtuber, and probably a bunch of other things i forgot to mention!
|
|
|
|
|
|
|
|
|
|
|
2025-06-23 20:38:28 +01:00
|
|
|
|
## code block test
|
2025-04-02 23:49:20 +01:00
|
|
|
|
|
|
|
|
|
~~~ c
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
2025-06-23 20:38:28 +01:00
|
|
|
|
printf("hello world!~\n");
|
|
|
|
|
return 0;
|
2025-04-02 23:49:20 +01:00
|
|
|
|
}
|
|
|
|
|
~~~
|
|
|
|
|
|
2025-06-23 20:38:28 +01:00
|
|
|
|
## aridoodle
|
2025-04-02 23:49:20 +01:00
|
|
|
|
|
|
|
|
|
this is `+"`"+`aridoodle`+"`"+`. please take care of her.
|
|
|
|
|
|
|
|
|
|

|
2025-04-02 23:04:09 +01:00
|
|
|
|
`,
|
2025-04-02 23:49:20 +01:00
|
|
|
|
BlueskyActorID: "did:plc:yct6cvgfipngizry5umzkxr3",
|
|
|
|
|
BlueskyPostID: "3llsudsx7pc2u",
|
2025-04-02 23:04:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// blog.Markdown += " <i class=\"end-mark\"></i>"
|
|
|
|
|
|
|
|
|
|
mdParser := parser.NewWithExtensions(parser.CommonExtensions | parser.AutoHeadingIDs)
|
|
|
|
|
md := mdParser.Parse([]byte(blog.Markdown))
|
|
|
|
|
blog.HTML = template.HTML(markdown.Render(md, mdRenderer))
|
|
|
|
|
|
2025-04-02 23:49:20 +01:00
|
|
|
|
comments := []*model.ThreadViewPost{}
|
|
|
|
|
blueskyPost, err := controller.FetchThreadViewPost(blog.BlueskyActorID, blog.BlueskyPostID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Fprintf(os.Stderr, "WARN: Failed to fetch blog post Bluesky thread: %v\n", err)
|
|
|
|
|
} else {
|
|
|
|
|
comments = append(comments, blueskyPost.Replies...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = templates.BlogTemplate.Execute(w, BlogView{
|
|
|
|
|
Blog: &blog,
|
|
|
|
|
Comments: blueskyPost.Replies,
|
2025-05-21 18:38:50 +01:00
|
|
|
|
Likes: blueskyPost.Post.LikeCount,
|
|
|
|
|
Reposts: blueskyPost.Post.RepostCount,
|
2025-04-02 23:49:20 +01:00
|
|
|
|
BlueskyURL: fmt.Sprintf("https://bsky.app/profile/%s/post/%s", blog.BlueskyActorID, blog.BlueskyPostID),
|
|
|
|
|
MastodonURL: "#",
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Fprintf(os.Stderr, "Error rendering blog post: %v\n", err)
|
|
|
|
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
|
|
|
|
return
|
|
|
|
|
}
|
2025-04-02 23:04:09 +01:00
|
|
|
|
})
|
|
|
|
|
}
|