add: use photodown to gen page
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from jinja2 import Environment, FileSystemLoader
|
from jinja2 import Environment, FileSystemLoader
|
||||||
import markdown
|
import photodown
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from path import Path
|
from path import Path
|
||||||
@ -51,7 +51,7 @@ class BulkPage():
|
|||||||
text = f.read()
|
text = f.read()
|
||||||
if len(text) == 0:
|
if len(text) == 0:
|
||||||
return None
|
return None
|
||||||
html = markdown.markdown(text)
|
html = photodown.markdown(text)
|
||||||
return html
|
return html
|
||||||
|
|
||||||
def _gen_exif(self):
|
def _gen_exif(self):
|
||||||
|
24
src/main.py
24
src/main.py
@ -1,5 +1,3 @@
|
|||||||
import sys
|
|
||||||
import os
|
|
||||||
from progress.bar import Bar
|
from progress.bar import Bar
|
||||||
|
|
||||||
from path import Path
|
from path import Path
|
||||||
@ -7,6 +5,7 @@ from picture import Picture
|
|||||||
from bulk_page import BulkPage
|
from bulk_page import BulkPage
|
||||||
from bulk_category import BulkCategory
|
from bulk_category import BulkCategory
|
||||||
from page import Page
|
from page import Page
|
||||||
|
from photodown import Photodown
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import config
|
import config
|
||||||
@ -80,12 +79,18 @@ def create_categories(categories: list[BulkCategory]) -> None:
|
|||||||
category.create()
|
category.create()
|
||||||
bar.next()
|
bar.next()
|
||||||
|
|
||||||
def gen_bulk(bulk_path: Path):
|
def gen_bulk(bulk_path: Path, markdown: Photodown):
|
||||||
category_path: Path = Path(bulk_path, "categories")
|
category_path: Path = Path(bulk_path, "categories")
|
||||||
|
|
||||||
pages: list[BulkPage] = scan_bulk_pages(bulk_path.get_dirs())
|
pages: list[BulkPage] = scan_bulk_pages(bulk_path.get_dirs())
|
||||||
categories: list[BulkCategory] = scan_categories(pages, category_path)
|
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:
|
if config.CREATE_GENERAL_CATEGORY:
|
||||||
for category in categories:
|
for category in categories:
|
||||||
if (category.name == "general"):
|
if (category.name == "general"):
|
||||||
@ -99,13 +104,13 @@ def gen_bulk(bulk_path: Path):
|
|||||||
category_path.create()
|
category_path.create()
|
||||||
create_categories(categories)
|
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)]:
|
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()
|
page.create()
|
||||||
|
|
||||||
def gen_pages(site_path: Path):
|
def gen_pages(site_path: Path, markdown: Photodown):
|
||||||
scan_pages(site_path)
|
scan_pages(site_path, markdown)
|
||||||
|
|
||||||
def regen(bulk_path: Path, is_thumb: bool, is_small: bool):
|
def regen(bulk_path: Path, is_thumb: bool, is_small: bool):
|
||||||
pages: list[BulkPage] = scan_bulk_pages(bulk_path.get_dirs())
|
pages: list[BulkPage] = scan_bulk_pages(bulk_path.get_dirs())
|
||||||
@ -132,8 +137,9 @@ def main():
|
|||||||
bulk_path: Path = Path(site_path, "bulk/")
|
bulk_path: Path = Path(site_path, "bulk/")
|
||||||
if args.regen is not None:
|
if args.regen is not None:
|
||||||
regen(bulk_path, 't' in args.regen, 's' in args.regen)
|
regen(bulk_path, 't' in args.regen, 's' in args.regen)
|
||||||
gen_bulk(bulk_path)
|
markdown = Photodown()
|
||||||
gen_pages(site_path)
|
gen_bulk(bulk_path, markdown)
|
||||||
|
gen_pages(site_path, markdown)
|
||||||
gen_home(site_path)
|
gen_home(site_path)
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,20 +3,21 @@ from __future__ import annotations
|
|||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
import config
|
import config
|
||||||
import bozodown
|
|
||||||
from path import Path
|
from path import Path
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from photodown import Photodown
|
||||||
class Page:
|
class Page:
|
||||||
|
|
||||||
def __init__(self, path: Path):
|
def __init__(self, path: Path, markdown: Photodown):
|
||||||
self._path: Path = path
|
self._path: Path = path
|
||||||
self._html: Path = Path(self._path.get_absolute_path()[:-len(config.PAGE_EXT)] + ".html")
|
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:
|
with open(path.get_absolute_path(), "r") as f:
|
||||||
self._raw_content: str = f.read()
|
self._raw_content: str = f.read()
|
||||||
|
|
||||||
def _get_content(self):
|
def _get_content(self):
|
||||||
content = bozodown.render(self._raw_content)
|
content = self._markdown.render(self._raw_content)
|
||||||
return content
|
return content
|
||||||
|
|
||||||
def _to_html(self) -> str:
|
def _to_html(self) -> str:
|
||||||
|
@ -23,6 +23,9 @@ class Photodown(Bozodown):
|
|||||||
def _photohub_render(self, id: str, text: str) -> str:
|
def _photohub_render(self, id: str, text: str) -> str:
|
||||||
if (id == "image"):
|
if (id == "image"):
|
||||||
picture_url = f"{text[2:-1]}"
|
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"""<a href={picture.get_page().html.get_url()}><img src='{picture.get_small().get_url()}'></a>"""
|
||||||
return f"<img src='{picture_url}'>"
|
return f"<img src='{picture_url}'>"
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user