Skip to content

Commit

Permalink
optional description for blog posts (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
alidevjimmy authored Oct 4, 2024
1 parent 82e0f35 commit 3f297ff
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 11 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ image = "/images/pic.jpg"

Make sure to fill all the fields carefully as they are important for SEO and user-friendly URLs.\
After creating the file, you can start writing your blog post.\
You can see your blog post in `http://localhost:1313/blog/your-post-slug`
You can see your blog post in `http://localhost:1313/blog/your-post-slug` \
**Note that description field is optional**

### Images

Expand Down
2 changes: 1 addition & 1 deletion layouts/_default/single-baseof.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- layouts/index.html -->
<!doctype html>
<html lang="en" data-theme="dark">
{{ partial "signle-head.html" . }}
{{ partial "single-head.html" . }}


<body class="bg-[#0B0B0F] flex flex-col min-h-screen">
Expand Down
2 changes: 1 addition & 1 deletion layouts/blog/index-baseof.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- layouts/index.html -->
<!doctype html>
<html lang="en" data-theme="dark">
{{ partial "signle-head.html" . }}
{{ partial "single-head.html" . }}


<body class="bg-[#0B0B0F] flex flex-col min-h-screen">
Expand Down
8 changes: 3 additions & 5 deletions layouts/blog/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class="container mx-auto px-4 py-8 pt-[8rem] md:pt-[10rem] relative z-20 flex-grow pb-20 flex flex-col min-h-full">
{{ $latestPost := index (.Pages.ByDate.Reverse) 0 }}
{{ $image := resources.Get $latestPost.Params.image }}
{{ $resized := $image.Resize "800x webp q60" }}
{{ $resized := $image.Resize "1000x webp q70" }}
<a href="{{ $latestPost.Permalink }}"
class="relative w-full min-h-[300px] h-auto rounded-xl block fill-neutral-content">
<div class="absolute inset-0 bg-cover bg-top bg-no-repeat rounded-xl"
Expand All @@ -19,8 +19,7 @@ <h1 class="rounded-xl inline-block text-neutral-50 font-bold text-3xl">
</div>
<div class="mt-3 block">
<p class="rounded-xl inline-block text-neutral-50 font-light text-lg">
{{ $summary := $latestPost.Params.description | plainify | truncate 300 " ..." }}
{{ $summary }}
{{ partial "desc.html" (dict "description" $latestPost.Params.description "summary" $latestPost.Content "charCount" 300)}}
</p>
</div>
<div class="mt-5 flex">
Expand Down Expand Up @@ -50,8 +49,7 @@ <h1 class="text-neutral-50 font-bold text-xl hover:text-[#7064e9]">
{{ .Title }}
</h1>
</a>
{{ $summary := .Params.description | plainify | truncate 150 " ..." }}
<p class="text-sm mt-2">{{ $summary }}</p>
<p class="text-sm mt-2">{{ partial "desc.html" (dict "description" .Params.description "summary" .Content "charCount" 150)}}</p>
</div>
<div class="block mt-8">
<h1 class="text-[#97989F] font-medium text-sm">
Expand Down
2 changes: 1 addition & 1 deletion layouts/blog/single-baseof.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- layouts/index.html -->
<!doctype html>
<html lang="en" data-theme="dark">
{{ partial "signle-head.html" . }}
{{ partial "single-head.html" . }}


<body class="bg-[#0B0B0F] flex flex-col min-h-screen">
Expand Down
3 changes: 1 addition & 2 deletions layouts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,7 @@ <h6 class="font-medium text-sm mt-2">
{{ .Date.Format "January 2, 2006" }}
</h6>
<p class="mt-5 text-neutral-50">
{{ $summary := .Params.description | plainify | truncate 300 " ..." }}
{{ $summary }}
{{ partial "desc.html" (dict "description" .Params.description "summary" .Content "charCount" 150)}}
<br /><br />
<a href="{{ .Permalink }}" class="hover:text-opacity-80 font-bold text-[#1EA4E8]">Read
More</a>
Expand Down
6 changes: 6 additions & 0 deletions layouts/partials/desc.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{if .description}}
{{.description | plainify | truncate .charCount " ..." | safeHTML}}
{{else}}
{{ $summary := findRE "(?s)<p.*?>.*?</p>" .summary }}
{{ delimit $summary " " | plainify | truncate .charCount " ..." | safeHTML }}
{{end}}
File renamed without changes.

0 comments on commit 3f297ff

Please sign in to comment.