2024-09-11 03:16:53 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const config = require('config');
|
|
|
|
const dateFns = require('date-fns');
|
|
|
|
|
|
|
|
const extensions = {
|
|
|
|
'image/jpeg': '.jpg',
|
|
|
|
'image/gif': '.gif',
|
|
|
|
'video/mp4': '.mp4',
|
|
|
|
'video/webm': '.webm'
|
|
|
|
};
|
|
|
|
|
2024-09-11 03:16:53 +00:00
|
|
|
function interpolate(path, post, item) {
|
2024-09-11 03:16:53 +00:00
|
|
|
const dateFormat = config.patterns.dateFormat || 'YYYYMMDD';
|
2024-09-11 03:16:53 +00:00
|
|
|
|
|
|
|
const vars = {
|
|
|
|
$postId: post.id,
|
2024-09-11 03:16:53 +00:00
|
|
|
$postTitle: (post.title || '').slice(0, config.patterns.titleLength),
|
2024-09-11 03:16:53 +00:00
|
|
|
$postUser: post.user,
|
2024-09-11 03:16:53 +00:00
|
|
|
$postDate: dateFns.format(post.datetime, dateFormat),
|
2024-09-11 03:16:53 +00:00
|
|
|
$postIndex: post.index + config.patterns.indexOffset,
|
|
|
|
$host: post.host.label
|
2024-09-11 03:16:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if(post.content.album) {
|
|
|
|
Object.assign(vars, {
|
|
|
|
$albumId: post.content.album.id,
|
2024-09-11 03:16:53 +00:00
|
|
|
$albumTitle: (post.content.album.title || '').slice(0, config.patterns.titleLength),
|
2024-09-11 03:16:53 +00:00
|
|
|
$albumDescription: post.content.album.description,
|
|
|
|
$albumDate: dateFns.format(post.content.album.datetime, dateFormat)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if(item) {
|
|
|
|
Object.assign(vars, {
|
|
|
|
$itemId: item.id,
|
2024-09-11 03:16:53 +00:00
|
|
|
$itemTitle: (item.title || '').slice(0, config.patterns.titleLength),
|
2024-09-11 03:16:53 +00:00
|
|
|
$itemDescription: item.description,
|
|
|
|
$itemDate: dateFns.format(item.datetime, dateFormat),
|
2024-09-11 03:16:53 +00:00
|
|
|
$itemIndex: item.index + config.patterns.indexOffset,
|
2024-09-11 03:16:53 +00:00
|
|
|
$extracted: item.extracted ? config.patterns.extractedLabel : '',
|
2024-09-11 03:16:53 +00:00
|
|
|
$ext: extensions[item.type]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return Object.entries(vars).reduce((acc, [key, value], index) => {
|
|
|
|
// strip slashes for filesystem compatability
|
|
|
|
value = (value || '').toString().replace(/\//g, config.patterns.slashSubstitute);
|
|
|
|
|
|
|
|
return acc.replace(key, value);
|
|
|
|
}, path);
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = interpolate;
|