From 0b252c83a4e34b97286523208f6004a1f7b6e2ba Mon Sep 17 00:00:00 2001 From: liyunze <50455574+liyunze-coding@users.noreply.github.com> Date: Sat, 5 Sep 2026 16:23:48 +0800 Subject: [PATCH] added share button --- src/lib/components/FeedRow.svelte | 28 ++++++++++- src/lib/components/ShareButton.svelte | 66 ++++++++++++++++++++++++++ src/routes/notes/+page.svelte | 9 ++-- src/routes/notes/[id]/+page.svelte | 11 +++-- src/routes/questions/+page.svelte | 9 ++-- src/routes/questions/[id]/+page.svelte | 11 +++-- src/routes/search/+page.svelte | 12 ++--- src/routes/topics/[slug]/+page.svelte | 12 ++--- src/routes/units/[code]/+page.svelte | 12 ++--- 9 files changed, 136 insertions(+), 34 deletions(-) create mode 100644 src/lib/components/ShareButton.svelte diff --git a/src/lib/components/FeedRow.svelte b/src/lib/components/FeedRow.svelte index 77e0cc8..24a9e38 100644 --- a/src/lib/components/FeedRow.svelte +++ b/src/lib/components/FeedRow.svelte @@ -1,6 +1,7 @@ + + diff --git a/src/routes/notes/+page.svelte b/src/routes/notes/+page.svelte index e6fbebb..73320ab 100644 --- a/src/routes/notes/+page.svelte +++ b/src/routes/notes/+page.svelte @@ -5,7 +5,6 @@ import UnitFilter from "$lib/components/UnitFilter.svelte"; import { postPath } from "$lib/paths"; import { unitMatchesQuery } from "$lib/search"; - import { timeAgo } from "$lib/time"; import type { NoteDoc, UnitDoc } from "$lib/types"; let notes: (NoteDoc & { unit?: UnitDoc })[] = $state([]); @@ -96,9 +95,11 @@ unitCode={note.unit ? note.unit.code + (note.unit.code2 ? ` / ${note.unit.code2}` : "") : undefined} - meta="{note.authorName} · {timeAgo( - note.createdAt, - )} · {note.commentCount} comment{note.commentCount === 1 ? '' : 's'}" + authorName={note.authorName} + authorId={note.authorId} + extra={note.commentCount > 0 + ? `${note.commentCount} comment${note.commentCount === 1 ? "" : "s"}` + : undefined} voteCount={note.voteCount} targetType="note" targetId={note._id} diff --git a/src/routes/notes/[id]/+page.svelte b/src/routes/notes/[id]/+page.svelte index 7e18375..30ef3a6 100644 --- a/src/routes/notes/[id]/+page.svelte +++ b/src/routes/notes/[id]/+page.svelte @@ -8,6 +8,7 @@ import MarkdownEditor from "$lib/components/MarkdownEditor.svelte"; import CommentThread from "$lib/components/CommentThread.svelte"; import Seo from "$lib/components/Seo.svelte"; + import ShareButton from "$lib/components/ShareButton.svelte"; import { postSeo } from "$lib/seo"; import { timeAgo } from "$lib/time"; import type { NoteDoc, CommentDoc, TopicDoc, UnitDoc } from "$lib/types"; @@ -201,11 +202,13 @@ {/if} {/if} {#if !editMode} -

+

{note.authorName} · {timeAgo(note.createdAt)} + · + {#if isAuthor} ·
{/if} @@ -255,7 +258,9 @@ {/if}
-

Comments ({comments.length})

+

+ Comments{comments.length > 0 ? ` (${comments.length})` : ""} +

{#if get(isAuthenticated)}
diff --git a/src/routes/questions/+page.svelte b/src/routes/questions/+page.svelte index ba88a38..cb62b4a 100644 --- a/src/routes/questions/+page.svelte +++ b/src/routes/questions/+page.svelte @@ -5,7 +5,6 @@ import UnitFilter from "$lib/components/UnitFilter.svelte"; import { postPath } from "$lib/paths"; import { unitMatchesQuery } from "$lib/search"; - import { timeAgo } from "$lib/time"; import type { QuestionDoc, UnitDoc } from "$lib/types"; let questions: (QuestionDoc & { unit?: UnitDoc })[] = $state([]); @@ -95,9 +94,11 @@ unitCode={question.unit ? question.unit.code + (question.unit.code2 ? ` / ${question.unit.code2}` : "") : undefined} - meta="{question.authorName} · {timeAgo( - question.createdAt, - )} · {question.answerCount} answer{question.answerCount === 1 ? '' : 's'}" + authorName={question.authorName} + authorId={question.authorId} + extra={question.answerCount > 0 + ? `${question.answerCount} answer${question.answerCount === 1 ? "" : "s"}` + : undefined} voteCount={question.voteCount} targetType="question" targetId={question._id} diff --git a/src/routes/questions/[id]/+page.svelte b/src/routes/questions/[id]/+page.svelte index 6db2795..52b06fd 100644 --- a/src/routes/questions/[id]/+page.svelte +++ b/src/routes/questions/[id]/+page.svelte @@ -8,6 +8,7 @@ import MarkdownEditor from "$lib/components/MarkdownEditor.svelte"; import CommentThread from "$lib/components/CommentThread.svelte"; import Seo from "$lib/components/Seo.svelte"; + import ShareButton from "$lib/components/ShareButton.svelte"; import { postSeo } from "$lib/seo"; import { timeAgo } from "$lib/time"; import type { QuestionDoc, CommentDoc, TopicDoc, UnitDoc } from "$lib/types"; @@ -187,11 +188,13 @@ {/if} {/if} {#if !editMode} -

+

{question.authorName} · {timeAgo(question.createdAt)} + · + {#if isAuthor} ·
{/if}
@@ -242,7 +245,9 @@ {/if}
-

Answers ({answers.length})

+

+ Answers{answers.length > 0 ? ` (${answers.length})` : ""} +

{#if get(isAuthenticated)}
diff --git a/src/routes/search/+page.svelte b/src/routes/search/+page.svelte index 940471b..af95f1d 100644 --- a/src/routes/search/+page.svelte +++ b/src/routes/search/+page.svelte @@ -85,9 +85,9 @@ unitCode={result.unit ? result.unit.code + (result.unit.code2 ? ` / ${result.unit.code2}` : "") : undefined} - meta="{result.authorName} · {timeAgo( - result.createdAt, - )} · {result.commentCount} comment{result.commentCount === 1 ? '' : 's'}" + meta={result.commentCount > 0 + ? `${result.authorName} · ${timeAgo(result.createdAt)} · ${result.commentCount} comment${result.commentCount === 1 ? "" : "s"}` + : `${result.authorName} · ${timeAgo(result.createdAt)}`} voteCount={result.voteCount} targetType="note" targetId={result._id} @@ -101,9 +101,9 @@ unitCode={result.unit ? result.unit.code + (result.unit.code2 ? ` / ${result.unit.code2}` : "") : undefined} - meta="{result.authorName} · {timeAgo( - result.createdAt, - )} · {result.answerCount} answer{result.answerCount === 1 ? '' : 's'}" + meta={result.answerCount > 0 + ? `${result.authorName} · ${timeAgo(result.createdAt)} · ${result.answerCount} answer${result.answerCount === 1 ? "" : "s"}` + : `${result.authorName} · ${timeAgo(result.createdAt)}`} voteCount={result.voteCount} targetType="question" targetId={result._id} diff --git a/src/routes/topics/[slug]/+page.svelte b/src/routes/topics/[slug]/+page.svelte index 9ef53f4..f6da8cd 100644 --- a/src/routes/topics/[slug]/+page.svelte +++ b/src/routes/topics/[slug]/+page.svelte @@ -67,9 +67,9 @@ unitCode={note.unit ? note.unit.code + (note.unit.code2 ? ` / ${note.unit.code2}` : "") : undefined} - meta="{note.authorName} · {timeAgo( - note.createdAt, - )} · {note.commentCount} comment{note.commentCount === 1 ? '' : 's'}" + meta={note.commentCount > 0 + ? `${note.authorName} · ${timeAgo(note.createdAt)} · ${note.commentCount} comment${note.commentCount === 1 ? "" : "s"}` + : `${note.authorName} · ${timeAgo(note.createdAt)}`} voteCount={note.voteCount} targetType="note" targetId={note._id} @@ -88,9 +88,9 @@ ? question.unit.code + (question.unit.code2 ? ` / ${question.unit.code2}` : "") : undefined} - meta="{question.authorName} · {timeAgo( - question.createdAt, - )} · {question.answerCount} answer{question.answerCount === 1 ? '' : 's'}" + meta={question.answerCount > 0 + ? `${question.authorName} · ${timeAgo(question.createdAt)} · ${question.answerCount} answer${question.answerCount === 1 ? "" : "s"}` + : `${question.authorName} · ${timeAgo(question.createdAt)}`} voteCount={question.voteCount} targetType="question" targetId={question._id} diff --git a/src/routes/units/[code]/+page.svelte b/src/routes/units/[code]/+page.svelte index 1b8d1d9..5a542aa 100644 --- a/src/routes/units/[code]/+page.svelte +++ b/src/routes/units/[code]/+page.svelte @@ -174,9 +174,9 @@ title={note.title} content={note.content} unitCode={unit.code + (unit.code2 ? ` / ${unit.code2}` : "")} - meta="{timeAgo( - note.createdAt, - )} · {note.commentCount} comment{note.commentCount === 1 ? '' : 's'}" + meta={note.commentCount > 0 + ? `${timeAgo(note.createdAt)} · ${note.commentCount} comment${note.commentCount === 1 ? "" : "s"}` + : timeAgo(note.createdAt)} voteCount={note.voteCount} targetType="note" targetId={note._id} @@ -192,9 +192,9 @@ title={question.title} content={question.content} unitCode={unit.code + (unit.code2 ? ` / ${unit.code2}` : "")} - meta="{question.authorName} · {timeAgo( - question.createdAt, - )} · {question.answerCount} answer{question.answerCount === 1 ? '' : 's'}" + meta={question.answerCount > 0 + ? `${question.authorName} · ${timeAgo(question.createdAt)} · ${question.answerCount} answer${question.answerCount === 1 ? "" : "s"}` + : `${question.authorName} · ${timeAgo(question.createdAt)}`} voteCount={question.voteCount} targetType="question" targetId={question._id}