aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBobby <[email protected]>2023-05-27 01:00:09 -0400
committerBobby <[email protected]>2023-05-27 01:00:09 -0400
commit1fb8d9590f286112f790bcd4e29fcfece22c7fb3 (patch)
tree14383e7a89f63e511ce4d07e78705e9c2435f8bb
parent9cbdfa382757c263974a4c3bc0238fed03f2cce0 (diff)
downloadthatcomputerscientist-1fb8d9590f286112f790bcd4e29fcfece22c7fb3.tar.xz
thatcomputerscientist-1fb8d9590f286112f790bcd4e29fcfece22c7fb3.zip
Update Meta Values in Post
-rw-r--r--blog/views.py4
-rw-r--r--middleware/globalmetamiddleware.py1
-rw-r--r--templates/blog/partials/base.html6
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 @@
<meta name="description" content="{{ request.meta.description }}" />
<meta name="image" content="{{ request.meta.image }}" />
<meta name="url" content="{{ request.meta.url }}" />
- <meta name="title" content="{{ request.meta.title }}" />
- <meta property="og:title" content="{{ request.meta.title }}" />
+ <meta name="title" content="That Computer Scientist - {{ title }}" />
+ <meta property="og:title" content="That Computer Scientist - {{ title }}" />
<meta property="og:description" content="{{ request.meta.description }}" />
<meta property="og:image" content="{{ request.meta.image }}" />
<meta property="og:url" content="{{ request.meta.url }}" />
<meta name="twitter:card" content="summary_large_image" />
- <meta name="twitter:title" content="{{ request.meta.title }}" />
+ <meta name="twitter:title" content="That Computer Scientist - {{ title }}" />
<meta name="twitter:description" content="{{ request.meta.description }}" />
<meta name="twitter:image" content="{{ request.meta.image }}" />
<meta name="robots" content="{{ request.meta.robots }}" />