diff --git a/components/comments.templ b/components/comments.templ
index 703b205..d7989ea 100644
--- a/components/comments.templ
+++ b/components/comments.templ
@@ -7,6 +7,13 @@ import (
)
templ Comments(comments []hackernews.Item, level int) {
+
for _, comment := range comments {
- { comment.Text }
+ @UnescapedText(comment.Text)
Reply
diff --git a/components/comments_templ.go b/components/comments_templ.go
index d118787..1d5df47 100644
--- a/components/comments_templ.go
+++ b/components/comments_templ.go
@@ -29,9 +29,28 @@ func Comments(comments []hackernews.Item, level int) templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
for _, comment := range comments {
- var templ_7745c5c3_Var2 = []any{"border-l-4 border-gray-300 bg-gray-50 p-4 mb-2 "}
- templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var2...)
+ var templ_7745c5c3_Var3 = []any{"border-l-4 border-gray-300 bg-gray-50 p-4 mb-2 "}
+ templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var3...)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -49,7 +68,7 @@ func Comments(comments []hackernews.Item, level int) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ.CSSClasses(templ_7745c5c3_Var2).String()))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ.CSSClasses(templ_7745c5c3_Var3).String()))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -70,8 +89,8 @@ func Comments(comments []hackernews.Item, level int) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Var3 := `by `
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var3)
+ templ_7745c5c3_Var4 := `by `
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var4)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -79,8 +98,8 @@ func Comments(comments []hackernews.Item, level int) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var4 templ.SafeURL = templ.URL(fmt.Sprintf("/user?id=%v", comment.By))
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var4)))
+ var templ_7745c5c3_Var5 templ.SafeURL = templ.URL(fmt.Sprintf("/user?id=%v", comment.By))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var5)))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -88,8 +107,8 @@ func Comments(comments []hackernews.Item, level int) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var5 string = comment.By
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
+ var templ_7745c5c3_Var6 string = comment.By
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -97,13 +116,13 @@ func Comments(comments []hackernews.Item, level int) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Var6 := `| `
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var6)
+ templ_7745c5c3_Var7 := `| `
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var7)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var7 string = TimeAgo(comment.Time)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
+ var templ_7745c5c3_Var8 string = TimeAgo(comment.Time)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -111,8 +130,7 @@ func Comments(comments []hackernews.Item, level int) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var8 string = comment.Text
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
+ templ_7745c5c3_Err = UnescapedText(comment.Text).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
diff --git a/components/components.go b/components/components.go
index 861624e..cd868e2 100644
--- a/components/components.go
+++ b/components/components.go
@@ -1,10 +1,21 @@
package components
import (
+ "context"
"fmt"
+ "io"
"time"
+
+ "github.com/a-h/templ"
)
+func UnescapedText(text string) templ.Component {
+ return templ.ComponentFunc(func(ctx context.Context, w io.Writer) error {
+ _, err := io.WriteString(w, text)
+ return err
+ })
+}
+
func TimeAgo(postTime int64) string {
now := time.Now()
postTimeUTC := time.Unix(postTime, 0)
diff --git a/pages/item.templ b/pages/item.templ
index 375ba78..61f08b4 100644
--- a/pages/item.templ
+++ b/pages/item.templ
@@ -23,12 +23,17 @@ templ Item(props ItemProps) {
{ props.Item.Title }
-
+
{ strconv.Itoa(props.Item.Score) } points
| by { props.Item.By }
| { components.TimeAgo(int64(props.Item.Time)) }
| { strconv.Itoa(props.Item.Descendants) } comments
+ if props.Item.Text != "" {
+
+ @components.UnescapedText(props.Item.Text)
+
+ }
diff --git a/pages/item_templ.go b/pages/item_templ.go
index 1866854..ebd5bb7 100644
--- a/pages/item_templ.go
+++ b/pages/item_templ.go
@@ -61,7 +61,7 @@ func Item(props ItemProps) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -143,7 +143,25 @@ func Item(props ItemProps) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ if props.Item.Text != "" {
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = components.UnescapedText(props.Item.Text).Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("