have aaaaall the images
This commit is contained in:
parent
29f6ca9691
commit
d0aeff8488
1 changed files with 69 additions and 18 deletions
|
|
@ -265,23 +265,51 @@ function renderRandomPictures(picturesData, containerId, randomize = false) {
|
||||||
const container = document.getElementById(containerId);
|
const container = document.getElementById(containerId);
|
||||||
if (!container) return;
|
if (!container) return;
|
||||||
|
|
||||||
let selected;
|
// First, flatten all pictures from all events
|
||||||
if (randomize) {
|
let allPictures = [];
|
||||||
const shuffled = shuffleArray(picturesData);
|
|
||||||
selected = shuffled.slice(0, 6);
|
picturesData.forEach(event => {
|
||||||
} else {
|
// Check if this event has multiple imeta tags
|
||||||
const sorted = [...picturesData].sort((a, b) => b.created_at - a.created_at);
|
const imetaTags = [];
|
||||||
selected = sorted.slice(0, 6);
|
event.tags.forEach(tag => {
|
||||||
|
if (tag[0] === 'imeta') {
|
||||||
|
imetaTags.push(tag);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
container.innerHTML = '';
|
if (imetaTags.length > 0) {
|
||||||
|
// Parse each imeta tag
|
||||||
selected.forEach(picture => {
|
imetaTags.forEach(imetaTag => {
|
||||||
let imageUrl = '';
|
let imageUrl = '';
|
||||||
let alt = picture.content || '';
|
let alt = event.content || '';
|
||||||
|
|
||||||
if (picture.tags) {
|
// The imeta tag is an array of strings
|
||||||
picture.tags.forEach(tag => {
|
imetaTag.forEach(item => {
|
||||||
|
if (typeof item === 'string') {
|
||||||
|
if (item.startsWith('url ')) {
|
||||||
|
imageUrl = item.replace('url ', '').trim();
|
||||||
|
}
|
||||||
|
if (item.startsWith('alt ')) {
|
||||||
|
alt = item.replace('alt ', '').trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (imageUrl) {
|
||||||
|
allPictures.push({
|
||||||
|
url: imageUrl,
|
||||||
|
alt: alt,
|
||||||
|
created_at: event.created_at,
|
||||||
|
pubkey: event.pubkey
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Fallback: single image event (kind 20 with one imeta)
|
||||||
|
let imageUrl = '';
|
||||||
|
let alt = event.content || '';
|
||||||
|
|
||||||
|
event.tags.forEach(tag => {
|
||||||
if (tag[0] === 'imeta') {
|
if (tag[0] === 'imeta') {
|
||||||
const imetaStr = tag[1];
|
const imetaStr = tag[1];
|
||||||
const urlMatch = imetaStr.match(/url ([^\s]+)/);
|
const urlMatch = imetaStr.match(/url ([^\s]+)/);
|
||||||
|
|
@ -290,12 +318,35 @@ function renderRandomPictures(picturesData, containerId, randomize = false) {
|
||||||
if (altMatch) alt = altMatch[1];
|
if (altMatch) alt = altMatch[1];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (imageUrl) {
|
||||||
|
allPictures.push({
|
||||||
|
url: imageUrl,
|
||||||
|
alt: alt,
|
||||||
|
created_at: event.created_at,
|
||||||
|
pubkey: event.pubkey
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Now select from all pictures
|
||||||
|
let selected;
|
||||||
|
if (randomize) {
|
||||||
|
const shuffled = shuffleArray(allPictures);
|
||||||
|
selected = shuffled.slice(0, 6);
|
||||||
|
} else {
|
||||||
|
const sorted = [...allPictures].sort((a, b) => b.created_at - a.created_at);
|
||||||
|
selected = sorted.slice(0, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
container.innerHTML = '';
|
||||||
|
|
||||||
|
selected.forEach(picture => {
|
||||||
const item = document.createElement('div');
|
const item = document.createElement('div');
|
||||||
item.className = 'photo-item';
|
item.className = 'photo-item';
|
||||||
item.dataset.image = imageUrl;
|
item.dataset.image = picture.url;
|
||||||
item.dataset.alt = alt;
|
item.dataset.alt = picture.alt;
|
||||||
|
|
||||||
const date = new Date(picture.created_at * 1000);
|
const date = new Date(picture.created_at * 1000);
|
||||||
const dateStr = date.toLocaleDateString('en-US', {
|
const dateStr = date.toLocaleDateString('en-US', {
|
||||||
|
|
@ -305,7 +356,7 @@ function renderRandomPictures(picturesData, containerId, randomize = false) {
|
||||||
item.dataset.pubkey = picture.pubkey || '';
|
item.dataset.pubkey = picture.pubkey || '';
|
||||||
|
|
||||||
item.innerHTML = `
|
item.innerHTML = `
|
||||||
${imageUrl ? `<img src="${imageUrl}" alt="${alt}" loading="lazy">` : ''}
|
${picture.url ? `<img src="${picture.url}" alt="${picture.alt}" loading="lazy">` : ''}
|
||||||
<div class="photo-date"><span>📅 ${dateStr}</span></div>
|
<div class="photo-date"><span>📅 ${dateStr}</span></div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue