diff --git a/src/jakecharman/__init__.py b/src/jakecharman/__init__.py index 9affc32..bd7c8fa 100644 --- a/src/jakecharman/__init__.py +++ b/src/jakecharman/__init__.py @@ -26,6 +26,8 @@ projects = ContentArea( root_templ='projects.html', post_templ='article.html', name='projects', + title='Projects', + desc='A selection of projects I\'ve been involved in', import_name=__name__ ) @@ -34,6 +36,8 @@ blog = ContentArea( root_templ='blog.html', post_templ='post.html', name='blog', + title='Blog', + desc='Less formal writing, usually something I\'ve been working on that isn\'t worthy of a project write up', import_name=__name__ ) diff --git a/src/jakecharman/content.py b/src/jakecharman/content.py index 1e6a39e..9dc40a6 100755 --- a/src/jakecharman/content.py +++ b/src/jakecharman/content.py @@ -5,12 +5,13 @@ import json from datetime import datetime import frontmatter from markdown import markdown +import readtime from bs4 import BeautifulSoup from flask import render_template, Response, Blueprint from .storage import LocalStorage class ContentArea(Blueprint): - def __init__(self, directory: LocalStorage, root_templ: str, post_templ: str, *args, **kwargs): + def __init__(self, directory: LocalStorage, root_templ: str, post_templ: str, title: str, desc: str, *args, **kwargs): self.md_directory = directory super().__init__(*args, **kwargs) @@ -26,6 +27,8 @@ class ContentArea(Blueprint): self.root_templ = root_templ self.post_templ = post_templ + self.title = title + self.desc = desc def processor(self) -> dict: ''' Jninja processors ''' @@ -34,7 +37,14 @@ class ContentArea(Blueprint): post_soup = BeautifulSoup(html, 'html.parser') all_text = ' '.join([x.get_text() for x in post_soup.findAll('p')]) return ' '.join(all_text.split()[:200]) - return dict(get_excerpt=get_excerpt) + + def get_readtime(post: str) -> str: + return readtime.of_html(post).text + + def get_readtime_mins(post: str) -> int: + return readtime.of_html(post).minutes + + return dict(get_excerpt=get_excerpt, get_readtime=get_readtime, get_readtime_mins=get_readtime_mins) def human_date(self, iso_date: str) -> str: ''' Jninja filter to convert an ISO date to human readable. ''' @@ -87,9 +97,9 @@ class ContentArea(Blueprint): return render_template(self.root_templ, articles=articles_to_return, all_categories=categories, - title='Projects', + title=self.title, page_title='Projects - ', - description='A selection of projects I\'ve been involved in') + description=self.desc) def category(self, category_id: str) -> str: ''' Load the page for a given category ''' diff --git a/src/jakecharman/templates/article.html b/src/jakecharman/templates/article.html index 27d8877..3475519 100755 --- a/src/jakecharman/templates/article.html +++ b/src/jakecharman/templates/article.html @@ -18,6 +18,7 @@ "headline": {{ metadata.title | tojson }}, "datePublished": "{{ metadata.date }}", "image": "https://{{ url }}/image/{{ metadata.image }}", + "timeRequired": "PT{{ get_readtime_mins(post) }}M", "author": { "@type": "Person", "name": "Jake Charman", @@ -42,6 +43,7 @@

{{ metadata.title}}

+

{{ get_readtime(post) }} read

{{ metadata.date | human_date }}


{{post|safe}} diff --git a/src/jakecharman/templates/blog.html b/src/jakecharman/templates/blog.html index 1d40b13..1ce55b9 100755 --- a/src/jakecharman/templates/blog.html +++ b/src/jakecharman/templates/blog.html @@ -14,8 +14,6 @@

{{ title }}

{{ description }}

-

This page is relatively new. I'm adding projects as fast as I can but feel free to contact me if you want to know about something in particular.

-
{% for row in articles %}
{% if row.get('link') is not none %} @@ -44,10 +42,13 @@ {% endif %}

{{ row.title }}

-

{{ row.description }}

{{ row.date | human_date }}

+

{{ get_readtime(row.content) }} read

+
+

{{ get_excerpt(row) }}... Read more

+
{% for category in row.categories %} - {{ all_categories.get(category, {}).get('title', '') }}{{ ", " if not loop.last }} + {{ all_categories.get(category, {}).get('title', '') }}{{ ", " if not loop.last }} {% endfor %}
diff --git a/src/jakecharman/templates/post.html b/src/jakecharman/templates/post.html index 6e8b627..c5b973f 100755 --- a/src/jakecharman/templates/post.html +++ b/src/jakecharman/templates/post.html @@ -17,6 +17,7 @@ "@type": "BlogPosting", "headline": {{ metadata.title | tojson }}, "description": {{ metadata.description | tojson }}, + "timeRequired": "PT{{ get_readtime_mins(post) }}M", "datePublished": "{{ metadata.date }}", {% if metadata.updated %} "dateModified": "{{ metadata.updated }}", @@ -34,9 +35,9 @@ }, "mainEntityOfPage": { "@type": "WebPage", - "@id": "https://{{ url }}/writing/{{ metadata.id }}" + "@id": "https://{{ url }}/blog/{{ metadata.id }}" }, - "url": "https://{{ url }}/writing/{{ metadata.id }}", + "url": "https://{{ url }}/blog/{{ metadata.id }}", "inLanguage": "en-GB" } @@ -56,7 +57,11 @@

{{ metadata.title}}

+

{{ get_readtime(post) }} read

{{ metadata.date | human_date }}

+ {% if metadata.updated %} +

Updated: {{ metadata.updated | human_date }}

+ {% endif %}
{{post|safe}}
diff --git a/src/jakecharman/templates/projects.html b/src/jakecharman/templates/projects.html index 3744c47..a9fcfe9 100755 --- a/src/jakecharman/templates/projects.html +++ b/src/jakecharman/templates/projects.html @@ -47,7 +47,7 @@

{{ row.description }}

{% for category in row.categories %} - + {% endfor %} diff --git a/src/requirements.txt b/src/requirements.txt index d3b3521..9ce025c 100755 --- a/src/requirements.txt +++ b/src/requirements.txt @@ -7,3 +7,4 @@ python-frontmatter>=1.1.0 requests>=2.32.3 pillow>=11.0.0 mod_wsgi>=5.0.2 +readtime>=3.0.0 \ No newline at end of file diff --git a/src/static/style/mobile.css b/src/static/style/mobile.css index 7e52a2b..9c6b0e8 100755 --- a/src/static/style/mobile.css +++ b/src/static/style/mobile.css @@ -339,6 +339,10 @@ pre{ object-fit: cover; } +#blog-main { + padding: 0 10px 0 10px; +} + .blog-post { border: 5px solid #e5e5e5; padding: 10px;