nomadro/apps/ebook/src/lib/share-text.ts
eric 0fc608ea26 Fix ebook /read links to /book/read and add compat redirects.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-28 18:54:03 -05:00

25 lines
809 B
TypeScript

import type { Book, Chapter } from './book-types';
import { buildShareUrl } from './utm';
export function getShareText(chapter: Chapter, book: Book) {
const tags = book.viralTags.slice(0, 2).map((t) => `#${t}`).join(' ');
return `《${book.title}》· ${chapter.title}\n${chapter.hook}\n\n${tags}`;
}
export function getBookShareText(book: Pick<Book, 'title' | 'tagline' | 'viralTags'>) {
const tags = book.viralTags.slice(0, 3).map((t) => `#${t}`).join(' ');
return `📖《${book.title}》\n${book.tagline}\n\n${tags}`;
}
export function getChapterShareUrl(slug: string) {
return buildShareUrl(`/book/read#${slug}`, 'chapter');
}
export function getBookShareUrl() {
return buildShareUrl('/', 'cover');
}
export function getReadShareUrl() {
return buildShareUrl('/book/read', 'reader');
}