pages
This commit is contained in:
parent
76851fa48d
commit
05c03eeff2
2 changed files with 23 additions and 6 deletions
3
TODO.md
3
TODO.md
|
@ -1 +1,2 @@
|
||||||
- limit articles on index page
|
- navigating pages
|
||||||
|
- customizable articles per page
|
22
compiler.py
22
compiler.py
|
@ -1,5 +1,5 @@
|
||||||
from json import loads
|
from json import loads
|
||||||
from os import walk
|
from os import walk, mkdir
|
||||||
from os.path import isdir, join, exists
|
from os.path import isdir, join, exists
|
||||||
from shutil import copytree
|
from shutil import copytree
|
||||||
from typing import Dict
|
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(template_directory, 'static'), join(target_directory, 'static'), dirs_exist_ok=True)
|
||||||
copytree(join(work_directory, 'posts'), join(target_directory, 'post'), 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'))
|
file = open(join(work_directory, 'config.json'))
|
||||||
site = Site.from_open_file(file)
|
site = Site.from_open_file(file)
|
||||||
|
@ -46,7 +50,19 @@ def compile(work_directory: str, template_directory: str=None, target_directory:
|
||||||
|
|
||||||
articles += [article]
|
articles += [article]
|
||||||
|
|
||||||
content = template.process_index(*articles)
|
page = 1
|
||||||
file = open(join(target_directory, 'index.html'), 'w')
|
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.write(content)
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
|
articles = articles[10:]
|
||||||
|
page += 1
|
Reference in a new issue