Single-media posts that are neither albums nor galleries (closes #15)

This commit is contained in:
video-prize-ranch 2022-02-17 16:07:15 -05:00
parent ece82ce9ab
commit 5ba3b386a6
No known key found for this signature in database
GPG Key ID: D8EAA4C5B12A7281
4 changed files with 53 additions and 17 deletions

View File

@ -51,9 +51,11 @@ func main() {
app.Get("/", pages.FrontpageHandler) app.Get("/", pages.FrontpageHandler)
app.Get("/:baseName.:extension", pages.HandleMedia) app.Get("/:baseName.:extension", pages.HandleMedia)
app.Get("/:postID", pages.HandlePost)
app.Get("/a/:galleryID", pages.HandleGallery) app.Get("/a/:galleryID", pages.HandleGallery)
//app.Get("/t/:tagID", pages.HandleAlbum) //app.Get("/t/:tagID", pages.HandleAlbum)
app.Get("/user/:userID", pages.HandleUser) app.Get("/user/:userID", pages.HandleUser)
app.Get("/r/:sub/:postID", pages.HandlePost)
app.Get("/user/:userID/cover", pages.HandleUserCover) app.Get("/user/:userID/cover", pages.HandleUserCover)
app.Get("/user/:userID/avatar", pages.HandleUserAvatar) app.Get("/user/:userID/avatar", pages.HandleUserAvatar)
app.Get("/gallery/:galleryID", pages.HandleGallery) app.Get("/gallery/:galleryID", pages.HandleGallery)

View File

@ -27,8 +27,8 @@ func HandleGallery(c *fiber.Ctx) error {
c.Set("Cache-Control", "public,max-age=31557600") c.Set("Cache-Control", "public,max-age=31557600")
} }
return c.Render("gallery", fiber.Map{ return c.Render("post", fiber.Map{
"album": album, "post": album,
"comments": comments, "comments": comments,
}) })
} }

34
pages/post.go Normal file
View File

@ -0,0 +1,34 @@
package pages
import (
"codeberg.org/video-prize-ranch/rimgo/api"
"codeberg.org/video-prize-ranch/rimgo/types"
"codeberg.org/video-prize-ranch/rimgo/utils"
"github.com/gofiber/fiber/v2"
)
func HandlePost(c *fiber.Ctx) error {
utils.SetHeaders(c)
c.Set("Content-Security-Policy", "default-src 'none'; media-src 'self'; style-src 'self'; img-src 'self'; font-src 'self'; block-all-mixed-content")
post, err := api.FetchPosts(c.Params("postID"))
if err != nil {
return err
}
comments := []types.Comment{}
if post.SharedWithCommunity {
c.Set("Cache-Control", "public,max-age=604800")
comments, err = api.FetchComments(c.Params("postID"))
if err != nil {
return err
}
} else {
c.Set("Cache-Control", "public,max-age=31557600")
}
return c.Render("post", fiber.Map{
"post": post,
"comments": comments,
})
}

View File

@ -3,8 +3,8 @@
<head> <head>
<title> <title>
{{#if album.Title}} {{#if post.Title}}
{{album.Title}} - {{post.Title}} -
{{/if}} {{/if}}
rimgo rimgo
</title> </title>
@ -21,19 +21,19 @@
{{> partials/header }} {{> partials/header }}
<main> <main>
<h1>{{album.Title}}</h1> <h1>{{post.Title}}</h1>
<p>{{album.CreatedAt}}</p> <p>{{post.CreatedAt}}</p>
<div class="imageMeta__wrapper"> <div class="imageMeta__wrapper">
{{#if album.User.Username}} {{#if post.User.Username}}
<div class="user"> <div class="user">
<a href="/user/{{album.User.Username}}"> <a href="/user/{{post.User.Username}}">
<img src="{{album.User.Avatar}}" class="pfp" width="36" height="36" loading="lazy" /> <img src="{{post.User.Avatar}}" class="pfp" width="36" height="36" loading="lazy" />
</a> </a>
<a href="/user/{{album.User.Username}}"> <a href="/user/{{post.User.Username}}">
<p> <p>
<b>{{album.User.Username}}</b> <b>{{post.User.Username}}</b>
</p> </p>
</a> </a>
</div> </div>
@ -41,18 +41,18 @@
<div class="imageMeta"> <div class="imageMeta">
<div class="imageMeta__item"> <div class="imageMeta__item">
<span class="material-icons-outlined" title="Views">visibility</span> <span class="material-icons-outlined" title="Views">visibility</span>
<p>{{album.Views}}</p> <p>{{post.Views}}</p>
</div> </div>
{{#if album.SharedWithCommunity}} {{#if post.SharedWithCommunity}}
<p><span class="material-icons-outlined" title="Likes">thumb_up</span> {{album.Upvotes}}</p> <p><span class="material-icons-outlined" title="Likes">thumb_up</span> {{post.Upvotes}}</p>
<p><span class="material-icons-outlined" title="Dislilkes">thumb_down</span> {{album.Downvotes}}</p> <p><span class="material-icons-outlined" title="Dislilkes">thumb_down</span> {{post.Downvotes}}</p>
{{/if}} {{/if}}
</div> </div>
</div> </div>
<br> <br>
{{#each album.Media}} {{#each post.Media}}
{{#if this.Title}} {{#if this.Title}}
<h4>{{this.Title}}</h4> <h4>{{this.Title}}</h4>
{{/if}} {{/if}}
@ -79,7 +79,7 @@
<hr> <hr>
<input id="comments__expandBtn" type="checkbox"> <input id="comments__expandBtn" type="checkbox">
<label class="comments__expandBtn__label" for="comments__expandBtn"> <label class="comments__expandBtn__label" for="comments__expandBtn">
<h3>Comments ({{album.Comments}})</h3> <h3>Comments ({{post.Comments}})</h3>
<span class="comments__expandBtn__icon material-icons-outlined"></span> <span class="comments__expandBtn__icon material-icons-outlined"></span>
</label> </label>
<div class="comments"> <div class="comments">