Add image resize
This commit is contained in:
parent
3c5e1cc3c8
commit
42cf006f4f
|
@ -1 +1,2 @@
|
|||
.venv
|
||||
__pycache__
|
2
common
2
common
|
@ -1 +1 @@
|
|||
Subproject commit 50eddb5731ae9ba44513f9d0be7b4885fdff8b9e
|
||||
Subproject commit faba107ed11c0ffb1965710e602cab9a1342baf0
|
21
franca.py
21
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/')
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue