diff --git a/.gitignore b/.gitignore index b694934..0e5ac79 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.venv \ No newline at end of file +.venv +__pycache__ \ No newline at end of file diff --git a/common b/common index 50eddb5..faba107 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 50eddb5731ae9ba44513f9d0be7b4885fdff8b9e +Subproject commit faba107ed11c0ffb1965710e602cab9a1342baf0 diff --git a/franca.py b/franca.py index b2ce0c4..5e209dd 100644 --- a/franca.py +++ b/franca.py @@ -10,6 +10,7 @@ import yaml import frontmatter import markdown2 import fire +from PIL import Image from common.functions import * @@ -66,6 +67,9 @@ def develop(prod): # Функция для генерации сайта def crater(prod=False): + # if prod is False, then redefine config.base_url + if prod is False: + config['base_url'] = "http://127.0.0.1:8000" # Load theme's jinja templates templates = Environment(loader=FileSystemLoader( f"themes/{config['theme']}/templates/"), autoescape=select_autoescape()) @@ -118,8 +122,19 @@ def crater(prod=False): image = post_data.get('image', None) if image: - posts[language][section][url]['image'] = image - copy_file(f'assets{image}', f'public{image}') + os.makedirs(os.path.dirname(f'public{image}'), exist_ok=True) + filename = image.split('/')[-1].split('.')[0] + extension = image.split('/')[-1].split('.')[1] + image = Image.open(f'assets{image}') + + image.thumbnail((600, 600)) + image.save(f'public/images/{filename}_600.{extension}', optimize=True) + posts[language][section][url]['image'] = f'/images/{filename}_600.{extension}' + + image.thumbnail((400, 400)) + image.save(f'public/images/{filename}_400.{extension}', optimize=True) + posts[language][section][url]['thumbnail'] = f'/images/{filename}_400.{extension}' + for section, urls in posts[language].items(): if section != "/": @@ -141,7 +156,7 @@ def crater(prod=False): # copy images/css/js from theme shutil.copytree(f"themes/{config['theme']}/static/images", 'public/images', dirs_exist_ok=True) - shutil.copytree(f"themes/{config['theme']}/static/css", 'public/css', dirs_exist_ok=True) + copy_file(f"themes/{config['theme']}/static/css/style.css", 'public/css/') if 'css_includes' in config: for include in config['css_includes']: copy_file(f"themes/{config['theme']}/static/css/{include}", 'public/css/') diff --git a/requirements.txt b/requirements.txt index f930900..82ea9e9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,7 @@ fire==0.5.0 Jinja2==3.1.2 markdown2==2.4.9 MarkupSafe==2.1.3 +Pillow==10.0.0 Pygments==2.15.1 pyinstaller==5.13.0 pyinstaller-hooks-contrib==2023.6