This commit is contained in:
Minecon724 2024-05-24 18:17:39 +02:00
parent 76851fa48d
commit 05c03eeff2
2 changed files with 23 additions and 6 deletions

View file

@ -1 +1,2 @@
- limit articles on index page
- navigating pages
- customizable articles per page

View file

@ -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')
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