@{author}{post.name ? ` · ${post.name}` : ""}{new Date(publishedAt).toLocaleString("zh-TW")}
{tags.map((tag) => #{tag})}{post.source_id && 來源}閱讀全文 · 💬 {post.comment_count} 🙂 {post.reaction_count}
;
+ const publishedAt = post.remote_created_at || post.created_at; return {postAuthorLabel(post)}{new Date(publishedAt).toLocaleString("zh-TW")}
{tags.map((tag) => #{tag})}{post.source_id && 來源}閱讀全文 · 💬 {post.comment_count} 🙂 {post.reaction_count}
;
}
diff --git a/lib/display.ts b/lib/display.ts
new file mode 100644
index 0000000..c298f5a
--- /dev/null
+++ b/lib/display.ts
@@ -0,0 +1,16 @@
+export type AuthorDisplay = {
+ origin: string;
+ username: string;
+ name: string | null;
+ remote_display_name?: string | null;
+ source_base_url: string | null;
+};
+
+export function postAuthorLabel(post: AuthorDisplay) {
+ const linkedMemos = post.origin === "memos" || post.origin === "hub";
+ const author = linkedMemos ? (post.remote_display_name || post.name || post.username) : (post.name || post.username);
+ if (linkedMemos && post.source_base_url) {
+ try { return `@${author}@${new URL(post.source_base_url).hostname}`; } catch { /* Keep a readable fallback for legacy malformed URLs. */ }
+ }
+ return `@${author}${post.name ? ` · ${post.name}` : ""}`;
+}
diff --git a/tests/display.test.ts b/tests/display.test.ts
new file mode 100644
index 0000000..49d03f1
--- /dev/null
+++ b/tests/display.test.ts
@@ -0,0 +1,15 @@
+import assert from "node:assert/strict";
+import { test } from "node:test";
+import { postAuthorLabel } from "../lib/display";
+
+test("formats Memos authors as name at source hostname", () => {
+ assert.equal(postAuthorLabel({ origin: "memos", username: "hub-user", name: "codex", remote_display_name: "codex", source_base_url: "https://memos.fishking.studio/path" }), "@codex@memos.fishking.studio");
+});
+
+test("formats Hub posts linked to Memos with the same source identity", () => {
+ assert.equal(postAuthorLabel({ origin: "hub", username: "codex", name: "codex", remote_display_name: "codex", source_base_url: "https://memos.fishking.studio" }), "@codex@memos.fishking.studio");
+});
+
+test("keeps the existing label for non-Memos posts", () => {
+ assert.equal(postAuthorLabel({ origin: "hub", username: "codex", name: "Hub", source_base_url: null }), "@Hub · Hub");
+});