diff --git a/nova.py b/nova.py index fdcd350..b95bd8d 100755 --- a/nova.py +++ b/nova.py @@ -22,10 +22,11 @@ def gen_name(date, slug): class EpisodeList(UserList): "Represents list of episodes" - def __init__(self, data, output, template): + def __init__(self, data, output, template, archives): super().__init__(data) self.output = output self.template = template + self.archives = archives def sort(self, *_args, **_kwargs): "Sorts the EpisodeList" @@ -45,6 +46,15 @@ class EpisodeList(UserList): def generate_atom(self): "Generates the Atom feed" + def generate_archives(self): + "Generates archives page" + with open(self.output + "archives.html", "w") as file: + episodes = [{ + "slug": gen_name(i.date, i.slug) + ".html", + "title": i.title + } for i in self.data] + file.write(self.archives.render(episodes=episodes)) + def generate_site(self, root): "Generates the entire site" # Generate CSS from SCSS @@ -119,20 +129,30 @@ def main(): output_dir = args.output_dir.rstrip("/") + "/" # Input validation - if not all(path.isdir(i) for i in (input_dir, input_dir + "md", - input_dir + "videos")): + paths = [ + input_dir, + input_dir + "md", + input_dir + "videos", + input_dir + "audios", + ] + if not all(path.isdir(i) for i in paths): print("Invalid Input", file=sys.stderr) return if not path.isdir(args.output_dir): os.mkdir(args.output_dir) - template = jinja2.Environment( + env = jinja2.Environment( loader=jinja2.FileSystemLoader(root), autoescape=jinja2.select_autoescape("html") - ).get_template("index.html") + ) - podcast = EpisodeList([], output_dir, template) + podcast = EpisodeList( + [], + output_dir, + env.get_template("index.html"), + env.get_template("archives.html") + ) split = re.compile(r"((?P\d{4}-[01]?\d-[0123]?\d)-(?P.*).md)") for file in os.listdir(input_dir + "md"): @@ -145,12 +165,20 @@ def main(): with open(input_dir + "md/" + file) as episode: title = episode.readline() show_notes = episode.read() - video = input_dir + "videos/" + gen_name(date, slug) + ".mp4" - audio = input_dir + "audios/" + gen_name(date, slug) + ".mp3" - podcast.append(Episode(date, slug, title, show_notes, video, audio)) + podcast.append( + Episode( + date, + slug, + title, + show_notes, + input_dir + "videos/" + gen_name(date, slug) + ".mp4", + input_dir + "audios/" + gen_name(date, slug) + ".mp3" + ) + ) podcast.sort() podcast.generate_thumbnails() + podcast.generate_archives() podcast.generate_atom() podcast.generate_site(root)