Skip to content

Commit

Permalink
Blog improvement: new sidebar template (#148)
Browse files Browse the repository at this point in the history
* Added sidebar template for the blog
* Updated readme
* Dark mode
* Dark mode improvements
  • Loading branch information
zetxek authored Jan 14, 2025
1 parent 190c614 commit 67ad525
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 20 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,18 @@ _(optional, if you want to use the contact form)_ edit line 212 in your `homepag

##### Blog

Two layouts are available for the blog:
- `default` (full-width for posts)
- `sidebar` (sidebar with recent posts and categories)

| Default Layout | Sidebar Layout |
|---------------|----------------|
| ![Default blog layout with full width content](./images/blog-default.jpeg) | ![Blog layout with sidebar showing recent posts](./images/blog-sidebar.jpeg) |
| Full width posts | Posts with left sidebar |
| Clean, focused reading experience | Shows recent posts and categories |
| Maximizes content area | 25% width sidebar by default |
| Best for image-heavy posts | Helps with site navigation |

<img width="1271" alt="image" src="https://github.com/user-attachments/assets/1821a3b7-f572-4958-8c4f-bd1687cc8f71">


Expand All @@ -145,6 +157,8 @@ You can add a menu link to it in `hugo.toml`.

The posts will be markdown files stored in the `content/blog` folder.

The layout can be configured in the `hugo.toml` file, under the `[params.blog]` section.

##### Experience

This functionality and content is especially suited for personal professional sites, showcasing the work experience:
Expand Down
93 changes: 93 additions & 0 deletions assets/scss/_blog.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
.blog {
.has-sidebar {
display: flex;
flex-wrap: wrap;
gap: 2rem;

@media (min-width: 768px) {
flex-wrap: nowrap;
}
}

.col-sidebar {
width: 100%;

@media (min-width: 768px) {
min-width: 250px;
}
}

.blog-sidebar {
position: sticky;
top: 2rem;

.sidebar-section {
margin-bottom: 2rem;
padding: 1.5rem;
background: #edf1f4;
border-radius: 0.5rem;

h3 {
margin-bottom: 1rem;
font-size: 1.2rem;
font-weight: 600;
color: var(--bs-gray-900);
}

ul {
list-style: none;
padding: 0;
margin: 0;

li {
margin-bottom: 0.75rem;

a {
color: var(--bs-gray-700);
text-decoration: none;
transition: color 0.2s ease;

&:hover {
color: var(--bs-primary);
}
}
}
}

&.recent-posts {
.post-date {
display: block;
font-size: 0.875rem;
color: var(--bs-gray-600);
}
}
}
}
}

@include color-mode(dark) {
.blog {
.blog-sidebar {
.sidebar-section {
background: var(--bs-gray-800);

h3 {
color: var(--bs-white);
}

ul li a {
color: black;
}

&.recent-posts {
a{
color: white;
}
.post-date {
color: var(--bs-gray-500);
}
}
}
}
}
}
2 changes: 1 addition & 1 deletion assets/scss/_raditian.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1469,7 +1469,7 @@ ul.tags {
position: relative;
display: inline-block;
padding: 0.4em 1.2em 0.4em 1.6em;
background-color: #f5f5f5;
background-color: white;
color: #333;
font-size: 0.9rem;
border-radius: 0.25rem;
Expand Down
3 changes: 1 addition & 2 deletions assets/scss/adritian.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@import "navbar";
@import "menu";
@import "raditian";
@import "blog";

/** main style **/
.header .navbar-brand span:first-child{
Expand Down Expand Up @@ -207,8 +208,6 @@ footer_links .nav-item .nav-link::after {
}

/* dark mode */
/** Media-query based color switching **/
// $color-mode-type: media-query;
@include color-mode(dark) {

html body, body {
Expand Down
7 changes: 7 additions & 0 deletions exampleSite/hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,10 @@ theme = "adritian-free-hugo-theme"


## by default we allow override AND automatic selection

[params.blog]
layout = "default" # options: default, sidebar
sidebarWidth = "25" # percentage width of the sidebar
showCategories = true
showRecentPosts = true
recentPostCount = 5
Binary file added images/blog-default.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/blog-sidebar.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 24 additions & 17 deletions layouts/blog/list.html
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
<!-- inject:../components/baseHead/baseHeadStart.html -->
<!DOCTYPE html>
<html lang="{{- $.Lang }}">

<head>
{{ partial "head.html" . }} {{ partial "head_custom.html" . }}
{{ partial "head.html" . }}
{{ partial "head_custom.html" . }}
</head>

<body>
{{ partial "header.html" . }}

<main id="main-content" class="blog flex-grow-1">
<section class="container section">
<h1 class="rad-fade-down rad-waiting rad-animate">{{ .Title }}</h1>
<div class="posts-list container">
<!-- Renders the li.html content view for each content/posts/*.md -->
{{ range .Pages }}
<div class="row row--padded rad-animation-group rad-fade-down rad-waiting rad-animate section--border-bottom">
{{ .Render "summary" }}
</div>
<main id="main-content" class="blog flex-grow-1">
<div class="container section">
<div class="row {{ if eq .Site.Params.blog.layout "sidebar" }}has-sidebar{{ end }}">
{{ if eq .Site.Params.blog.layout "sidebar" }}
<div class="col-sidebar" style="width: {{ .Site.Params.blog.sidebarWidth }}%">
{{ partial "blog-sidebar.html" . }}
</div>
{{ end }}

<div class="col-content" {{ if eq .Site.Params.blog.layout "sidebar" }}style="width: calc(100% - {{ .Site.Params.blog.sidebarWidth }}%)"{{ end }}>
<h1 class="rad-fade-down rad-waiting rad-animate">{{ .Title }}</h1>
<div class="posts-list">
{{ range .Pages }}
<div class="row row--padded rad-animation-group rad-fade-down rad-waiting rad-animate section--border-bottom">
{{ .Render "summary" }}
</div>
{{ end }}
</div>
</div>
</div>
</section>
</div>
</main>

{{ partial "footer.html" . }} {{ partial "base-foot.html" . }}
{{ partial "footer.html" . }}
{{ partial "base-foot.html" . }}
</body>

</html>
<!-- endinject -->
</html>
30 changes: 30 additions & 0 deletions layouts/partials/blog-sidebar.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<aside class="blog-sidebar">
{{ if .Site.Params.blog.showCategories }}
<div class="sidebar-section categories">
<h3>{{ i18n "categories" | default "Categories" }}</h3>
{{ if .Site.Taxonomies.tags }}
<ul class="tags">
{{ range $name, $taxonomy := .Site.Taxonomies.tags }}
<li>
<a href="{{ "/tags/" | relLangURL }}{{ $name | urlize }}">{{ $name }}</a>
</li>
{{ end }}
</ul>
{{ end }}
</div>
{{ end }}

{{ if .Site.Params.blog.showRecentPosts }}
<div class="sidebar-section recent-posts">
<h3>{{ i18n "recent_posts" | default "Recent Posts" }}</h3>
<ul>
{{ range first .Site.Params.blog.recentPostCount (where .Site.RegularPages "Type" "blog") }}
<li>
<a href="{{ .RelPermalink }}">{{ .Title }}</a>
<span class="post-date">{{ .Date.Format "Jan 2, 2006" }}</span>
</li>
{{ end }}
</ul>
</div>
{{ end }}
</aside>

0 comments on commit 67ad525

Please sign in to comment.