Add /items: one merged grid of every item the pub knows about
cust.ooo linked to one viewer page per kiosk, so every new kiosk meant
another hand-added link. /items selects on "whatever this pub follows"
instead: follow a new kiosk from the pub and its items appear on the next
cache miss, with no code change and no edit to the site.
serveUserFeed already reduced a feed's contact messages into a follow set;
that moves to lib/follows.js so both routes share one implementation rather
than drifting. It also picks up a fix on the way: the old filter passed
messages with no .value through and then dereferenced .value.content on them.
Two properties of the data drive items.js, both verified against the live log
and both quietly wrong to assume otherwise:
* custodisco is the STRING "true", not a boolean.
* no custo message has ever set content.channel, so the channel index finds
nothing and the filter has to read content fields directly. This is why
/channel/custodisco renders an empty page.
Log order is arrival order, which diverges from publish order whenever an old
feed is backfilled, so the collected set is sorted by timestamp. That makes
"newest first" and the ?before cursor agree; verified as zero overlap between
consecutive pages.
Cards rather than articles: 300 photos in a single column reads like a mailing
list, not an archive. A transfer borrows the photo of the item it transfers and
links to that item's thread, so the grid stays regular and the give is still
legible as a hand-off. Images are lazy, and 267 blobs are held against 301
mints, so a missing photo degrades to a placeholder instead of a broken icon.
serveHome now shows the grid instead of a bare id-lookup box, which was a dead
end for anyone arriving without an id already in hand. The ?id= redirect stays.
The footer commit now comes from .deployed-commit, written by the deploy
script. Deploys are rsync, so the server's checkout keeps whatever HEAD it was
cloned at and `git rev-parse` there names a commit unrelated to the files
actually running.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0192zBTNZKZn5svyJ5HTnYds
This commit is contained in:
@@ -17,6 +17,7 @@ exports.MdRenderer = MdRenderer
|
||||
exports.renderEmoji = renderEmoji
|
||||
exports.formatMsgs = formatMsgs
|
||||
exports.renderThread = renderThread
|
||||
exports.renderItemGrid = renderItemGrid
|
||||
exports.renderAbout = renderAbout
|
||||
exports.renderShowAll = renderShowAll
|
||||
exports.renderRssItem = renderRssItem
|
||||
@@ -172,10 +173,21 @@ function renderRssItem(opts) {
|
||||
)
|
||||
}
|
||||
|
||||
const gitHead = proc.spawnSync('git', ['rev-parse', 'HEAD'], {
|
||||
encoding: 'utf8',
|
||||
cwd: __dirname
|
||||
}).stdout.trim()
|
||||
// Which commit is actually running. Deploys are rsync, not `git pull`, so the
|
||||
// checkout on the server keeps whatever HEAD it was cloned at and `git
|
||||
// rev-parse` there would name a commit that has nothing to do with these files.
|
||||
// bin/deploy-viewer.sh writes the real one to .deployed-commit; fall back to
|
||||
// git only when running straight from a working copy.
|
||||
const gitHead = (function () {
|
||||
try {
|
||||
var stamped = fs.readFileSync(path.join(__dirname, '.deployed-commit'), 'utf8').trim()
|
||||
if (stamped) return stamped
|
||||
} catch (e) { /* not a deploy, ask git */ }
|
||||
return proc.spawnSync('git', ['rev-parse', 'HEAD'], {
|
||||
encoding: 'utf8',
|
||||
cwd: __dirname
|
||||
}).stdout.trim()
|
||||
}())
|
||||
const gitHeadShort = gitHead && gitHead.substr(0, 7)
|
||||
const commitUrl = pkg.homepage &&
|
||||
pkg.homepage.replace(/\/+$/, '') + '/commit/' + gitHead
|
||||
@@ -192,7 +204,7 @@ function wrapPage(id) {
|
||||
"<!doctype html><html><head>" +
|
||||
"<meta charset=utf-8>" +
|
||||
"<title>" +
|
||||
id + " | ssb-viewer" +
|
||||
id + " | custo" +
|
||||
"</title>" +
|
||||
'<meta name=viewport content="width=device-width,initial-scale=1">' +
|
||||
styles +
|
||||
@@ -339,6 +351,77 @@ var styles = `
|
||||
font-size: 14px;
|
||||
color: #868e96;
|
||||
}
|
||||
|
||||
.items-header { max-width: 60rem; margin: 0 auto 24px; text-align: center; }
|
||||
.items-header h1 { margin: 0 0 4px; font-size: 1.6em; letter-spacing: 0.04em; }
|
||||
.items-count { margin: 0 0 14px; color: #868e96; font-size: 14px; }
|
||||
.items-search input[type=submit] { cursor: pointer; }
|
||||
|
||||
main.item-grid {
|
||||
max-width: 60rem;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
|
||||
gap: 14px;
|
||||
}
|
||||
/* the single-column rules above target articles; cards are anchors */
|
||||
.item-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background-color: white;
|
||||
border-radius: 3px;
|
||||
box-shadow: 0 1px 3px #949494;
|
||||
overflow: hidden;
|
||||
text-decoration: none;
|
||||
color: #212529;
|
||||
}
|
||||
.item-card:hover { box-shadow: 0 2px 8px #6c757d; }
|
||||
.item-media { position: relative; }
|
||||
.item-photo {
|
||||
display: block;
|
||||
width: 100%;
|
||||
aspect-ratio: 1 / 1;
|
||||
object-fit: cover;
|
||||
background-color: #e9ecef;
|
||||
}
|
||||
.item-photo-missing {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #adb5bd;
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
}
|
||||
.item-photo-missing::after { content: "photo not fetched yet"; }
|
||||
.item-card-give .item-photo { opacity: 0.55; }
|
||||
.item-badge {
|
||||
position: absolute;
|
||||
left: 0; right: 0; bottom: 0;
|
||||
padding: 6px 8px;
|
||||
background-color: rgba(33, 37, 41, 0.82);
|
||||
color: #f1f3f5;
|
||||
font-size: 13px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.item-meta { padding: 10px 12px; display: flex; flex-direction: column; gap: 3px; }
|
||||
.item-caption {
|
||||
line-height: 1.35em;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 3;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
.item-by { color: #495057; font-size: 13px; }
|
||||
.item-meta time { color: #868e96; font-size: 12px; }
|
||||
.items-more {
|
||||
max-width: 60rem;
|
||||
margin: 20px auto 0;
|
||||
text-align: center;
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
justify-content: center;
|
||||
}
|
||||
</style>
|
||||
`
|
||||
|
||||
@@ -633,3 +716,99 @@ function renderShowAll(showAll, url) {
|
||||
if (!showAll)
|
||||
return '<br>' + h('a', { href : url + '?showAll' }, 'Show whole feed').outerHTML
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// The custo item grid (/items)
|
||||
//
|
||||
// Cards, not articles: this is a collection of things, and a single-column feed
|
||||
// of 300 photos reads like a mailing list rather than an archive. A transfer
|
||||
// borrows the photo of the item it transfers, so the grid stays regular.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function renderItemGrid(opts, meta) {
|
||||
return pull(
|
||||
pull.map(renderItemCard.bind(this, opts)),
|
||||
wrap(toolTipTop() + itemsHeader(opts, meta) + '<main class="item-grid">',
|
||||
'</main>' + itemsFooter(opts, meta) + callToAction())
|
||||
)
|
||||
}
|
||||
|
||||
function itemsHeader(opts, meta) {
|
||||
var counted = meta.total === 1 ? '1 item' : meta.total + ' items and transfers'
|
||||
var feeds = meta.feeds === 1 ? '1 feed' : meta.feeds + ' feeds'
|
||||
return h('header.items-header',
|
||||
h('h1', 'custo items'),
|
||||
h('p.items-count', counted + ' from ' + feeds),
|
||||
h('form.items-search', { method: 'get', action: opts.base },
|
||||
h('input', { name: 'id', size: 34,
|
||||
placeholder: 'paste a message or feed id' }), ' ',
|
||||
h('input', { type: 'submit', value: 'Go' }))
|
||||
).outerHTML
|
||||
}
|
||||
|
||||
function itemsFooter(opts, meta) {
|
||||
var links = []
|
||||
if (meta.older)
|
||||
links.push(h('a', { href: opts.base + 'items?before=' + meta.older }, 'older items'))
|
||||
if (!meta.showAll && meta.total > meta.shown)
|
||||
links.push(h('a', { href: opts.base + 'items?showAll' }, 'show everything'))
|
||||
if (!links.length) return ''
|
||||
return h('div.items-more', links).outerHTML
|
||||
}
|
||||
|
||||
function renderItemCard(opts, msg) {
|
||||
var c = msg.value.content
|
||||
var isGive = c.nft === 'give'
|
||||
|
||||
// A transfer links to the item it transfers, not to itself: the thread page
|
||||
// shows the mint and every hand-off since, which is the interesting view.
|
||||
var target = isGive && c.root ? c.root : msg.key
|
||||
|
||||
var media
|
||||
if (msg.itemPhoto) {
|
||||
media = h('img.item-photo', { src: opts.img_base + msg.itemPhoto, alt: '' })
|
||||
// hyperscript assigns these as DOM properties, which outerHTML then drops,
|
||||
// so they have to be set as attributes explicitly.
|
||||
media.setAttribute('loading', 'lazy')
|
||||
media.setAttribute('decoding', 'async')
|
||||
// 267 blobs are held against 301 mints, so some photos genuinely are not
|
||||
// here yet. Fall back to the placeholder rather than a broken-image icon.
|
||||
media.setAttribute('onerror',
|
||||
"this.className='item-photo item-photo-missing';this.removeAttribute('src')")
|
||||
} else {
|
||||
media = h('div.item-photo.item-photo-missing')
|
||||
}
|
||||
|
||||
var badge = isGive
|
||||
? h('span.item-badge', '\u2192 ' + stewardName(msg, c))
|
||||
: ''
|
||||
|
||||
var caption = msg.itemCaption || (isGive ? 'an item' : itemFallbackCaption(c))
|
||||
|
||||
return h('a.item-card' + (isGive ? '.item-card-give' : ''),
|
||||
{ href: opts.base + encodeURIComponent(target) },
|
||||
h('div.item-media', media, badge),
|
||||
h('div.item-meta',
|
||||
h('span.item-caption', caption),
|
||||
h('span.item-by', msg.author && msg.author.name),
|
||||
itemTime(msg))
|
||||
).outerHTML
|
||||
}
|
||||
|
||||
function stewardName(msg, c) {
|
||||
if (msg.stewardAbout && msg.stewardAbout.name) return msg.stewardAbout.name
|
||||
return String(c.target || 'someone').substr(0, 10) + '\u2026'
|
||||
}
|
||||
|
||||
function itemFallbackCaption(c) {
|
||||
return String(c.text || '').replace(/\s+/g, ' ').trim().substr(0, 140) || 'untitled'
|
||||
}
|
||||
|
||||
// Like msgTimestamp, but without the nested <a> \u2014 the whole card is a link.
|
||||
function itemTime(msg) {
|
||||
var date = new Date(msg.value.timestamp)
|
||||
var isoStr = date.toISOString()
|
||||
return h('time.ssb-timestamp',
|
||||
{ datetime: isoStr, title: isoStr },
|
||||
formatDate(date))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user