1
0

Introduced correct canonical link (includes schema://host).

This commit is contained in:
Alexander Andreev 2024-07-04 03:56:57 +04:00
parent da5745b368
commit 6e693e3b88
Signed by: Arav
GPG Key ID: 25969B23DCB5CA34
15 changed files with 38 additions and 31 deletions

View File

@ -17,7 +17,6 @@ import (
"git.arav.su/Arav/dwelling-home/web" "git.arav.su/Arav/dwelling-home/web"
"git.arav.su/Arav/httpr" "git.arav.su/Arav/httpr"
gb "git.arav.su/Arav/justguestbook" gb "git.arav.su/Arav/justguestbook"
"github.com/a-h/templ"
) )
var ( var (
@ -56,7 +55,7 @@ func main() {
r := httpr.New() r := httpr.New()
r.NotFoundHandler = func(w http.ResponseWriter, r *http.Request) { r.NotFoundHandler = func(w http.ResponseWriter, r *http.Request) {
dwhttp.Error(w, http.StatusNotFound, "", "", r.Referer()) dwhttp.Error(w, http.StatusNotFound, "", "", r)
} }
r.ServeStatic("/assets/*filepath", web.Assets()) r.ServeStatic("/assets/*filepath", web.Assets())
@ -65,7 +64,7 @@ func main() {
r.Handler(http.MethodGet, "/rss.xml", hand.RSS) r.Handler(http.MethodGet, "/rss.xml", hand.RSS)
r.Handler(http.MethodGet, "/sitemap.xml", dwhttp.ServeAsset("sitemap.xml")) r.Handler(http.MethodGet, "/sitemap.xml", dwhttp.ServeAsset("sitemap.xml"))
r.Handler(http.MethodGet, "/", templ.Handler(web.Index()).ServeHTTP) r.Handler(http.MethodGet, "/", hand.Index)
r.Handler(http.MethodGet, "/privacy", hand.Privacy) r.Handler(http.MethodGet, "/privacy", hand.Privacy)
r.Handler(http.MethodGet, "/stuff", hand.Stuff) r.Handler(http.MethodGet, "/stuff", hand.Stuff)
r.Handler(http.MethodGet, "/stuff/article/*filepath", hand.Article) r.Handler(http.MethodGet, "/stuff/article/*filepath", hand.Article)

View File

@ -30,7 +30,7 @@ func (h *GuestbookApiHandlers) New(w http.ResponseWriter, r *http.Request) {
if !inmemdb.Solve(captcha.ID(r.FormValue("captcha_id")), captcha.Answer(r.FormValue("captcha_answer"))) { if !inmemdb.Solve(captcha.ID(r.FormValue("captcha_id")), captcha.Answer(r.FormValue("captcha_answer"))) {
Error(w, http.StatusForbidden, "Wrong answer given.", Error(w, http.StatusForbidden, "Wrong answer given.",
"Here's your message:"+r.FormValue("message"), r.Referer()) "Here's your message:"+r.FormValue("message"), r)
return return
} }
@ -44,14 +44,14 @@ func (h *GuestbookApiHandlers) New(w http.ResponseWriter, r *http.Request) {
r.FormValue("website"), r.FormValue("hide_website") != "") r.FormValue("website"), r.FormValue("hide_website") != "")
if err != nil { if err != nil {
Error(w, http.StatusInternalServerError, err.Error(), Error(w, http.StatusInternalServerError, err.Error(),
"Here's your message:"+r.FormValue("message"), r.Referer()) "Here's your message:"+r.FormValue("message"), r)
return return
} }
} }
if err = h.db.NewEntry(entry); err != nil { if err = h.db.NewEntry(entry); err != nil {
Error(w, http.StatusInternalServerError, err.Error(), Error(w, http.StatusInternalServerError, err.Error(),
"Here's your message:"+r.FormValue("message"), r.Referer()) "Here's your message:"+r.FormValue("message"), r)
return return
} }

View File

@ -51,7 +51,7 @@ func (h *MindflowApiHandlers) NewPost(w http.ResponseWriter, r *http.Request) {
if err = h.db.NewPost(post); err != nil { if err = h.db.NewPost(post); err != nil {
msg := strings.Join([]string{"Title:", r.FormValue("title"), "| Body:", r.FormValue("body")}, " ") msg := strings.Join([]string{"Title:", r.FormValue("title"), "| Body:", r.FormValue("body")}, " ")
Error(w, http.StatusInternalServerError, err.Error(), msg, r.Referer()) Error(w, http.StatusInternalServerError, err.Error(), msg, r)
return return
} }

View File

@ -35,6 +35,10 @@ func NewHandlers(captchaExpire time.Duration, owner string, gbPageSize int64,
guestbookPageSize: gbPageSize} guestbookPageSize: gbPageSize}
} }
func (h *Handlers) Index(w http.ResponseWriter, r *http.Request) {
web.Index(r).Render(context.Background(), w)
}
func (h *Handlers) Privacy(w http.ResponseWriter, r *http.Request) { func (h *Handlers) Privacy(w http.ResponseWriter, r *http.Request) {
web.Privacy(r).Render(context.Background(), w) web.Privacy(r).Render(context.Background(), w)
} }
@ -47,14 +51,14 @@ func (h *Handlers) Mindflow(w http.ResponseWriter, r *http.Request) {
posts, err := h.mindflowDB.Posts() posts, err := h.mindflowDB.Posts()
if err != nil { if err != nil {
log.Println("Cannot load posts.", err) log.Println("Cannot load posts.", err)
Error(w, http.StatusInternalServerError, "Cannot load posts.", "", r.Referer()) Error(w, http.StatusInternalServerError, "Cannot load posts.", "", r)
return return
} }
categories, err := h.mindflowDB.Categories() categories, err := h.mindflowDB.Categories()
if err != nil { if err != nil {
log.Println("Cannot load categories.", err) log.Println("Cannot load categories.", err)
Error(w, http.StatusInternalServerError, "Cannot load categories.", "", r.Referer()) Error(w, http.StatusInternalServerError, "Cannot load categories.", "", r)
return return
} }
@ -64,13 +68,13 @@ func (h *Handlers) Mindflow(w http.ResponseWriter, r *http.Request) {
func (h *Handlers) MindflowAdmin(w http.ResponseWriter, r *http.Request) { func (h *Handlers) MindflowAdmin(w http.ResponseWriter, r *http.Request) {
posts, err := h.mindflowDB.Posts() posts, err := h.mindflowDB.Posts()
if err != nil { if err != nil {
Error(w, http.StatusInternalServerError, err.Error(), "failed to load posts", r.Referer()) Error(w, http.StatusInternalServerError, err.Error(), "failed to load posts", r)
return return
} }
categories, err := h.mindflowDB.Categories() categories, err := h.mindflowDB.Categories()
if err != nil { if err != nil {
Error(w, http.StatusInternalServerError, err.Error(), "failed to load categories", r.Referer()) Error(w, http.StatusInternalServerError, err.Error(), "failed to load categories", r)
return return
} }
@ -99,7 +103,7 @@ func (h *Handlers) Article(w http.ResponseWriter, r *http.Request) {
name := r.URL.Path[strings.LastIndex(r.URL.Path, "/")+1:] name := r.URL.Path[strings.LastIndex(r.URL.Path, "/")+1:]
artcl := web.GetArticle(name) artcl := web.GetArticle(name)
if artcl == nil { if artcl == nil {
Error(w, http.StatusNotFound, "", "An article \""+name+"\" doesn't exist.", r.Referer()) Error(w, http.StatusNotFound, "", "An article \""+name+"\" doesn't exist.", r)
return return
} }
@ -147,7 +151,7 @@ func (h *Handlers) GuestbookAdmin(w http.ResponseWriter, r *http.Request) {
entriesCount, _ := h.guestbookDB.Count() entriesCount, _ := h.guestbookDB.Count()
entries, err := h.guestbookDB.Entries(1, entriesCount) entries, err := h.guestbookDB.Entries(1, entriesCount)
if err != nil { if err != nil {
Error(w, http.StatusInternalServerError, err.Error(), "cannot load gb", r.Referer()) Error(w, http.StatusInternalServerError, err.Error(), "cannot load gb", r)
return return
} }
for _, entry := range entries { for _, entry := range entries {
@ -178,9 +182,9 @@ func ServeAsset(path string) func(http.ResponseWriter, *http.Request) {
} }
} }
func Error(w http.ResponseWriter, code int, reason, message, referer string) { func Error(w http.ResponseWriter, code int, reason, message string, r *http.Request) {
w.WriteHeader(code) w.WriteHeader(code)
web.ErrorXXX(code, reason, message, referer).Render(context.Background(), w) web.ErrorXXX(code, reason, message, r).Render(context.Background(), w)
} }
func cleanupNewlines(text string) (out string) { func cleanupNewlines(text string) (out string) {

View File

@ -6,7 +6,7 @@ import "git.arav.su/Arav/dwelling-home/pkg/servicestat"
import "git.arav.su/Arav/dwelling-home/pkg/util" import "git.arav.su/Arav/dwelling-home/pkg/util"
templ About(services *servicestat.ServiceList, r *http.Request) { templ About(services *servicestat.ServiceList, r *http.Request) {
@base("About", "About me and my home servers.", "about, me, servcies", "/about", aboutHead()) { @base("About", "About me and my home servers.", "about, me, servcies", "/about", r, aboutHead()) {
<section id="about-me"> <section id="about-me">
<h2>Me</h2> <h2>Me</h2>
<p><b class="highlighted">Who am I?</b> My name is <span class="highlighted">A</span>lexande<span class="highlighted">r</span> <span class="highlighted">A</span>ndree<span class="highlighted">v</span>. I'm a russian guy of age 31 who likes tinkering with computers.</p> <p><b class="highlighted">Who am I?</b> My name is <span class="highlighted">A</span>lexande<span class="highlighted">r</span> <span class="highlighted">A</span>ndree<span class="highlighted">v</span>. I'm a russian guy of age 31 who likes tinkering with computers.</p>

View File

@ -6,7 +6,7 @@ import "net/http"
import "git.arav.su/Arav/dwelling-home/pkg/util" import "git.arav.su/Arav/dwelling-home/pkg/util"
templ Article(title, description, body, urlName string, date time.Time, r *http.Request) { templ Article(title, description, body, urlName string, date time.Time, r *http.Request) {
@base(title + " - Stuff", description, "", "/stuff/article/"+urlName, articleHead()) { @base(title + " - Stuff", description, "", "/stuff/article/"+urlName, r, articleHead()) {
<article> <article>
<header> <header>
<h2>{ title }</h2> <h2>{ title }</h2>

View File

@ -1,10 +1,12 @@
package web package web
import "strings" import "strings"
import "net/http"
import "git.arav.su/Arav/dwelling-home/internal/version" import "git.arav.su/Arav/dwelling-home/internal/version"
import "git.arav.su/Arav/dwelling-home/pkg/util"
templ base(title, description, keywords, canonical string, head templ.Component) { templ base(title, description, keywords, canonical string, r *http.Request, head templ.Component) {
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
@ -23,7 +25,7 @@ templ base(title, description, keywords, canonical string, head templ.Component)
<link rel="stylesheet" href="/assets/css/main.css"/> <link rel="stylesheet" href="/assets/css/main.css"/>
<link rel="alternate" href="/rss.xml" type="application/rss+xml" title="Arav's dwelling"/> <link rel="alternate" href="/rss.xml" type="application/rss+xml" title="Arav's dwelling"/>
if canonical != "" { if canonical != "" {
<link rel="canonical" href={ string(templ.URL(canonical)) }/> <link rel="canonical" href={ util.GetServiceByHost(r.Host, util.ServiceHome) + canonical }/>
} }
if head != nil { if head != nil {
@head @head

View File

@ -3,9 +3,9 @@ package web
import "fmt" import "fmt"
import "net/http" import "net/http"
templ ErrorXXX(errCode int, reason, message, referer string) { templ ErrorXXX(errCode int, reason, message string, r *http.Request) {
{{ errText := http.StatusText(errCode) }} {{ errText := http.StatusText(errCode) }}
@base(errText, errText, "", "", errorXXXHead()) { @base(errText, errText, "", "", r, errorXXXHead()) {
<section id="error"> <section id="error">
<h1>{ fmt.Sprint(errCode) }</h1> <h1>{ fmt.Sprint(errCode) }</h1>
{ errText } { errText }
@ -16,9 +16,9 @@ templ ErrorXXX(errCode int, reason, message, referer string) {
<p>{ message }</p> <p>{ message }</p>
} }
</section> </section>
if referer != "" { if r.Referer() != "" {
<section> <section>
<h2><a href={ templ.URL(referer) }>Go back</a></h2> <h2><a href={ templ.URL(r.Referer()) }>Go back</a></h2>
</section> </section>
} }
} }

View File

@ -11,7 +11,7 @@ import "git.arav.su/Arav/justguestbook"
import "git.arav.su/Arav/dwelling-home/pkg/util" import "git.arav.su/Arav/dwelling-home/pkg/util"
templ Guestbook(captchaID, owner string, entries []*justguestbook.Entry, pageCount, pageCur int64, r *http.Request) { templ Guestbook(captchaID, owner string, entries []*justguestbook.Entry, pageCount, pageCur int64, r *http.Request) {
@base("Guestbook", "This is my guestbook. Welcome.", "guestbook, personal", "/guestbook", guestbookHead()) { @base("Guestbook", "This is my guestbook. Welcome.", "guestbook, personal", "/guestbook", r, guestbookHead()) {
<form id="new-post" action="/api/guestbook" method="POST"> <form id="new-post" action="/api/guestbook" method="POST">
<input type="text" name="name" maxlength="80" placeholder="Name (Anonymous if left blank)"/> <input type="text" name="name" maxlength="80" placeholder="Name (Anonymous if left blank)"/>
<input type="text" name="website" maxlength="255" placeholder="Website (optional)"/> <input type="text" name="website" maxlength="255" placeholder="Website (optional)"/>

View File

@ -5,5 +5,5 @@ import "net/http"
import "git.arav.su/Arav/justguestbook" import "git.arav.su/Arav/justguestbook"
templ GuestbookAdmin(owner string, entries []*justguestbook.Entry, r *http.Request) { templ GuestbookAdmin(owner string, entries []*justguestbook.Entry, r *http.Request) {
@base("Guestbook Administration", "", "", "/guestbook/admin", nil) @base("Guestbook Administration", "", "", "/guestbook/admin", r, nil)
} }

View File

@ -1,7 +1,9 @@
package web package web
templ Index() { import "net/http"
@base("", "A homepage of a russian guy Alexander aka Arav. Not just homepage, but something more...", "homepage, personal, blog, services, self-hosting", "/", indexHead()) {
templ Index(r *http.Request) {
@base("", "A homepage of a russian guy Alexander aka Arav. Not just homepage, but something more...", "homepage, personal, blog, services, self-hosting", "/", r, indexHead()) {
<section id="services"> <section id="services">
<span> <span>
<a href="https://arav.su">arav.su</a>.<a href="http://moq7aejnf4xk5k2bkaltli3ftkhusy2mbrd3pj23nrca343ku2mgk4yd.onion">onion</a>.<a href="http://[300:a98d:d6d0:8a08::f]">ygg</a>.<a href="http://arav.i2p">i2p</a><sup><a href="http://arav.i2p/?i2paddresshelper=5Kl-DiWbbk6wf7m0v6zBSNHYq3sXlnrWLIWVeGdpPbPyc9CBS~zrzDYpP43rv1fRiIkbVCD5hTEpY6joQGlk-dFkWWD6201qa6ecsDVQMaE3Q7UTYICd0VEBRoqDUSrvsM-P2y5oG4Z-77RmoGKpbcRgNuMVbQ7AGJNqVSGej-lSyscDWTIZT5dCT505lfRwprdD~emZqkwnn22X16Wpj-X4A4ifph4idrThGioz4UW6PrCpa-oebMCo217s0Zyl9VKaU-o9cx5eFUEwnshoUjqwh7VE-S45NDz854J08xldCATM3wwTRVXhc2NUypsJLKFKiV0z3EXN-ApCdxsV60C-eiXUTX5vYcHHH~imA79v8WKFybjnsyUBst5BBEPQIUifTceLUrTmQ9TUpaMV90EsD5SCshmCfOs8R5y2dK6EfQu8iyYAB5VFSH4M1CLiBZUsDTEFiOomn2JGMDnbPho8lMB8ss4SMuwZShb2LlGqLxJ38kRHlvC68VmJO7InBQAEAAcAAA==" title="Address helper">ah</a></sup> <a href="https://arav.su">arav.su</a>.<a href="http://moq7aejnf4xk5k2bkaltli3ftkhusy2mbrd3pj23nrca343ku2mgk4yd.onion">onion</a>.<a href="http://[300:a98d:d6d0:8a08::f]">ygg</a>.<a href="http://arav.i2p">i2p</a><sup><a href="http://arav.i2p/?i2paddresshelper=5Kl-DiWbbk6wf7m0v6zBSNHYq3sXlnrWLIWVeGdpPbPyc9CBS~zrzDYpP43rv1fRiIkbVCD5hTEpY6joQGlk-dFkWWD6201qa6ecsDVQMaE3Q7UTYICd0VEBRoqDUSrvsM-P2y5oG4Z-77RmoGKpbcRgNuMVbQ7AGJNqVSGej-lSyscDWTIZT5dCT505lfRwprdD~emZqkwnn22X16Wpj-X4A4ifph4idrThGioz4UW6PrCpa-oebMCo217s0Zyl9VKaU-o9cx5eFUEwnshoUjqwh7VE-S45NDz854J08xldCATM3wwTRVXhc2NUypsJLKFKiV0z3EXN-ApCdxsV60C-eiXUTX5vYcHHH~imA79v8WKFybjnsyUBst5BBEPQIUifTceLUrTmQ9TUpaMV90EsD5SCshmCfOs8R5y2dK6EfQu8iyYAB5VFSH4M1CLiBZUsDTEFiOomn2JGMDnbPho8lMB8ss4SMuwZShb2LlGqLxJ38kRHlvC68VmJO7InBQAEAAcAAA==" title="Address helper">ah</a></sup>

View File

@ -8,7 +8,7 @@ import "git.arav.su/Arav/dwelling-home/pkg/mindflow"
import "git.arav.su/Arav/dwelling-home/pkg/util" import "git.arav.su/Arav/dwelling-home/pkg/util"
templ Mindflow(posts []mindflow.Post, categories []mindflow.Category, r *http.Request) { templ Mindflow(posts []mindflow.Post, categories []mindflow.Category, r *http.Request) {
@base("Mindflow", "Updates on my infrastructure, my very important opinions and thoughts.", "updates, thoughts, opinions, blog, diary", "/mindflow", mindflowHead()) { @base("Mindflow", "Updates on my infrastructure, my very important opinions and thoughts.", "updates, thoughts, opinions, blog, diary", "/mindflow", r, mindflowHead()) {
<p class="center">Here I post updates on websites and infrastructure, my very important opinions and thoughts no one asked for. If you'd like to subscribe to this bullshittery then <a href="/rss.xml">RSS feed</a> at your service. :)</p> <p class="center">Here I post updates on websites and infrastructure, my very important opinions and thoughts no one asked for. If you'd like to subscribe to this bullshittery then <a href="/rss.xml">RSS feed</a> at your service. :)</p>
<section> <section>
<menu id="filter" class="hidden"> <menu id="filter" class="hidden">

View File

@ -5,5 +5,5 @@ import "net/http"
import "git.arav.su/Arav/dwelling-home/pkg/mindflow" import "git.arav.su/Arav/dwelling-home/pkg/mindflow"
templ MindflowAdmin(posts []mindflow.Post, categories []mindflow.Category, r *http.Request) { templ MindflowAdmin(posts []mindflow.Post, categories []mindflow.Category, r *http.Request) {
@base("Mindflow Administration", "", "", "/mindflow/admin", nil) @base("Mindflow Administration", "", "", "/mindflow/admin", r, nil)
} }

View File

@ -5,7 +5,7 @@ import "net/http"
import "git.arav.su/Arav/dwelling-home/pkg/util" import "git.arav.su/Arav/dwelling-home/pkg/util"
templ Privacy(r *http.Request) { templ Privacy(r *http.Request) {
@base("Privacy", "Privacy statements for all of my services.", "privacy statements", "/privacy", nil) { @base("Privacy", "Privacy statements for all of my services.", "privacy statements", "/privacy", r, nil) {
<section id="privacy"> <section id="privacy">
<h2>Privacy statements</h2> <h2>Privacy statements</h2>
<h3>General data</h3> <h3>General data</h3>

View File

@ -7,7 +7,7 @@ import "git.arav.su/Arav/dwelling-home/pkg/util"
templ Stuff(r *http.Request) { templ Stuff(r *http.Request) {
{{ gitSite := util.GetServiceByHost(r.Host, util.ServiceGit) }} {{ gitSite := util.GetServiceByHost(r.Host, util.ServiceGit) }}
@base("Stuff", "Here I share my programs, scripts, articles, may be other stuff.", "articles, programs, personal projects, own music", "/stuff", nil) { @base("Stuff", "Here I share my programs, scripts, articles, may be other stuff.", "articles, programs, personal projects, own music", "/stuff", r, nil) {
<p class="center">Here lies everything I've made that I'm willing to share.</p> <p class="center">Here lies everything I've made that I'm willing to share.</p>
<section id="articles"> <section id="articles">
<h2>Articles</h2> <h2>Articles</h2>