From 4ad7f73c7f04609a57fb322f652fbf4d6edd0241 Mon Sep 17 00:00:00 2001 From: Doge Date: Sat, 15 May 2021 17:35:35 +0800 Subject: Add chapters to web-player support --- layout/_partial/scripts.ejs | 5 +++++ layout/post.ejs | 29 ++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) (limited to 'layout') diff --git a/layout/_partial/scripts.ejs b/layout/_partial/scripts.ejs index da0a8a1..2efb659 100644 --- a/layout/_partial/scripts.ejs +++ b/layout/_partial/scripts.ejs @@ -41,6 +41,11 @@ <% if (is_post() && theme.podcast && page.podcast) { %> + <% if (page.podcast.chapters) { %> + + + <% } %> <% } %> diff --git a/layout/post.ejs b/layout/post.ejs index 1e75de4..a9b1f8a 100644 --- a/layout/post.ejs +++ b/layout/post.ejs @@ -17,16 +17,43 @@ <%= page.title %> <% if (page.podcast) { %> +
+ <% if (page.podcast.chapters) { %> + <% + let final = page.podcast.duration; + let timestamps = []; + let data = page.podcast.chapters; + let chapters = []; + (data).forEach((chapter) => { + timestamps.push(chapter[1]); + }); + timestamps.push(final); + for (let index = 0; index < timestamps.length - 1; index++) { + let start = timestamps[index]; + let end = timestamps[index + 1]; + chapters.push({ + title: data[index][0], + startTime: start, endTime: end + }); + }; + %> + + <% } %>