Try extra hard to extract dates
This commit is contained in:
parent
2d0e9b9f67
commit
423bfe47d8
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "publikator",
|
"name": "publikator",
|
||||||
"version": "0.17.3",
|
"version": "0.17.5",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"repository": "https://github.com/aengl/publikator.git",
|
"repository": "https://github.com/aengl/publikator.git",
|
||||||
"author": "Lynn Smeria <ae@cephea.de>",
|
"author": "Lynn Smeria <ae@cephea.de>",
|
||||||
|
|
|
@ -17,18 +17,30 @@ const collect = (tracks, callback) => {
|
||||||
return values.length === 1 ? values[0] : values;
|
return values.length === 1 ? values[0] : values;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the first defined metadata at the specified path.
|
||||||
|
*/
|
||||||
|
const find = (tracks, path) =>
|
||||||
|
_.get(tracks.find(track => !_.isNil(_.get(track, path))), path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates release information for a single album.
|
* Creates release information for a single album.
|
||||||
*/
|
*/
|
||||||
const getAlbumInfo = (root, tracks) => ({
|
const getAlbumInfo = (root, tracks) => ({
|
||||||
layout: 'album',
|
layout: 'album',
|
||||||
slug: path.basename(root),
|
slug: path.basename(root),
|
||||||
name: tracks[0].common.album || '',
|
name: find(tracks, 'common.album'),
|
||||||
artists: collect(tracks, t => t.common.artists || t.common.artist),
|
artists: collect(tracks, t => t.common.artists || t.common.artist),
|
||||||
bitrate: collect(tracks, t => t.format.bitrate),
|
bitrate: collect(tracks, t => t.format.bitrate),
|
||||||
trackCount: tracks.length,
|
trackCount: tracks.length,
|
||||||
cover: tracks[0].cover || null,
|
cover: find(tracks, 'cover'),
|
||||||
date: tracks[0].common.date || null,
|
date:
|
||||||
|
find(tracks, 'common.date') ||
|
||||||
|
find(tracks, 'common.originaldate') ||
|
||||||
|
find(tracks, 'all.ORIGINALDATE') ||
|
||||||
|
find(tracks, 'common.year') ||
|
||||||
|
find(tracks, 'common.originalyear') ||
|
||||||
|
find(tracks, 'all.ORIGINALYEAR'),
|
||||||
tracks: _.sortBy(tracks, 'common.track.no'),
|
tracks: _.sortBy(tracks, 'common.track.no'),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -47,6 +59,14 @@ const getTrackInfo = (albumInfo, trackIndex) => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts an object to YAML.
|
||||||
|
*/
|
||||||
|
const toYaml = obj =>
|
||||||
|
yaml.safeDump(obj, {
|
||||||
|
skipInvalid: true,
|
||||||
|
});
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
/**
|
/**
|
||||||
* Generates Jekyll-compatible release data
|
* Generates Jekyll-compatible release data
|
||||||
|
@ -68,7 +88,7 @@ module.exports = {
|
||||||
} track(s)`
|
} track(s)`
|
||||||
);
|
);
|
||||||
const albumInfo = getAlbumInfo(albumRoot, tracks);
|
const albumInfo = getAlbumInfo(albumRoot, tracks);
|
||||||
const releaseInfo = `---\n${yaml.safeDump(albumInfo)}---\n`;
|
const releaseInfo = `---\n${toYaml(albumInfo)}---\n`;
|
||||||
await fs.writeFile(
|
await fs.writeFile(
|
||||||
path.resolve(albumCollectionRoot, `${baseName}.md`),
|
path.resolve(albumCollectionRoot, `${baseName}.md`),
|
||||||
releaseInfo
|
releaseInfo
|
||||||
|
@ -84,10 +104,7 @@ module.exports = {
|
||||||
`${track.slug}.md`
|
`${track.slug}.md`
|
||||||
);
|
);
|
||||||
await fs.ensureFile(trackInfoPath);
|
await fs.ensureFile(trackInfoPath);
|
||||||
await fs.writeFile(
|
await fs.writeFile(trackInfoPath, `---\n${toYaml(track)}---\n`);
|
||||||
trackInfoPath,
|
|
||||||
`---\n${yaml.safeDump(track)}---\n`
|
|
||||||
);
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -99,6 +116,6 @@ module.exports = {
|
||||||
debug(`generating data for ${albumsInfo.length} album(s)`);
|
debug(`generating data for ${albumsInfo.length} album(s)`);
|
||||||
const albumsInfoPath = path.resolve(root, '_data', 'albums.yml');
|
const albumsInfoPath = path.resolve(root, '_data', 'albums.yml');
|
||||||
await fs.ensureFile(albumsInfoPath);
|
await fs.ensureFile(albumsInfoPath);
|
||||||
await fs.writeFile(albumsInfoPath, yaml.safeDump(albumsInfo));
|
await fs.writeFile(albumsInfoPath, toYaml(albumsInfo));
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue