17 lines
1.1 KiB
JavaScript
17 lines
1.1 KiB
JavaScript
const { getImageUrl } = require('./request');
|
|
function diaryEntry(item) {
|
|
var images = item.images || [];
|
|
if (typeof images === 'string') { try { images = JSON.parse(images); } catch (e) { images = []; } }
|
|
if (!Array.isArray(images)) images = [];
|
|
var date = String(item.created_at || '').slice(0, 10);
|
|
var characters = Array.from(String(item.content || '').replace(/\s+/g, ' '));
|
|
var summary = characters.slice(0, 100).join('') + (characters.length > 100 ? '…' : '');
|
|
return Object.assign({}, item, { title: item.title || '日常的一页', summary: summary, date: date, dateLabel: date.replace(/-/g, '.'), cover: getImageUrl(images[0]), imageCount: images.length, author: item.creator_name || item.created_by_name || '' });
|
|
}
|
|
function albumEntry(item) { return Object.assign({}, item, { cover: getImageUrl(item.cover), title: item.title || '我们的相册' }); }
|
|
function memoryEntry(item) {
|
|
var date = String(item.event_date || '').slice(0, 10);
|
|
return Object.assign({}, item, { date: date, dateMonth: date.slice(5, 7), dateDay: date.slice(8, 10) });
|
|
}
|
|
module.exports = { diaryEntry, albumEntry, memoryEntry };
|