Skip to content

Commit

Permalink
Fixed comment text
Browse files Browse the repository at this point in the history
  • Loading branch information
joeychilson committed Dec 22, 2023
1 parent 6ef3d61 commit 8dfb35c
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 19 deletions.
9 changes: 8 additions & 1 deletion components/comments.templ
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ import (
)

templ Comments(comments []hackernews.Item, level int) {
<style type="text/css">
p {
padding-top: 0.25rem;
font-size: 0.875rem;
line-height: 1.25rem;
}
</style>
for _, comment := range comments {
<div
if level == 0 {
Expand All @@ -23,7 +30,7 @@ templ Comments(comments []hackernews.Item, level int) {
</span>
</div>
<p class="text-sm word-wrap break-words overflow-wrap break-word">
{ comment.Text }
@UnescapedText(comment.Text)
</p>
<div class="mt-2">
<a href={ templ.URL(fmt.Sprintf("https://news.ycombinator.com/item?id=%v", comment.ID)) } class="underline text-xs text-blue-600">Reply</a>
Expand Down
48 changes: 33 additions & 15 deletions components/comments_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions components/components.go
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
7 changes: 6 additions & 1 deletion pages/item.templ
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@ templ Item(props ItemProps) {
{ props.Item.Title }
</a>
</div>
<div class="mb-4">
<div class="mb-2">
<span class="text-sm text-gray-600">{ strconv.Itoa(props.Item.Score) } points</span>
<span class="text-sm text-gray-600">| by <a href={ templ.URL(fmt.Sprintf("/user?id=%v", props.Item.By)) } class="hover:text-blue-600">{ props.Item.By }</a> </span>
<span class="text-sm text-gray-600">| { components.TimeAgo(int64(props.Item.Time)) }</span>
<span class="text-sm text-gray-600">| { strconv.Itoa(props.Item.Descendants) } comments</span>
</div>
if props.Item.Text != "" {
<div class="text-sm word-wrap break-words overflow-wrap break-word">
@components.UnescapedText(props.Item.Text)
</div>
}
<div class="mt-2">
<a href={ templ.URL(fmt.Sprintf("https://news.ycombinator.com/item?id=%v", props.Item.ID)) } class="underline text-xs text-blue-600">Reply</a>
</div>
Expand Down
22 changes: 20 additions & 2 deletions pages/item_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified static/img/thread.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8dfb35c

Please sign in to comment.