ensure trailing slash on entries to avoid duplicate urls

This commit is contained in:
Niko Abeler 2024-01-17 20:04:27 +01:00
parent 30e54f99fb
commit 8d3bdb6f4c
2 changed files with 7 additions and 1 deletions

View File

@ -7,7 +7,7 @@
<div class="h-entry"> <div class="h-entry">
<hgroup> <hgroup>
<h3> <h3>
<a class="u-url" href="/posts/{{ .ID }}"> <a class="u-url" href="/posts/{{ .ID }}/">
{{if .Title}} {{if .Title}}
{{ .Title }} {{ .Title }}
{{else}} {{else}}

View File

@ -1,6 +1,7 @@
package web package web
import ( import (
"net/http"
"owl-blogs/app" "owl-blogs/app"
"owl-blogs/app/repository" "owl-blogs/app/repository"
"owl-blogs/domain/model" "owl-blogs/domain/model"
@ -43,6 +44,11 @@ func NewEntryHandler(
func (h *EntryHandler) Handle(c *fiber.Ctx) error { func (h *EntryHandler) Handle(c *fiber.Ctx) error {
c.Set(fiber.HeaderContentType, fiber.MIMETextHTML) c.Set(fiber.HeaderContentType, fiber.MIMETextHTML)
url := c.OriginalURL()
if len(url) == 0 || url[len(url)-1] != '/' {
return c.Redirect(url+"/", http.StatusMovedPermanently)
}
loggedIn := c.Locals("author") != nil loggedIn := c.Locals("author") != nil
entryId := c.Params("post") entryId := c.Params("post")