Include track info for next/prev track

This commit is contained in:
Lynn Smeria 2018-08-29 14:45:46 +02:00
parent 31def3deb0
commit d0a7696b80
2 changed files with 19 additions and 6 deletions

View file

@ -1,6 +1,6 @@
{ {
"name": "publikator", "name": "publikator",
"version": "0.11.0", "version": "0.12.0",
"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>",

View file

@ -31,6 +31,21 @@ const getAlbumInfo = (root, tracks) => ({
tracks, tracks,
}); });
/**
* Creates release information for a single track.
*/
const getTrackInfo = (albumInfo, trackIndex) => {
const nextTrackIndex = (trackIndex + 1) % albumInfo.trackCount;
const previousTrackIndex =
trackIndex === 0 ? albumInfo.trackCount - 1 : trackIndex - 1;
return {
layout: 'track',
...albumInfo.tracks[trackIndex],
nextTrack: albumInfo.tracks[nextTrackIndex],
previousTrack: albumInfo.tracks[previousTrackIndex],
};
};
module.exports = { module.exports = {
/** /**
* Generates Jekyll-compatible release data * Generates Jekyll-compatible release data
@ -60,7 +75,8 @@ module.exports = {
// Write track collection // Write track collection
await Promise.all( await Promise.all(
tracks.map(async track => { tracks.map(async (_0, i) => {
const track = getTrackInfo(albumInfo, i);
const trackInfoPath = path.resolve( const trackInfoPath = path.resolve(
trackCollectionRoot, trackCollectionRoot,
baseName, baseName,
@ -69,10 +85,7 @@ module.exports = {
await fs.ensureFile(trackInfoPath); await fs.ensureFile(trackInfoPath);
await fs.writeFile( await fs.writeFile(
trackInfoPath, trackInfoPath,
`---\n${yaml.safeDump({ `---\n${yaml.safeDump(track)}---\n`
layout: 'track',
...track,
})}---\n`
); );
}) })
); );