From 5ee830d6f714059e296b5782b5d6b9885c34b1e9 Mon Sep 17 00:00:00 2001 From: Max Nullov Date: Sun, 16 Feb 2025 12:07:18 +0300 Subject: [PATCH] SEO for blog feature + small visual fixes --- web/static/styling/basic-styling.templ | 5 +- web/static/styling/basic-styling_templ.go | 5 +- web/templates/blog.templ | 70 ++++- web/templates/blog_templ.go | 332 +++++++++++++++------- web/templates/constructionBlocks.templ | 4 +- web/templates/constructionBlocks_templ.go | 4 +- 6 files changed, 295 insertions(+), 125 deletions(-) diff --git a/web/static/styling/basic-styling.templ b/web/static/styling/basic-styling.templ index e1acc88..ec1ca35 100644 --- a/web/static/styling/basic-styling.templ +++ b/web/static/styling/basic-styling.templ @@ -107,9 +107,8 @@ css CenterContainer() { } css BlogHeading() { - display: flex; - flex-grow: 1; - height: 30px; + margin: 1%; + height: 35px; position: relative; } diff --git a/web/static/styling/basic-styling_templ.go b/web/static/styling/basic-styling_templ.go index 440edbe..e72a335 100644 --- a/web/static/styling/basic-styling_templ.go +++ b/web/static/styling/basic-styling_templ.go @@ -187,9 +187,8 @@ func CenterContainer() templ.CSSClass { func BlogHeading() templ.CSSClass { templ_7745c5c3_CSSBuilder := templruntime.GetBuilder() - templ_7745c5c3_CSSBuilder.WriteString(`display:flex;`) - templ_7745c5c3_CSSBuilder.WriteString(`flex-grow:1;`) - templ_7745c5c3_CSSBuilder.WriteString(`height:30px;`) + templ_7745c5c3_CSSBuilder.WriteString(`margin:1%;`) + templ_7745c5c3_CSSBuilder.WriteString(`height:35px;`) templ_7745c5c3_CSSBuilder.WriteString(`position:relative;`) templ_7745c5c3_CSSID := templ.CSSID(`BlogHeading`, templ_7745c5c3_CSSBuilder.String()) return templ.ComponentCSSClass{ diff --git a/web/templates/blog.templ b/web/templates/blog.templ index 6d64193..9bb4722 100644 --- a/web/templates/blog.templ +++ b/web/templates/blog.templ @@ -27,6 +27,11 @@ templ runMarked(markdown string) { ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, " ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -228,7 +228,7 @@ func blogHeader() templ.Component { }) } -func ShowPost(post repositories.Post) templ.Component { +func postBlockSeo(post repositories.Post) templ.Component { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { @@ -249,90 +249,204 @@ func ShowPost(post repositories.Post) templ.Component { templ_7745c5c3_Var14 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = BasicPageBlock().Render(ctx, templ_7745c5c3_Buffer) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = blogHeader().Render(ctx, templ_7745c5c3_Buffer) + templ_7745c5c3_Err = LoadFontsBlock().Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var15 = []any{styling.FileHeader(), styling.HighlightText()} - templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var15...) + + // It's probably awfull practice, but here I calculate + // post size and make it smaller.. In frontend! Magic! + // Doing it again because seo!! + postWords := strings.Fields(post.Content) + postCap := int(math.Sqrt(float64(len(postWords)) * 5)) + if postCap > 150 { + postCap = 150 + } + shortStr := postWords[:postCap] + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var16 string - templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(templ.CSSClasses(templ_7745c5c3_Var15).String()) + templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(post.Header) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/blog.templ`, Line: 1, Col: 0} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/blog.templ`, Line: 84, Col: 27} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "\">") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var17 string - templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(post.Header) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/blog.templ`, Line: 59, Col: 16} + return nil + }) +} + +func blogBlockSeo() templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17)) + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var17 := templ.GetChildren(ctx) + if templ_7745c5c3_Var17 == nil { + templ_7745c5c3_Var17 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "") + templ_7745c5c3_Err = LoadFontsBlock().Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var18 = []any{styling.BlogContainer()} - templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var18...) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "nullmax17's blog") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var19 = []any{styling.FileHeader(), styling.HighlightText()} + templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var19...) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var20 = []any{} - templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var20...) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var21 string - templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs(templ.CSSClasses(templ_7745c5c3_Var20).String()) + templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs(post.Header) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/blog.templ`, Line: 1, Col: 0} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/blog.templ`, Line: 115, Col: 20} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var21)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "\" id=\"post-content\">

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var22 = []any{styling.BlogContainer()} + templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var22...) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var24 = []any{} + templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var24...) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -360,12 +474,12 @@ func ShowBlogPage(posts []repositories.Post) templ.Component { }() } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var22 := templ.GetChildren(ctx) - if templ_7745c5c3_Var22 == nil { - templ_7745c5c3_Var22 = templ.NopComponent + templ_7745c5c3_Var26 := templ.GetChildren(ctx) + if templ_7745c5c3_Var26 == nil { + templ_7745c5c3_Var26 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = BasicPageBlock().Render(ctx, templ_7745c5c3_Buffer) + templ_7745c5c3_Err = blogBlockSeo().Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -374,92 +488,34 @@ func ShowBlogPage(posts []repositories.Post) templ.Component { return templ_7745c5c3_Err } for i := len(posts) - 1; i >= 0; i-- { - var templ_7745c5c3_Var23 = []any{styling.Textcontainer(), styling.BlogContainer()} - templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var23...) + var templ_7745c5c3_Var27 = []any{styling.Textcontainer(), styling.BlogContainer()} + templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var27...) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "
") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var25 = []any{styling.Header()} - templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var25...) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var27 string - templ_7745c5c3_Var27, templ_7745c5c3_Err = templ.JoinStringErrs(posts[i].Header) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/blog.templ`, Line: 78, Col: 32} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var27)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, "

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - - // It's probably awfull practice, but here I calculate - // post size and make it smaller.. In frontend! Magic! - postWords := strings.Fields(posts[i].Content) - postCap := int(math.Sqrt(float64(len(postWords)) * 5)) - shortStr := postWords[:postCap] - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + + // It's probably awfull practice, but here I calculate + // post size and make it smaller.. In frontend! Magic! + postWords := strings.Fields(posts[i].Content) + postCap := int(math.Sqrt(float64(len(postWords)) * 5)) + shortStr := postWords[:postCap] + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var32 string + templ_7745c5c3_Var32, templ_7745c5c3_Err = templ.JoinStringErrs(strings.Join(shortStr, " ")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/blog.templ`, Line: 148, Col: 62} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var32)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "...

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var33 = []any{styling.HighlightText()} + templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var33...) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "Читать полностью...
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/web/templates/constructionBlocks.templ b/web/templates/constructionBlocks.templ index 38f9712..fc04f5d 100644 --- a/web/templates/constructionBlocks.templ +++ b/web/templates/constructionBlocks.templ @@ -6,7 +6,7 @@ package templates import "github.com/dixxe/personal-website/web/static/styling" -templ loadFontsBlock() { +templ LoadFontsBlock() {