fix post generate

This commit is contained in:
2026-01-15 19:46:01 +09:00
parent 162072d980
commit 9980e596ca
13 changed files with 1834 additions and 120 deletions

View File

@@ -47,7 +47,7 @@ async function renderServices(did: string, handle: string): Promise<string> {
const items = Array.from(serviceMap.entries()).map(([domain, info]) => {
return `
<li class="service-list-item">
<a href="?mode=browser&handle=${handle}&service=${encodeURIComponent(domain)}" class="service-list-link">
<a href="/at/${handle}/${domain}" class="service-list-link">
<img src="${info.favicon}" class="service-list-favicon" alt="" onerror="this.style.display='none'">
<span class="service-list-name">${info.name}</span>
<span class="service-list-count">${info.count}</span>
@@ -84,7 +84,7 @@ async function renderCollections(did: string, handle: string, serviceDomain: str
const items = filtered.map(col => {
return `
<li class="collection-item">
<a href="?mode=browser&handle=${handle}&collection=${encodeURIComponent(col)}" class="collection-link">
<a href="/at/${handle}/${col}" class="collection-link">
<span class="collection-nsid">${col}</span>
</a>
</li>
@@ -111,7 +111,7 @@ async function renderRecordList(did: string, handle: string, collection: string)
const preview = rec.value.title || rec.value.text?.slice(0, 50) || rkey
return `
<li class="record-item">
<a href="?mode=browser&handle=${handle}&collection=${encodeURIComponent(collection)}&rkey=${rkey}" class="record-link">
<a href="/at/${handle}/${collection}/${rkey}" class="record-link">
<span class="record-rkey">${rkey}</span>
<span class="record-preview">${preview}</span>
</a>
@@ -168,7 +168,7 @@ export async function mountAtBrowser(
service: string | null = null,
loginDid: string | null = null
): Promise<void> {
container.innerHTML = '<p class="loading">Loading...</p>'
container.innerHTML = '<div class="loading"><div class="loading-spinner"></div></div>'
try {
const did = handle.startsWith('did:') ? handle : await resolveHandle(handle)
@@ -178,16 +178,16 @@ export async function mountAtBrowser(
let nav = ''
if (collection && rkey) {
nav = `<a href="?mode=browser&handle=${handle}&collection=${encodeURIComponent(collection)}" class="back-link">← Back</a>`
nav = `<a href="/at/${handle}/${collection}" class="back-link">← Back</a>`
content = await renderRecordDetail(did, handle, collection, rkey, canDelete)
} else if (collection) {
// Get service from collection for back link
const info = getServiceInfo(collection)
const backService = info ? info.domain : ''
nav = `<a href="?mode=browser&handle=${handle}&service=${encodeURIComponent(backService)}" class="back-link">← ${info?.name || 'Back'}</a>`
nav = `<a href="/at/${handle}/${backService}" class="back-link">← ${info?.name || 'Back'}</a>`
content = await renderRecordList(did, handle, collection)
} else if (service) {
nav = `<a href="?mode=browser&handle=${handle}" class="back-link">← Services</a>`
nav = `<a href="/at/${handle}" class="back-link">← Services</a>`
content = await renderCollections(did, handle, service)
} else {
content = await renderServices(did, handle)
@@ -213,7 +213,7 @@ export async function mountAtBrowser(
btn.textContent = 'Deleting...'
await deleteRecord(col, rk)
// Go back to collection
window.location.href = `?mode=browser&handle=${handle}&collection=${encodeURIComponent(col)}`
window.location.href = `/at/${handle}/${col}`
} catch (err) {
alert('Delete failed: ' + err)
btn.disabled = false

View File

@@ -41,13 +41,25 @@ export function mountHeader(
currentHandle: string,
isLoggedIn: boolean,
userHandle: string | undefined,
callbacks: HeaderCallbacks
callbacks: HeaderCallbacks,
isStatic: boolean = false
): void {
container.innerHTML = renderHeader(currentHandle, isLoggedIn, userHandle)
// For static pages, only update if login state requires it
const existingLoginBtn = container.querySelector('#login-btn')
const existingUserBtn = container.querySelector('#user-btn')
const needsUpdate = !isStatic ||
(isLoggedIn && existingLoginBtn) || // Need to show user button
(!isLoggedIn && existingUserBtn) // Need to show login button
if (needsUpdate) {
container.innerHTML = renderHeader(currentHandle, isLoggedIn, userHandle)
}
const form = document.getElementById('header-form') as HTMLFormElement
const input = document.getElementById('header-input') as HTMLInputElement
if (!form) return
form.addEventListener('submit', (e) => {
e.preventDefault()
const handle = input.value.trim()

View File

@@ -1,5 +1,6 @@
import type { BlogPost } from '../types.js'
import { putRecord } from '../lib/auth.js'
import { renderMarkdown } from '../lib/markdown.js'
function formatDate(dateStr: string): string {
const date = new Date(dateStr)
@@ -28,7 +29,7 @@ export function mountPostList(container: HTMLElement, posts: BlogPost[]): void {
const rkey = post.uri.split('/').pop()
return `
<li class="post-item">
<a href="?rkey=${rkey}" class="post-link">
<a href="/post/${rkey}" class="post-link">
<span class="post-title">${escapeHtml(post.title)}</span>
<span class="post-date">${formatDate(post.createdAt)}</span>
</a>
@@ -41,7 +42,7 @@ export function mountPostList(container: HTMLElement, posts: BlogPost[]): void {
export function mountPostDetail(container: HTMLElement, post: BlogPost, handle: string, collection: string, canEdit: boolean = false): void {
const rkey = post.uri.split('/').pop() || ''
const jsonUrl = `?mode=browser&handle=${handle}&collection=${encodeURIComponent(collection)}&rkey=${rkey}`
const jsonUrl = `/at/${handle}/${collection}/${rkey}`
const editBtn = canEdit ? `<button class="edit-btn" id="edit-btn">edit</button>` : ''
@@ -55,7 +56,7 @@ export function mountPostDetail(container: HTMLElement, post: BlogPost, handle:
${editBtn}
</div>
</header>
<div class="post-content" id="post-content">${escapeHtml(post.content)}</div>
<div class="post-content" id="post-content">${renderMarkdown(post.content)}</div>
</article>
<div class="edit-form-container" id="edit-form-container" style="display: none;">

View File

@@ -23,7 +23,7 @@ export async function renderServices(handle: string): Promise<string> {
}
const items = Array.from(serviceMap.entries()).map(([domain, info]) => {
const url = `?mode=browser&handle=${handle}&service=${encodeURIComponent(domain)}`
const url = `/at/${handle}/${domain}`
return `
<a href="${url}" class="service-item" title="${info.collections.join(', ')}">