diff --git a/.gitignore b/.gitignore index 047495f..e564153 100755 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ __pycache__ .vscode -.buildinfo.json \ No newline at end of file +.buildinfo.json +*.md \ No newline at end of file diff --git a/src/jakecharman/__init__.py b/src/jakecharman/__init__.py index d6a754b..9affc32 100644 --- a/src/jakecharman/__init__.py +++ b/src/jakecharman/__init__.py @@ -22,11 +22,23 @@ app = Flask(__name__) md_path = path.join(path.realpath(path.dirname(__file__)), path.normpath('../projects/')) projects = ContentArea( - directory=LocalStorage(md_path), + directory=LocalStorage(path.join(md_path, 'projects')), + root_templ='projects.html', + post_templ='article.html', name='projects', - import_name=__name__) + import_name=__name__ + ) + +blog = ContentArea( + directory=LocalStorage(path.join(md_path, 'blog')), + root_templ='blog.html', + post_templ='post.html', + name='blog', + import_name=__name__ + ) app.register_blueprint(projects, url_prefix='/projects') +app.register_blueprint(blog, url_prefix='/blog') app.register_blueprint(ContactForm('contact', __name__), url_prefix='/contact') app.register_blueprint(Links(path.join(md_path, 'links.json'), 'links', __name__), url_prefix='/links') diff --git a/src/jakecharman/content.py b/src/jakecharman/content.py index ce9fb63..1e6a39e 100755 --- a/src/jakecharman/content.py +++ b/src/jakecharman/content.py @@ -10,12 +10,11 @@ from flask import render_template, Response, Blueprint from .storage import LocalStorage class ContentArea(Blueprint): - def __init__(self, directory: LocalStorage, *args, **kwargs): + def __init__(self, directory: LocalStorage, root_templ: str, post_templ: str, *args, **kwargs): self.md_directory = directory super().__init__(*args, **kwargs) - self.add_app_template_filter(self.category_title, 'category_title') self.add_app_template_filter(self.human_date, 'human_date') self.add_app_template_filter(self.to_html, 'to_html') @@ -24,7 +23,9 @@ class ContentArea(Blueprint): self.add_url_rule('/', view_func=self.projects) self.add_url_rule('/category//', view_func=self.category) self.add_url_rule('/', view_func=self.article) - #self.add_url_rule('/image/', view_func=self.image) + + self.root_templ = root_templ + self.post_templ = post_templ def processor(self) -> dict: ''' Jninja processors ''' @@ -35,13 +36,6 @@ class ContentArea(Blueprint): return ' '.join(all_text.split()[:200]) return dict(get_excerpt=get_excerpt) - def category_title(self, category_id: str) -> str: - ''' Jninja filter to get a category title by its ID ''' - with self.md_directory.open('categories.json') as categories_file: - categories = json.load(categories_file) - - return categories.get(category_id).get('title', '') - def human_date(self, iso_date: str) -> str: ''' Jninja filter to convert an ISO date to human readable. ''' try: @@ -90,7 +84,7 @@ class ContentArea(Blueprint): error='There\'s nothing here... yet.', description='I\'m still working on this page. Check back soon for some content.') - return render_template('projects.html', + return render_template(self.root_templ, articles=articles_to_return, all_categories=categories, title='Projects', @@ -123,7 +117,7 @@ class ContentArea(Blueprint): error='There\'s nothing here... yet.', description='I\'m still working on this page. Check back soon for some content.') - return render_template('projects.html', articles=articles_to_return, + return render_template(self.root_templ, articles=articles_to_return, title=the_category['title'], description=the_category['long_description'], page_title=f'{the_category["title"]} - ', @@ -140,6 +134,6 @@ class ContentArea(Blueprint): return Response(status=500) the_article = articles[0] - return render_template('article.html', post=markdown(the_article.content), + return render_template(self.post_templ, post=markdown(the_article.content), metadata=the_article.metadata, page_title=f'{the_article.metadata["title"]} - ') \ No newline at end of file diff --git a/src/jakecharman/templates/blog.html b/src/jakecharman/templates/blog.html new file mode 100755 index 0000000..1d40b13 --- /dev/null +++ b/src/jakecharman/templates/blog.html @@ -0,0 +1,57 @@ +{% extends 'main.html' %} + +{% block content %} +
+ +

{{ 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 %} + + {% else %} + + {% endif %} + {{ row.alt }} + +
+ {% if row.get('link') is not none %} + + {% else %} + + {% endif %} +

{{ row.title }}

+
+

{{ row.description }}

+

{{ row.date | human_date }}

+ {% for category in row.categories %} + {{ all_categories.get(category, {}).get('title', '') }}{{ ", " if not loop.last }} + {% endfor %} +
+
+ {% endfor %} +
+
+{% endblock %} \ No newline at end of file diff --git a/src/jakecharman/templates/main.html b/src/jakecharman/templates/main.html index cfbf3c4..9f0be65 100644 --- a/src/jakecharman/templates/main.html +++ b/src/jakecharman/templates/main.html @@ -59,6 +59,7 @@ diff --git a/src/jakecharman/templates/post.html b/src/jakecharman/templates/post.html new file mode 100755 index 0000000..6e8b627 --- /dev/null +++ b/src/jakecharman/templates/post.html @@ -0,0 +1,64 @@ +{% extends 'main.html' %} +{% block description %}{{ metadata.description }}{% endblock %} +{% block head %} +{% if metadata.gallery %} + +{% endif %} + + +{% endblock %} + +{% block content %} +
+
+

{{ metadata.title}}

+

{{ metadata.date | human_date }}

+
+ {{post|safe}} +
+
+{% endblock %} \ No newline at end of file diff --git a/src/jakecharman/templates/projects.html b/src/jakecharman/templates/projects.html index 7b98fef..3744c47 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/static/js/filter_projects.js b/src/static/js/filter_projects.js index 6d772e0..7624a4b 100755 --- a/src/static/js/filter_projects.js +++ b/src/static/js/filter_projects.js @@ -1,10 +1,11 @@ function update_filter() { + var section = window.location.pathname.split('/')[1] var project_filter = document.getElementById("filter_category"); console.log(project_filter.value) if (project_filter.value == 'all') { - window.location.href = '/projects'; + window.location.href = '/'+section; } else { - window.location.href = '/projects/category/' + project_filter.value; + window.location.href = '/'+section+'/category/' + project_filter.value; } } diff --git a/src/static/style/desktop.css b/src/static/style/desktop.css index a5e8d27..ba5a70a 100755 --- a/src/static/style/desktop.css +++ b/src/static/style/desktop.css @@ -129,4 +129,8 @@ padding: 10px; height: 14vw; } + + .blogpost-thumb { + width: 12.5vw; + } } diff --git a/src/static/style/mobile.css b/src/static/style/mobile.css index e61a69c..7e52a2b 100755 --- a/src/static/style/mobile.css +++ b/src/static/style/mobile.css @@ -337,4 +337,18 @@ pre{ padding: 5px; height: 31vw; object-fit: cover; +} + +.blog-post { + border: 5px solid #e5e5e5; + padding: 10px; + margin: 10px; + border-radius: 15px; + overflow: hidden; +} + +.blogpost-thumb { + float: left; + padding-right: 20px; + width: 25vw; } \ No newline at end of file