You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
from glob import glob
|
|
import os
|
|
from shutil import copy2
|
|
import frontmatter
|
|
from pathlib import Path
|
|
from PIL import Image
|
|
|
|
|
|
|
|
# from frontmatter import frontmatter
|
|
for folder in glob('projects/*'):
|
|
project = folder.replace('projects/', '')
|
|
with open(os.path.join(folder,project+'.md'), 'r') as f:
|
|
meta, content = frontmatter.parse(f.read())
|
|
if 'cover' in meta:
|
|
cover = meta.get('cover')
|
|
file = Path(f'static/img2/{cover}')
|
|
if file.is_file():
|
|
try:
|
|
with Image.open(file) as img:
|
|
print(f'Ok im copying {cover} to {project}')
|
|
f, e = os.path.splitext(cover)
|
|
img.save(os.path.join(folder, f + '.jpg'))
|
|
img.convert('RGB')
|
|
img.thumbnail((256,256))
|
|
img.save(os.path.join(folder, 'thumb_' + cover), 'JPEG')
|
|
except:
|
|
print(f"Couldn't convert {cover}")
|