diff --git a/make-website.py b/make-website.py index 27544a4..cb744e0 100644 --- a/make-website.py +++ b/make-website.py @@ -2,6 +2,7 @@ import datetime import json import re import shutil +import hashlib with open('web/templates/review.html', 'r') as f: REVIEW_TEMPLATE = f.read() @@ -25,7 +26,8 @@ def generate_website(website_source: str, json_source: str, dest: str): website = populate_template_str(website_content, { 'index': generate_index(data['reviews']), 'pesto_ratings': '\n\n'.join(generate_review_html(review) for review in data['reviews']), - 'current_year': str(datetime.date.today().year) + 'current_year': str(datetime.date.today().year), + 'css_hash': stylesheet_hash(), }) with open(dest, 'w') as f: @@ -46,6 +48,7 @@ def generate_review_html(review: dict) -> str: , 'rating_price': review['rating_value']['price'] , 'rating_size': review['rating_value']['size'] , 'rating': review['final_verdict']['string'] + , 'image_items': generate_image_items(review) }) def generate_index(reviews): @@ -60,7 +63,24 @@ def populate_template_str(templatestr, fields: dict[str, str]): return fields.get(match.group(1).lower(), 'Unknown field {}'.format(match.group(1))) return re.sub(r'{([A-Z_]+)}', fill, templatestr) - + +def generate_image_items(review: dict) -> str: + return '\n'.join( + '
'.format(img) + for img in review.get('images', []) + ) + +def stylesheet_hash(): + hash = hashlib.sha256() + with open("web/style.css", 'rb') as f: + while True: + chunk = f.read(hash.block_size) + if not chunk: + break + hash.update(chunk) + return hash.hexdigest() + + if __name__ == '__main__': generate_website('web/templates/index.html', 'reviews.json', 'web/index.html') shutil.copy('reviews.json', 'web/reviews.json') \ No newline at end of file diff --git a/parse-md.py b/parse-md.py index 9afb8e1..e3d4b94 100644 --- a/parse-md.py +++ b/parse-md.py @@ -303,6 +303,11 @@ class ReviewPostprocessor: x.strip() for x in ingredients.rstrip('.').split(',') ] + def images(self, images: str): + return [ + x.strip() for x in images.split(',') + ] + def rating_value(self, table: Dict[str, str]): new = dict() for key, value in table.items(): diff --git a/web/style.css b/web/style.css index 5080524..0048635 100644 --- a/web/style.css +++ b/web/style.css @@ -30,6 +30,7 @@ h1, h2, h3, h4, h5 { p { font-family: 'Times New Roman', Times, serif; + text-align: justify; } header { @@ -49,7 +50,7 @@ header h1 span { .thin { font-weight: 300; } -.final-raiting { +.final-rating { font-size: 2rem; } @@ -63,6 +64,14 @@ footer { width: 90vw; } +footer p { + text-align: left; +} + +footer p:last-child { + text-align: right; +} + table, tr, td, th { border-collapse: collapse; } @@ -107,6 +116,22 @@ body.dark-theme a { color: darkturquoise; } +.image-container { + display: flex; + flex-direction: row; +} + +.image-item { + flex-shrink: 1; + flex-basis: 260px; + margin: 8px; + float: left; +} + +.image-container img { + width: 100%; +} + @media (prefers-color-scheme: dark) { body { --table-border-color: #222; @@ -128,4 +153,8 @@ body.dark-theme a { table { width: 100%; } + + .final-rating { + font-size: 1.5rem; + } } \ No newline at end of file diff --git a/web/templates/index.html b/web/templates/index.html index c153c6e..a598aaf 100644 --- a/web/templates/index.html +++ b/web/templates/index.html @@ -4,7 +4,7 @@ - + Blog of Pesto diff --git a/web/templates/review.html b/web/templates/review.html index 0a0963b..17ad072 100644 --- a/web/templates/review.html +++ b/web/templates/review.html @@ -1,23 +1,28 @@

{TITLE}

+
+
+ {IMAGE_ITEMS} +
-

Date: {DATE}

+

Date: {DATE}

-

Notes: {NOTES}

+

Notes: {NOTES}

-

Ingredients: {INGREDIENTS}

+

Ingredients: {INGREDIENTS}

- - - - - - - - - - -
Category Score / Value
Taste {RATING_TASTE}
Consistency {RATING_CONSISTENCY}
Ingredients {RATING_INGREDIENTS}
Price {RATING_PRICE}
Size {RATING_SIZE}
+ + + + + + + + + + +
Category Score / Value
Taste {RATING_TASTE}
Consistency {RATING_CONSISTENCY}
Ingredients {RATING_INGREDIENTS}
Price {RATING_PRICE}
Size {RATING_SIZE}
-

Final raiting: {RATING}

+

Final rating: {RATING}

-
\ No newline at end of file +
+
\ No newline at end of file