From 05c03eeff2d00ad04536d6e67ccec37ee1636f92 Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Fri, 24 May 2024 18:17:39 +0200 Subject: [PATCH] pages --- TODO.md | 3 ++- compiler.py | 26 +++++++++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/TODO.md b/TODO.md index 4db3286..67b6a60 100644 --- a/TODO.md +++ b/TODO.md @@ -1 +1,2 @@ -- limit articles on index page \ No newline at end of file +- navigating pages +- customizable articles per page \ No newline at end of file diff --git a/compiler.py b/compiler.py index aa1c2f6..6163ec1 100644 --- a/compiler.py +++ b/compiler.py @@ -1,5 +1,5 @@ from json import loads -from os import walk +from os import walk, mkdir from os.path import isdir, join, exists from shutil import copytree from typing import Dict @@ -24,6 +24,10 @@ def compile(work_directory: str, template_directory: str=None, target_directory: copytree(join(template_directory, 'static'), join(target_directory, 'static'), dirs_exist_ok=True) copytree(join(work_directory, 'posts'), join(target_directory, 'post'), dirs_exist_ok=True) + try: + mkdir(join(target_directory, 'index')) + except FileExistsError: + pass file = open(join(work_directory, 'config.json')) site = Site.from_open_file(file) @@ -46,7 +50,19 @@ def compile(work_directory: str, template_directory: str=None, target_directory: articles += [article] - content = template.process_index(*articles) - file = open(join(target_directory, 'index.html'), 'w') - file.write(content) - file.close() \ No newline at end of file + page = 1 + while len(articles) > 0: + if page == 1: + fn = join(target_directory, 'index.html') + else: + fn = join(target_directory, 'index', f'page{page}.html') + + articles_on_page = articles[:10] # TODO make this customizable + content = template.process_index(*articles_on_page) + + file = open(fn, 'w') + file.write(content) + file.close() + + articles = articles[10:] + page += 1 \ No newline at end of file