diff --git a/src/bulk_page.py b/src/bulk_page.py index ace1dc5..255183c 100644 --- a/src/bulk_page.py +++ b/src/bulk_page.py @@ -1,7 +1,7 @@ from __future__ import annotations from jinja2 import Environment, FileSystemLoader -import markdown +import photodown import os from path import Path @@ -51,7 +51,7 @@ class BulkPage(): text = f.read() if len(text) == 0: return None - html = markdown.markdown(text) + html = photodown.markdown(text) return html def _gen_exif(self): diff --git a/src/main.py b/src/main.py index ea68e27..4644f6f 100644 --- a/src/main.py +++ b/src/main.py @@ -1,5 +1,3 @@ -import sys -import os from progress.bar import Bar from path import Path @@ -7,6 +5,7 @@ from picture import Picture from bulk_page import BulkPage from bulk_category import BulkCategory from page import Page +from photodown import Photodown import argparse import config @@ -80,12 +79,18 @@ def create_categories(categories: list[BulkCategory]) -> None: category.create() bar.next() -def gen_bulk(bulk_path: Path): +def gen_bulk(bulk_path: Path, markdown: Photodown): category_path: Path = Path(bulk_path, "categories") pages: list[BulkPage] = scan_bulk_pages(bulk_path.get_dirs()) categories: list[BulkCategory] = scan_categories(pages, category_path) + bulk: list[Picture] = [] + for page in pages: + for picture in page.get_pictures(): + bulk.append(picture) + markdown.add_bulk(bulk) + if config.CREATE_GENERAL_CATEGORY: for category in categories: if (category.name == "general"): @@ -99,13 +104,13 @@ def gen_bulk(bulk_path: Path): category_path.create() create_categories(categories) -def scan_pages(site_path: Path): +def scan_pages(site_path: Path, markdown: Photodown): for path in [f for f in site_path.get_files() if f.get_name().endswith(config.PAGE_EXT)]: - page: Page = Page(path) + page: Page = Page(path, markdown) page.create() -def gen_pages(site_path: Path): - scan_pages(site_path) +def gen_pages(site_path: Path, markdown: Photodown): + scan_pages(site_path, markdown) def regen(bulk_path: Path, is_thumb: bool, is_small: bool): pages: list[BulkPage] = scan_bulk_pages(bulk_path.get_dirs()) @@ -132,8 +137,9 @@ def main(): bulk_path: Path = Path(site_path, "bulk/") if args.regen is not None: regen(bulk_path, 't' in args.regen, 's' in args.regen) - gen_bulk(bulk_path) - gen_pages(site_path) + markdown = Photodown() + gen_bulk(bulk_path, markdown) + gen_pages(site_path, markdown) gen_home(site_path) diff --git a/src/page.py b/src/page.py index a41429f..bba23bb 100644 --- a/src/page.py +++ b/src/page.py @@ -3,20 +3,21 @@ from __future__ import annotations from typing import TYPE_CHECKING import config -import bozodown from path import Path - +if TYPE_CHECKING: + from photodown import Photodown class Page: - def __init__(self, path: Path): + def __init__(self, path: Path, markdown: Photodown): self._path: Path = path self._html: Path = Path(self._path.get_absolute_path()[:-len(config.PAGE_EXT)] + ".html") + self._markdown: Photodown = markdown with open(path.get_absolute_path(), "r") as f: self._raw_content: str = f.read() def _get_content(self): - content = bozodown.render(self._raw_content) + content = self._markdown.render(self._raw_content) return content def _to_html(self) -> str: diff --git a/src/photodown.py b/src/photodown.py index aaac921..f2faeec 100644 --- a/src/photodown.py +++ b/src/photodown.py @@ -23,6 +23,9 @@ class Photodown(Bozodown): def _photohub_render(self, id: str, text: str) -> str: if (id == "image"): picture_url = f"{text[2:-1]}" - + if (picture_url.startswith("./")): + for picture in self._bulk: + if picture_url == "." + picture.get_large().get_url()[:-4]: + return f"""""" return f""