refact web
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { renderMarkdown } from '../lib/markdown'
|
||||
import type { Post } from '../types'
|
||||
import { escapeHtml, escapeAttr, formatDateJa } from '../lib/util'
|
||||
|
||||
// Note post has extra fields for member content
|
||||
interface NotePost extends Post {
|
||||
@@ -42,12 +43,10 @@ export function renderNoteListPage(posts: NotePost[], handle: string): string {
|
||||
export function renderNoteDetailPage(
|
||||
post: NotePost,
|
||||
_handle: string,
|
||||
localOnly: boolean
|
||||
isOwner: boolean
|
||||
): string {
|
||||
const rkey = post.uri.split('/').pop() || ''
|
||||
const date = new Date(post.value.publishedAt).toLocaleDateString('ja-JP', {
|
||||
year: 'numeric', month: '2-digit', day: '2-digit'
|
||||
})
|
||||
const date = formatDateJa(post.value.publishedAt)
|
||||
const freeText = post.value.content?.text || ''
|
||||
const memberText = post.value.member?.text || ''
|
||||
const bonusText = post.value.member?.bonus || ''
|
||||
@@ -59,7 +58,7 @@ export function renderNoteDetailPage(
|
||||
let html = ''
|
||||
|
||||
// Action buttons at top
|
||||
if (localOnly) {
|
||||
if (isOwner) {
|
||||
html += `
|
||||
<div class="note-actions">
|
||||
<button type="button" class="note-copy-btn" id="note-copy-title">Copy Title</button>
|
||||
@@ -103,7 +102,7 @@ export function renderNoteDetailPage(
|
||||
html += `</div>`
|
||||
|
||||
// Edit form (below content)
|
||||
if (localOnly) {
|
||||
if (isOwner) {
|
||||
html += `
|
||||
<div class="note-edit" id="note-edit-form" style="display:none">
|
||||
<input type="text" id="note-edit-title" class="note-edit-input" value="${escapeAttr(post.value.title)}" placeholder="Title">
|
||||
@@ -223,10 +222,3 @@ export function setupNoteDetail(
|
||||
})
|
||||
}
|
||||
|
||||
function escapeHtml(s: string): string {
|
||||
return s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"')
|
||||
}
|
||||
|
||||
function escapeAttr(s: string): string {
|
||||
return s.replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user