eleventy-plugin-podcaster 2.0.0-alpha.0 → 2.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -21,35 +21,38 @@ export default function (eleventyConfig) {
|
|
|
21
21
|
if (!existsSync(episodesDir)) return
|
|
22
22
|
|
|
23
23
|
const episodes = await readdir(episodesDir)
|
|
24
|
-
const
|
|
25
|
-
let
|
|
24
|
+
const episodeData = {}
|
|
25
|
+
let numberOfEpisodes = 0
|
|
26
26
|
let totalSize = 0
|
|
27
27
|
let totalDuration = 0
|
|
28
28
|
|
|
29
29
|
for (const episode of episodes) {
|
|
30
30
|
if (!episode.endsWith('.mp3')) continue
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
numberOfEpisodes++
|
|
33
33
|
const episodePath = path.join(episodesDir, episode)
|
|
34
34
|
const episodeSize = (await stat(episodePath)).size
|
|
35
35
|
totalSize += episodeSize
|
|
36
36
|
const episodeMetadata = await parseFile(episodePath, { duration: true })
|
|
37
37
|
const episodeDuration = episodeMetadata.format.duration
|
|
38
38
|
totalDuration += episodeDuration
|
|
39
|
-
|
|
39
|
+
episodeData[episode] = {
|
|
40
40
|
size: episodeSize,
|
|
41
|
-
duration: episodeDuration
|
|
41
|
+
duration: Math.round(episodeDuration * 1000) / 1000
|
|
42
42
|
}
|
|
43
|
+
totalDuration = Math.round(totalDuration * 1000) / 1000
|
|
43
44
|
}
|
|
45
|
+
const podcastData = { numberOfEpisodes, totalSize, totalDuration }
|
|
44
46
|
|
|
45
47
|
const dataDir = path.join(process.cwd(), directories.data)
|
|
46
|
-
await writeFile(path.join(dataDir, 'episodeData.json'), JSON.stringify(
|
|
48
|
+
await writeFile(path.join(dataDir, 'episodeData.json'), JSON.stringify(episodeData, null, 2))
|
|
49
|
+
await writeFile(path.join(dataDir, 'podcastData.json'), JSON.stringify(podcastData, null, 2))
|
|
47
50
|
|
|
48
|
-
console.log(chalk.yellow(`${
|
|
51
|
+
console.log(chalk.yellow(`${numberOfEpisodes} episodes; ${hr.fromBytes(totalSize)}; ${convertSecondsToReadableDuration(totalDuration)}.`))
|
|
49
52
|
})
|
|
50
53
|
|
|
51
54
|
const filenameSeasonAndEpisodePattern =
|
|
52
|
-
/^.*?\b[sS](?<seasonNumber>\d+)[eE](?<episodeNumber>\d+)\b.*\.mp3$/
|
|
55
|
+
/^.*?\b[sS](?<seasonNumber>\d+)\s*[eE](?<episodeNumber>\d+)\b.*\.mp3$/
|
|
53
56
|
const filenameEpisodePattern = /^.*?\b(?<episodeNumber>\d+)\b.*\.mp3$/
|
|
54
57
|
|
|
55
58
|
eleventyConfig.addGlobalData('eleventyComputed.episode.filename', () => {
|
package/src/readableFilters.js
CHANGED
|
@@ -13,12 +13,17 @@ export default function (eleventyConfig, options = {}) {
|
|
|
13
13
|
return result.setLocale(readableDateLocale).toLocaleString(DateTime.DATE_HUGE)
|
|
14
14
|
})
|
|
15
15
|
|
|
16
|
-
eleventyConfig.addFilter('readableDuration', (seconds) => {
|
|
16
|
+
eleventyConfig.addFilter('readableDuration', (seconds, length) => {
|
|
17
17
|
if (!seconds) return '0:00:00'
|
|
18
|
-
if (
|
|
18
|
+
if (length === 'long') {
|
|
19
|
+
return Duration.fromMillis(seconds * 1000)
|
|
20
|
+
.shiftTo('days', 'hours', 'minutes', 'seconds')
|
|
21
|
+
.toHuman()
|
|
22
|
+
} else if (seconds < 60 * 60) {
|
|
19
23
|
return Duration.fromMillis(seconds * 1000).toFormat('mm:ss')
|
|
24
|
+
} else {
|
|
25
|
+
return Duration.fromMillis(seconds * 1000).toFormat('h:mm:ss')
|
|
20
26
|
}
|
|
21
|
-
return Duration.fromMillis(seconds * 1000).toFormat('h:mm:ss')
|
|
22
27
|
})
|
|
23
28
|
|
|
24
29
|
eleventyConfig.addFilter('readableSize', (bytes, fixedPrecision = 1) =>
|