import { searchPostsForUrl } from '../lib/api.js' import { escapeHtml } from '../lib/utils.js' // Map network to app URL export function getAppUrl(network: string): string { if (network === 'syu.is') { return 'https://syu.is' } return 'https://bsky.app' } function formatDate(dateStr: string): string { const date = new Date(dateStr) return date.toLocaleDateString('ja-JP', { year: 'numeric', month: '2-digit', day: '2-digit', }) } function getPostUrl(uri: string, appUrl: string): string { // at://did:plc:xxx/app.bsky.feed.post/rkey -> {appUrl}/profile/did:plc:xxx/post/rkey const parts = uri.replace('at://', '').split('/') if (parts.length >= 3) { return `${appUrl}/profile/${parts[0]}/post/${parts[2]}` } return '#' } export function renderDiscussionLink(postUrl: string, appUrl: string = 'https://bsky.app'): string { // Convert full URL to search-friendly format (domain/post/rkey_prefix without https://) // Keep total length around 20 chars to avoid URL truncation in posts const MAX_SEARCH_LENGTH = 20 let searchQuery = postUrl try { const urlObj = new URL(postUrl) const pathParts = urlObj.pathname.split('/').filter(Boolean) const basePath = urlObj.host + '/' + (pathParts[0] || '') + '/' const rkey = pathParts[1] || '' const remainingLength = MAX_SEARCH_LENGTH - basePath.length const rkeyPrefix = remainingLength > 0 ? rkey.slice(0, remainingLength) : '' searchQuery = basePath + rkeyPrefix } catch { // Keep original if parsing fails } const searchUrl = `${appUrl}/search?q=${encodeURIComponent(searchQuery)}` return `
` } export async function loadDiscussionPosts(container: HTMLElement, postUrl: string, appUrl: string = 'https://bsky.app'): Promise