From 1fb8d9590f286112f790bcd4e29fcfece22c7fb3 Mon Sep 17 00:00:00 2001 From: Bobby Date: Sat, 27 May 2023 01:00:09 -0400 Subject: Update Meta Values in Post --- blog/views.py | 4 ++++ middleware/globalmetamiddleware.py | 1 - templates/blog/partials/base.html | 6 +++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/blog/views.py b/blog/views.py index 4c10af31..0c21f9b6 100644 --- a/blog/views.py +++ b/blog/views.py @@ -136,6 +136,10 @@ def post(request, slug): comment.processed_body = comment_processor(comment.body) if post.is_public: + # modify request.meta description (only text) and image + request.meta['description'] = BeautifulSoup(first_paragraph, 'html.parser').get_text() + request.meta['image'] = 'https://thatcomputerscientist.com/ignis/post_image/720/' + str(post.id) + '.gif' + return render(request, 'blog/post.html', {'title': post.title, 'post': post, 'tags': tags, 'comments': comments}) else: if request.user.is_authenticated and request.user.is_superuser or request.user.is_staff: diff --git a/middleware/globalmetamiddleware.py b/middleware/globalmetamiddleware.py index 4a98dc02..a70efc8c 100644 --- a/middleware/globalmetamiddleware.py +++ b/middleware/globalmetamiddleware.py @@ -7,7 +7,6 @@ class GlobalMetaMiddleware: def __call__(self, request): request.meta = { # Default General Meta Tags - 'title': 'That Computer Scientist', 'description': 'Welcome to the home of That Computer Scientist. I am Kumar Priyansh. This is my personal website where I share all of my thoughts, ideas, and experiences.', 'image': 'https://thatcomputerscientist.com/static/images/logo/logo.png', 'url': '{}://{}{}'.format(request.scheme, request.get_host(), request.path), diff --git a/templates/blog/partials/base.html b/templates/blog/partials/base.html index 81ba98e1..9660a95d 100644 --- a/templates/blog/partials/base.html +++ b/templates/blog/partials/base.html @@ -8,13 +8,13 @@ - - + + - + -- cgit v1.2.3