diff --git a/TODO.md b/TODO.md index 59b0029..59de6a1 100644 --- a/TODO.md +++ b/TODO.md @@ -1 +1,3 @@ -- navigating pages \ No newline at end of file +- README & LICENSE +- basic standalone template +- git as part of software \ No newline at end of file diff --git a/article.py b/article.py index 8074bf2..0ab57f6 100644 --- a/article.py +++ b/article.py @@ -56,4 +56,10 @@ class Site: custom[key] = value return Site(custom=custom, **kwargs) - \ No newline at end of file + +@dataclass +class Page: + index: int + last: int + url_previous: str + url_next: str \ No newline at end of file diff --git a/compiler.py b/compiler.py index a2b1a3a..1ea4fc5 100644 --- a/compiler.py +++ b/compiler.py @@ -1,10 +1,11 @@ from json import loads +from math import ceil from os import walk, mkdir from os.path import isdir, join, exists from shutil import copytree from typing import Dict -from article import Article, Site +from article import Article, Page, Site from template import TemplateEnvironment def compile(work_directory: str, template_directory: str=None, target_directory: str=None, force: bool=False): @@ -53,19 +54,26 @@ def compile(work_directory: str, template_directory: str=None, target_directory: articles += [article] - page = 1 + page_index = 1 + pages = ceil(len(articles) / articles_per_page) while len(articles) > 0: - if page == 1: + page = Page( + page_index, pages, + f'/index/page{page_index - 1}.html' if page > 1 else None, + f'/index/page{page_index + 1}.html' if page < pages else None + ) + + if page_index == 1: fn = join(target_directory, 'index.html') else: - fn = join(target_directory, 'index', f'page{page}.html') + fn = join(target_directory, 'index', f'page{page_index}.html') articles_on_page = articles[:articles_per_page] # TODO make this customizable - content = template.process_index(*articles_on_page) + content = template.process_index(page, *articles_on_page) file = open(fn, 'w') file.write(content) file.close() articles = articles[articles_per_page:] - page += 1 \ No newline at end of file + page_index += 1 \ No newline at end of file diff --git a/template.py b/template.py index bdf26e4..0d19736 100644 --- a/template.py +++ b/template.py @@ -1,10 +1,11 @@ -from article import Article, Site from dataclasses import dataclass from io import TextIOWrapper from jinja2 import Environment, Template, FileSystemLoader, select_autoescape from json import loads from os.path import join +from article import Article, Page, Page + TEMPLATE_VERSIONS = [1] @dataclass @@ -55,8 +56,9 @@ class TemplateEnvironment: article = article ) - def process_index(self, *articles: Article) -> str: + def process_index(self, page: Page, *articles: Article) -> str: return self.index_template.render( site = self.site, + page = page, articles = articles ) \ No newline at end of file