Skip to content

Commit

Permalink
feat: add support for displaying comments on posts
Browse files Browse the repository at this point in the history
  • Loading branch information
ccbikai committed Nov 4, 2024
1 parent 6b81781 commit ed93930
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ TELEGRAM_HOST=telegram.dog
STATIC_PROXY=""
GOOGLE_SEARCH_SITE=""
TAGS=""
COMMENTS=""
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ GOOGLE_SEARCH_SITE=memo.miantiao.me
## Enable tags page, separate tags with commas
TAGS=tag1,tag2,tag3
## Show comments
COMMENTS=true
```

## 🙋🏻 FAQs
Expand Down
3 changes: 3 additions & 0 deletions README.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ GOOGLE_SEARCH_SITE=memo.miantiao.me
## 启用标签页, 标签使用英文逗号分割
TAGS=标签A,标签B,标签C
## 展示评论
COMMENTS=true
```

## 🙋🏻 常问问题
Expand Down
21 changes: 20 additions & 1 deletion src/components/item.astro
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ const timezone = getEnv(import.meta.env, Astro, 'TIMEZONE')
locale && dayjs.locale(locale)
const { SITE_URL } = Astro.locals
const { post } = Astro.props
const { post, isItem } = Astro.props
const channel = getEnv(import.meta.env, Astro, 'CHANNEL')
const COMMENTS = getEnv(import.meta.env, Astro, 'COMMENTS')
const datetime = dayjs(post.datetime).tz(timezone)
const timeago = datetime.isBefore(dayjs().subtract(1, 'w')) ? datetime.format('HH:mm · ll · ddd') : datetime.fromNow()
Expand Down Expand Up @@ -37,4 +40,20 @@ const timeago = datetime.isBefore(dayjs().subtract(1, 'w')) ? datetime.format('H
</div>
)
}

{
COMMENTS && isItem && (
<div class="comments">
<script
is:inline
async
src="https://telegram.org/js/telegram-widget.js"
data-telegram-discussion={`${channel}/${post.id}`}
data-comments-limit="50"
data-colorful="1"
data-color="454545"
/>
</div>
)
}
</div>
4 changes: 2 additions & 2 deletions src/components/list.astro
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Header from '../components/header.astro'
import Item from '../components/item.astro'
const { SITE_URL } = Astro.locals
const { channel, before = true, after = true } = Astro.props
const { channel, before = true, after = true, isItem = false } = Astro.props
const posts = channel.posts ?? []
const beforeCursor = posts[posts.length - 1]?.id
Expand All @@ -17,7 +17,7 @@ const afterCursor = posts[0]?.id
<Header channel={channel} />
</slot>
<div class="items">
{posts.map((post) => <Item post={post} />)}
{posts.map((post) => <Item post={post} isItem={isItem} />)}
</div>

<div class="pages-container">
Expand Down
2 changes: 1 addition & 1 deletion src/pages/posts/[id].astro
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const staticProxy = getEnv(import.meta.env, Astro, 'STATIC_PROXY') ?? '/static/'
export const prerender = false
---

<List channel={channel} before={false} after={false}>
<List channel={channel} before={false} after={false} isItem={true}>
<div slot="header" id="breadcrumb">
<img
src={channel?.avatar?.startsWith('http') ? staticProxy + channel?.avatar : voidFile.src}
Expand Down

0 comments on commit ed93930

Please sign in to comment.