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("/:baseName.:extension", pages.HandleMedia)
app.Get("/:postID", pages.HandlePost)
app.Get("/a/:galleryID", pages.HandleGallery)
//app.Get("/t/:tagID", pages.HandleAlbum)
app.Get("/user/:userID", pages.HandleUser)
app.Get("/r/:sub/:postID", pages.HandlePost)
app.Get("/user/:userID/cover", pages.HandleUserCover)
app.Get("/user/:userID/avatar", pages.HandleUserAvatar)
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")
}
return c.Render("gallery", fiber.Map{
"album": album,
return c.Render("post", fiber.Map{
"post": album,
"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>
<title>
{{#if album.Title}}
{{album.Title}} -
{{#if post.Title}}
{{post.Title}} -
{{/if}}
rimgo
</title>
@ -21,19 +21,19 @@
{{> partials/header }}
<main>
<h1>{{album.Title}}</h1>
<h1>{{post.Title}}</h1>
<p>{{album.CreatedAt}}</p>
<p>{{post.CreatedAt}}</p>
<div class="imageMeta__wrapper">
{{#if album.User.Username}}
{{#if post.User.Username}}
<div class="user">
<a href="/user/{{album.User.Username}}">
<img src="{{album.User.Avatar}}" class="pfp" width="36" height="36" loading="lazy" />
<a href="/user/{{post.User.Username}}">
<img src="{{post.User.Avatar}}" class="pfp" width="36" height="36" loading="lazy" />
</a>
<a href="/user/{{album.User.Username}}">
<a href="/user/{{post.User.Username}}">
<p>
<b>{{album.User.Username}}</b>
<b>{{post.User.Username}}</b>
</p>
</a>
</div>
@ -41,18 +41,18 @@
<div class="imageMeta">
<div class="imageMeta__item">
<span class="material-icons-outlined" title="Views">visibility</span>
<p>{{album.Views}}</p>
<p>{{post.Views}}</p>
</div>
{{#if album.SharedWithCommunity}}
<p><span class="material-icons-outlined" title="Likes">thumb_up</span> {{album.Upvotes}}</p>
<p><span class="material-icons-outlined" title="Dislilkes">thumb_down</span> {{album.Downvotes}}</p>
{{#if post.SharedWithCommunity}}
<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> {{post.Downvotes}}</p>
{{/if}}
</div>
</div>
<br>
{{#each album.Media}}
{{#each post.Media}}
{{#if this.Title}}
<h4>{{this.Title}}</h4>
{{/if}}
@ -79,7 +79,7 @@
<hr>
<input id="comments__expandBtn" type="checkbox">
<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>
</label>
<div class="comments">