Files
past-go/weapp/utils/photo-metadata.js

13 lines
717 B
JavaScript

function photoForm(photo) {
return { taken_at: String(photo.taken_at || '').slice(0, 10), location: photo.location || '', activity: photo.activity || '' };
}
function metadataRows(photos) {
const rows = photos.map((photo, index) => ({ ...photoForm(photo), id: photo.id, photoIndex: index, label: photos.length > 1 ? '第 ' + (index + 1) + ' 张' : '' }));
if (!rows.length) return [];
const same = rows.every(row => row.taken_at === rows[0].taken_at && row.location === rows[0].location && row.activity === rows[0].activity);
if (same) rows.splice(1);
if (same) rows[0].label = '';
return rows.filter(row => row.taken_at || row.location || row.activity);
}
module.exports = { photoForm, metadataRows };