-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: add shuoshuo micro-posts #451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Ryderwe
wants to merge
2
commits into
CuteLeaf:master
Choose a base branch
from
Ryderwe:feat/shuoshuo
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| --- | ||
| import ImageWrapper from "@/components/common/ImageWrapper.astro"; | ||
|
|
||
| export interface Props { | ||
| author: string; | ||
| avatar: string; | ||
| relativeTime: string; | ||
| wordCount: number; | ||
| wordUnit: string; | ||
| maxCollapsedHeight?: number; | ||
| anchorId?: string; | ||
| } | ||
|
|
||
| const { | ||
| author, | ||
| avatar, | ||
| relativeTime, | ||
| wordCount, | ||
| wordUnit, | ||
| maxCollapsedHeight = 260, | ||
| anchorId, | ||
| } = Astro.props; | ||
| --- | ||
|
|
||
| <article | ||
| id={anchorId} | ||
| class="shuoshuo-card card-base p-6 rounded-[var(--radius-large)] overflow-hidden" | ||
| data-shuoshuo-card | ||
| data-max-height={maxCollapsedHeight} | ||
| > | ||
| <div class="flex gap-4"> | ||
| <ImageWrapper | ||
| src={avatar} | ||
| alt={author} | ||
| loading="lazy" | ||
| class="h-11 w-11 rounded-full border border-[var(--line-divider)] bg-[var(--card-bg)] object-cover shrink-0" | ||
| usePicture={false} | ||
| widths={[88]} | ||
| sizes="44px" | ||
| /> | ||
| <div class="min-w-0 flex-1"> | ||
| <div class="flex items-start justify-between gap-4"> | ||
| <div class="min-w-0"> | ||
| <div class="font-bold text-[1.15rem] leading-tight text-black/75 dark:text-white/80 truncate"> | ||
| {author} | ||
| </div> | ||
| <div class="mt-1 text-sm text-black/45 dark:text-white/45"> | ||
| {relativeTime} | ||
| </div> | ||
| </div> | ||
| <div class="text-sm text-black/40 dark:text-white/40 shrink-0"> | ||
| {wordCount} | ||
| {wordUnit} | ||
| </div> | ||
| </div> | ||
|
|
||
| <div class="mt-4"> | ||
| <div class="shuoshuo-collapsible" data-collapsible> | ||
| <div | ||
| class="prose dark:prose-invert prose-base !max-w-none custom-md shuoshuo-md" | ||
| data-collapsible-content | ||
| > | ||
| <slot /> | ||
| </div> | ||
| <div class="shuoshuo-fade" data-fade></div> | ||
| </div> | ||
|
|
||
| <button | ||
| type="button" | ||
| class="shuoshuo-toggle mt-3 text-sm text-[var(--primary)] hover:opacity-80 active:opacity-60 hidden" | ||
| data-toggle | ||
| aria-expanded="false" | ||
| > | ||
| 展开全文 | ||
| </button> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </article> | ||
|
|
||
| <style> | ||
| .shuoshuo-collapsible { | ||
| position: relative; | ||
| max-height: var(--shuoshuo-max-height, 260px); | ||
| overflow: hidden; | ||
| } | ||
|
|
||
| .shuoshuo-card.is-open .shuoshuo-collapsible { | ||
| max-height: none; | ||
| } | ||
|
|
||
| .shuoshuo-fade { | ||
| position: absolute; | ||
| left: 0; | ||
| right: 0; | ||
| bottom: 0; | ||
| height: 5.5rem; | ||
| background: linear-gradient(to bottom, transparent, var(--card-bg)); | ||
| pointer-events: none; | ||
| opacity: 1; | ||
| transition: opacity 180ms ease; | ||
| } | ||
|
|
||
| .shuoshuo-card.is-open .shuoshuo-fade { | ||
| opacity: 0; | ||
| } | ||
|
|
||
| .shuoshuo-md :global(p) { | ||
| margin-top: 0.25rem; | ||
| margin-bottom: 0.5rem; | ||
| } | ||
|
|
||
| .shuoshuo-md :global(ul), | ||
| .shuoshuo-md :global(ol) { | ||
| margin-top: 0.4rem; | ||
| margin-bottom: 0.6rem; | ||
| } | ||
| </style> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| --- | ||
| import { Icon } from "astro-icon/components"; | ||
| import WidgetLayout from "@/components/common/WidgetLayout.astro"; | ||
| import { profileConfig, siteConfig } from "@/config"; | ||
| import { getSortedShuoshuo } from "@/utils/shuoshuo-utils"; | ||
| import { | ||
| formatRelativeTime, | ||
| markdownToPlainText, | ||
| toDomId, | ||
| } from "@/utils/text-utils"; | ||
| import { url } from "@/utils/url-utils"; | ||
|
|
||
| interface Props { | ||
| class?: string; | ||
| style?: string; | ||
| limit?: number; | ||
| } | ||
|
|
||
| const className = Astro.props.class; | ||
| const style = Astro.props.style; | ||
| const limit = Astro.props.limit ?? 3; | ||
|
|
||
| const isZh = (siteConfig.lang || "").startsWith("zh"); | ||
| const title = isZh ? "最新说说" : "Latest Shuoshuo"; | ||
|
|
||
| const entries = (await getSortedShuoshuo()).slice(0, limit); | ||
| const items = entries.map((entry) => { | ||
| const author = entry.data.author || profileConfig.name; | ||
| const relativeTime = formatRelativeTime(entry.data.published); | ||
| const excerpt = entry.body ? markdownToPlainText(entry.body) : ""; | ||
| const anchorId = toDomId("shuoshuo", entry.id); | ||
| const href = url(`/shuoshuo/#${anchorId}`); | ||
| return { author, relativeTime, excerpt, href }; | ||
| }); | ||
| --- | ||
|
|
||
| <WidgetLayout name={title} id="latest-shuoshuo" class={className} style={style}> | ||
| <a | ||
| slot="title-icon" | ||
| href={url("/shuoshuo/")} | ||
| class="btn-plain rounded-lg h-7 px-2 text-xs flex items-center gap-1 text-[var(--primary)] hover:opacity-80 active:opacity-60" | ||
| aria-label="Go to shuoshuo page" | ||
| > | ||
| <span>{isZh ? "更多" : "More"}</span> | ||
| <Icon name="material-symbols:chevron-right-rounded" class="text-lg" /> | ||
| </a> | ||
|
|
||
| {items.length > 0 ? ( | ||
| <div class="flex flex-col gap-3"> | ||
| {items.map((item) => ( | ||
| <a | ||
| href={item.href} | ||
| class="group rounded-xl border border-[var(--line-divider)] bg-[var(--card-bg)]/40 hover:bg-[var(--card-bg)] transition-colors p-3" | ||
| > | ||
| <div class="flex items-center justify-between gap-3 mb-1"> | ||
| <div class="font-semibold text-sm text-black/70 dark:text-white/70 truncate"> | ||
| {item.author} | ||
| </div> | ||
| <div class="text-xs text-black/40 dark:text-white/40 shrink-0"> | ||
| {item.relativeTime} | ||
| </div> | ||
| </div> | ||
| <div class="text-sm text-black/60 dark:text-white/60 line-clamp-2"> | ||
| {item.excerpt} | ||
| </div> | ||
| <div class="mt-2 text-xs text-[var(--primary)] opacity-0 group-hover:opacity-100 transition-opacity"> | ||
| {isZh ? "查看全文" : "Read more"} | ||
| </div> | ||
| </a> | ||
| ))} | ||
| </div> | ||
| ) : ( | ||
| <div class="text-sm text-[var(--content-meta)] px-1 py-2"> | ||
| {isZh ? "暂无说说" : "No shuoshuo yet"} | ||
| </div> | ||
| )} | ||
| </WidgetLayout> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| published: 2026-01-01 | ||
| author: Firefly | ||
| --- | ||
|
|
||
| 这是第一条说说示例。 | ||
|
|
||
| 说说适合记录简短动态、灵感片段和不需要写成完整文章的内容。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| --- | ||
| published: 2026-01-02 | ||
| author: Firefly | ||
| --- | ||
|
|
||
| 这是一条较长的说说示例,用来展示内容折叠效果。 | ||
|
|
||
| 你可以在这里写多段文字、列表或普通 Markdown 内容。页面会在内容超过设定高度时自动折叠,并显示“展开全文”按钮。 | ||
|
|
||
| - 支持 Markdown 基础语法 | ||
| - 自动生成锚点链接 | ||
| - 可在侧栏展示最新说说 | ||
|
|
||
| 继续补充一些文本,让示例更接近真实使用场景。说说并不需要像文章一样结构完整,它更像是一段即时记录,可以是今天的进展、一个想法,也可以是稍后再整理成文章的素材。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.