From 9abcf06dff2c4f0987433746ce5037eac711b31c Mon Sep 17 00:00:00 2001 From: Johannes Löthberg Date: Tue, 15 Nov 2016 11:31:36 +0100 Subject: build: Add support for unpublished entries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Johannes Löthberg --- build.py | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/build.py b/build.py index a9b328b..60f4510 100644 --- a/build.py +++ b/build.py @@ -46,13 +46,23 @@ def build_archive(jenv, entries): f.write(rendered) -def entry_exists(entry): - path = 'entries/{}.rst'.format(entry['file']) - if not os.path.isfile(path): - print('''Source file '{}' for entry '{}' does not exist. Skipping.''' - .format(path, entry['title'])) - return False - return True +def split_entries(entries): + published = [] + unpublished = [] + + for entry in entries: + path = 'entries/{}.rst'.format(entry['file']) + if not os.path.isfile(path): + print('''Source file '{}' for entry '{}' does not exist. Skipping.''' + .format(path, entry['title'])) + continue + + if entry.get('published', "True") == "True": + published.append(entry) + else: + unpublished.append(entry) + + return (published, unpublished) if __name__ == '__main__': @@ -63,21 +73,24 @@ if __name__ == '__main__': with open('entries.json') as f: entries = json.load(f) - entries = list(filter(entry_exists, entries)) + published, unpublished = split_entries(entries) + + for entry in unpublished: + build_entry(jenv, entry) - for index, entry in enumerate(entries): + for index, entry in enumerate(published): older = None newer = None if index > 0: - older = entries[index-1] - if index < len(entries) - 1: - newer = entries[index+1] + older = published[index-1] + if index < len(published) - 1: + newer = published[index+1] build_entry(jenv, entry, older, newer) - if len(entries) > 1: - build_index(jenv, entries[-1], entries[-2]) + if len(published) > 1: + build_index(jenv, published[-1], published[-2]) else: - build_index(jenv, entries[-1], None) + build_index(jenv, published[-1], None) - build_archive(jenv, entries) + build_archive(jenv, published) -- cgit v1.2.3-70-g09d2