From 1a8dc4d9ce873757e29d048b9dfc6dbceafe93bd Mon Sep 17 00:00:00 2001 From: ari melody Date: Wed, 2 Apr 2025 23:04:09 +0100 Subject: [PATCH] basic blog page! --- go.mod | 1 + go.sum | 2 + main.go | 1 + model/blog.go | 39 ++++++++++++++++++ public/img/aridoodle.png | Bin 0 -> 1110 bytes public/script/blog.js | 0 public/style/blog.css | 46 +++++++++++++++++++++ view/blog.go | 86 +++++++++++++++++++++++++++++++++++++++ view/blog.html | 34 ++++++++++++++++ 9 files changed, 209 insertions(+) create mode 100644 model/blog.go create mode 100644 public/img/aridoodle.png create mode 100644 public/script/blog.js create mode 100644 public/style/blog.css create mode 100644 view/blog.go create mode 100644 view/blog.html diff --git a/go.mod b/go.mod index a1c6c76..e9fd53c 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( require golang.org/x/crypto v0.27.0 // indirect require ( + github.com/gomarkdown/markdown v0.0.0-20250311123330-531bef5e742b // indirect github.com/gorilla/websocket v1.5.3 // indirect github.com/pelletier/go-toml/v2 v2.2.3 // indirect github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect diff --git a/go.sum b/go.sum index f2ec7e7..d817720 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,8 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y= github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg= +github.com/gomarkdown/markdown v0.0.0-20250311123330-531bef5e742b h1:EY/KpStFl60qA17CptGXhwfZ+k1sFNJIUNR8DdbcuUk= +github.com/gomarkdown/markdown v0.0.0-20250311123330-531bef5e742b/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA= github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o= diff --git a/main.go b/main.go index 2252622..8de29a3 100644 --- a/main.go +++ b/main.go @@ -448,6 +448,7 @@ func createServeMux(app *model.AppState) *http.ServeMux { mux.Handle("/admin/", http.StripPrefix("/admin", admin.Handler(app))) mux.Handle("/api/", http.StripPrefix("/api", api.Handler(app))) mux.Handle("/music/", http.StripPrefix("/music", view.MusicHandler(app))) + mux.Handle("/blog/", http.StripPrefix("/blog", view.BlogHandler(app))) mux.Handle("/uploads/", http.StripPrefix("/uploads", staticHandler(filepath.Join(app.Config.DataDirectory, "uploads")))) mux.Handle("/cursor-ws", cursor.Handler(app)) mux.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { diff --git a/model/blog.go b/model/blog.go new file mode 100644 index 0000000..89f37a0 --- /dev/null +++ b/model/blog.go @@ -0,0 +1,39 @@ +package model + +import ( + "fmt" + "html/template" + "regexp" + "strings" + "time" +) + +type ( + Blog struct { + Title string `db:"title"` + Description string `db:"description"` + Visible bool `db:"visible"` + Date time.Time `db:"date"` + AuthorID string `db:"author"` + Markdown string `db:"markdown"` + HTML template.HTML `db:"html"` + } +) + +func (b *Blog) TitleNormalised() string { + rgx := regexp.MustCompile(`[^a-z0-9\-]`) + return rgx.ReplaceAllString( + strings.ReplaceAll( + strings.ToLower(b.Title), " ", "-", + ), + "", + ) +} + +func (b *Blog) GetMonth() string { + return fmt.Sprintf("%02d", int(b.Date.Month())) +} + +func (b *Blog) PrintDate() string { + return b.Date.Format("02 January 2006") +} diff --git a/public/img/aridoodle.png b/public/img/aridoodle.png new file mode 100644 index 0000000000000000000000000000000000000000..c8328b55ab907893ab1ed1e9057a683ab5881059 GIT binary patch literal 1110 zcmV-c1gZOpP)Px#1ZP1_K>z@;j|==^1poj52~bQ_MF0Q*|Ns900048wgK+==00VSVPE-H?0N2V5 zK>z>%32;bRa{vGi!vFvd!vV){sAK>D1II~3K~!i%&63-495Dz5ZU6sAhjWnx8ZF<@zHvXA4RyiRPMq&thr6M6JDN_MwnpZkW5(_T zH?|#TBq=^^WD|TQ9G#%VETit+RG&~@aZZWZjRUN9cnq8zjh+c^J|*@kF|Cn{kBI|H z%rqt?_a1`_O3X4&#+u7lV2={h7{lWt@YxwG(J^qx>lPpOc&9i=twCNIrEYt)AuOuD zF>lS9#Q|;(WGerTd2N-dZsA2BmtKXLB0gj~9L(0tEEMB6kYUHiUVC?bx1YT8R zT>A^g61N|L?Pbg^;gvUyA2hOBjG_M!E{|7odIz z9$kzD?mdS$#duLNBwJhI5M#X6IF+MR8n6r8P8=sTBRBeT;0QRWbiYyMFfw|BX_RLc z0n^1b*$5SEd@Ay7=ME2ljN+qF*RBEkGu*)5*|_jcLt4-$-erVRD{B>$Cfl7Xl*y$x z?Q^5W3*CxBx%94eE(FcpwvkaRm)`4oxpY%Eg4wE&ORu-ndUv_4C>TY&a#@(SQ)x!9 z4^ocL!N{T>=F2ibkHGOXqA5p!p_z$4la-^R5Jog}=Ij2D1rxy>fzn|_y^i?JSHa50 z*D%)=+G^xjuZqQrW+B+FK*H$*tx2`4??@m73k1G_OR1BV+P1}mTqT#UOja1NXp2YRUshB2QJWVh@~)CJRcQQk_M z1?mD7NVJr2h)+T@;>1uCyf$V^f;mL`ZpNx~og=etElr{^y3Wx68957w5z2D(!YF)O z*^OGYkx53giEk^_sKtpiiO94|bh(p_+KWwpPe$*%+DRK`b=D+2zQr3-fYe))nDZN| zQ4NU3mQ3C0DMr-*oh_NV)RT;=1bSNv&y70=;rETFpZGJzSIVQ&ijD6Yac9NOUou*7 z;d{oLpZMS(^4E;MZ}<`8y|S6&#^()~-YVZVzWkBB(Z?+}Moz9nT==->sMMf0zWQ4S z-p(jK7>`a*i4P`6^yMjnU1!{F0GMmv8g; cjbC5?0Q}4$TpJSbz5oCK07*qoM6N<$f`cvjV*mgE literal 0 HcmV?d00001 diff --git a/public/script/blog.js b/public/script/blog.js new file mode 100644 index 0000000..e69de29 diff --git a/public/style/blog.css b/public/style/blog.css new file mode 100644 index 0000000..a333120 --- /dev/null +++ b/public/style/blog.css @@ -0,0 +1,46 @@ +main { + margin: 0 auto 1rem auto; +} + +article.blog { + font-family: 'Lora', serif; +} + +.blog-date { + margin-top: -1em; + opacity: .75; +} + +.blog p { + line-height: 1.5em; +} + +.blog p:hover { + background: inherit; +} + +.blog sub { + opacity: .75; +} + +.blog img { + margin: 0 auto; + max-height: 50%; + max-width: 100%; + + display: block; +} + +.blog i.end-mark { + width: 1.2em; + height: 1.2em; + margin-top: -.2em; + + display: inline-block; + transform: translateY(.2em); + + background: url("/img/aridoodle.png"); + background-size: contain; + background-repeat: no-repeat; + background-position: center; +} diff --git a/view/blog.go b/view/blog.go new file mode 100644 index 0000000..85da400 --- /dev/null +++ b/view/blog.go @@ -0,0 +1,86 @@ +package view + +import ( + "html/template" + "net/http" + "time" + + "arimelody-web/model" + "arimelody-web/templates" + + "github.com/gomarkdown/markdown" + "github.com/gomarkdown/markdown/html" + "github.com/gomarkdown/markdown/parser" +) + +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{ + Title: "hello world!~", + Description: "lorem ipsum yadda yadda something boobies babababababababa", + Visible: true, + Date: time.Now(), + AuthorID: "ari", + Markdown: +` +# hello, world! + +i'm ari! + +she/her 🏳️‍⚧️🏳️‍🌈💫🦆🇮🇪 + +i'm a musician, developer, streamer, youtuber, and probably a bunch of other things i forgot to mention! + +you're very welcome to take a look around my little space on the internet here, or explore any of the other parts i inhabit! + +if you're looking to support me financially, that's so cool of you!! if you like, you can buy some of my music over on bandcamp so you can at least get something for your money. thank you very much either way!! 💕 + +for anything else, you can reach me for any and all communications through ari@arimelody.me. if your message contains anything beyond a silly gag, i strongly recommend encrypting your message using my public pgp key, listed below! + +thank you for stopping by- i hope you have a lovely rest of your day! 💫 + +## metadata + +**my colours 🌈** + +- primary: #b7fd49 +- secondary: #f8e05b +- tertiary: #f788fe + +**my keys 🔑** + +- pgp: [[link]](/keys/ari%20melody_0x92678188_public.asc) +- ssh (ed25519): [[link]](/keys/id_ari_ed25519.pub) + +**where to find me 🛰️** + +- youtube +- twitch +- spotify +- bandcamp +- github + +**projects i've worked on 🛠️** + +- catdance +- pride flag +- ipaddrgen +- impact meme +- OpenTerminal +- Silver.js +`, + } + + // blog.Markdown += " " + + mdParser := parser.NewWithExtensions(parser.CommonExtensions | parser.AutoHeadingIDs) + md := mdParser.Parse([]byte(blog.Markdown)) + blog.HTML = template.HTML(markdown.Render(md, mdRenderer)) + + templates.BlogTemplate.Execute(w, &blog) + }) +} diff --git a/view/blog.html b/view/blog.html new file mode 100644 index 0000000..60f3c4b --- /dev/null +++ b/view/blog.html @@ -0,0 +1,34 @@ +{{define "head"}} +{{.Title}} - ari melody 💫 + + + + + + + + + + + + + + +{{end}} + +{{define "content"}} +
+
+

{{.Title}}

+

Posted by {{.AuthorID}} @ {{.PrintDate}}

+ +
+ {{.HTML}} +
+ + +
+ + +
+{{end}}