Skip to content

Commit 395dfa2

Browse files
authored
fix: css and navigation fixes. reorganize posts (#88)
* add additional tags to posts * fix tags color and add prev and next post title * fix: code color * remove bio * reorganize posts
1 parent dbd4514 commit 395dfa2

11 files changed

+142
-67
lines changed

src/components/Bio.astro

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/content.config.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,20 @@ import { defineCollection, z } from "astro:content";
22
import { glob } from "astro/loaders";
33

44
const posts = defineCollection({
5-
loader: glob({ pattern: "*.md", base: "./posts" }),
5+
loader: glob({ pattern: "*.md", base: "./src/posts" }),
6+
// schema: z.object({
7+
// title: z.string(),
8+
// slug: z.string(),
9+
// publishDate: z.union([z.string(), z.date()]),
10+
// description: z.string(),
11+
// tags: z.array(z.string()),
12+
// nextPost: z.string().optional(),
13+
// prevPost: z.string().optional(),
14+
// }),
15+
});
16+
17+
const data = defineCollection({
18+
loader: glob({pattern: "*.json", base: "./src/posts"}),
619
schema: z.object({
720
title: z.string(),
821
slug: z.string(),
@@ -14,4 +27,6 @@ const posts = defineCollection({
1427
}),
1528
});
1629

17-
export const collections = { posts };
30+
31+
32+
export const collections = { posts, data };

src/pages/blog/[slug].astro

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,51 @@
11
---
2-
import { getCollection, render } from "astro:content";
2+
import { getCollection, getEntry, render } from "astro:content";
33
import readingTime from "reading-time";
44
import BaseLayout from "../../layouts/BaseLayout.astro";
5-
import Bio from "../../components/Bio.astro";
65
76
export async function getStaticPaths() {
8-
const posts = await getCollection("posts");
9-
return posts.map((p) => ({
10-
params: { slug: p.data.slug },
11-
props: { post: p },
12-
}));
7+
const data = await getCollection("data");
8+
9+
return await Promise.all(
10+
data.map(async (d) => {
11+
const post = await getEntry("posts", d.id);
12+
13+
return {
14+
params: { slug: d.data.slug },
15+
props: { post: post, data: d.data },
16+
};
17+
}),
18+
);
1319
}
1420
15-
const { post } = Astro.props;
16-
const { title, slug, description, publishDate } = post.data;
21+
async function getPostTitleFromId(id) {
22+
try {
23+
if (!id) return null;
24+
const post = await getEntry("posts", id);
25+
return post.data.title;
26+
} catch (e) {
27+
return null;
28+
}
29+
}
30+
31+
const { post, data } = Astro.props;
32+
const { title, slug, description, publishDate, tags, prevPost, nextPost } =
33+
data;
34+
console.log({
35+
title,
36+
slug,
37+
description,
38+
publishDate,
39+
tags,
40+
prevPost,
41+
nextPost,
42+
});
1743
const readingTimeEstimate = readingTime(post.body).text;
1844
const permalink = `${Astro.site.href}blog/${slug}`;
45+
46+
const prevPostTitle = await getPostTitleFromId(prevPost);
47+
const nextPostTitle = await getPostTitleFromId(nextPost);
48+
1949
const { Content } = await render(post);
2050
---
2151

@@ -35,20 +65,25 @@ const { Content } = await render(post);
3565
<Content />
3666
</article>
3767
<hr />
38-
<Bio />
68+
69+
<div class="tags">
70+
{tags.map((tag) => <span>{tag}</span>)}
71+
</div>
3972

4073
<div class="post-navigation">
4174
<div>
4275
{
43-
post.data.prevPost && (
44-
<a href={`/blog/${post.data.prevPost}`}>Previous post</a>
76+
prevPost && (
77+
<a href={`/blog/${prevPost}`}>
78+
&larr; {prevPostTitle || "Previous"}
79+
</a>
4580
)
4681
}
4782
</div>
4883
<div>
4984
{
50-
post.data.nextPost && (
51-
<a href={`/blog/${post.data.nextPost}`}>Next post</a>
85+
nextPost && (
86+
<a href={`/blog/${nextPost}`}>{nextPostTitle || "Next"} &rarr;</a>
5287
)
5388
}
5489
</div>
@@ -83,4 +118,17 @@ const { Content } = await render(post);
83118
justify-content: space-between;
84119
align-items: center;
85120
}
121+
122+
.tags {
123+
display: flex;
124+
flex-wrap: wrap;
125+
gap: 8px;
126+
}
127+
128+
.tags span {
129+
padding: 2px 6px;
130+
border-radius: 3px;
131+
background-color: var(--tag-bg-color);
132+
color: var(--tag-color);
133+
}
86134
</style>

src/pages/blog/index.astro

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const title = "Blog - Pijush Barik";
66
const description = "Blog posts from Pijush";
77
const permalink = `${Astro.site.href}blog`;
88
9-
let allPosts = await getCollection("posts");
9+
let allPosts = await getCollection("data");
1010
allPosts = allPosts.sort(
1111
(a, b) =>
1212
new Date(b.data.publishDate).valueOf() -
@@ -66,13 +66,16 @@ allPosts = allPosts.sort(
6666

6767
.post-item-tags {
6868
display: flex;
69-
gap: 14px;
69+
flex-wrap: wrap;
70+
gap: 8px;
7071
}
7172

7273
.post-item-tags span {
74+
font-size: 14px;
7375
padding: 2px 6px;
7476
border-radius: 3px;
75-
background-color: rgba(81, 81, 81, 0.5);
77+
background-color: var(--tag-bg-color);
78+
color: var(--tag-color);
7679
}
7780

7881
hr {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"title": "Homelab - getting started",
3+
"slug": "homelab-0-getting-started",
4+
"publishDate": "22 Nov 2025",
5+
"description": "Getting started with my homelab setup journey and documentation. Setting up hardware, OS and Docker.",
6+
"nextPost": "homelab-1-additional-configuration",
7+
"tags": [
8+
"homelab",
9+
"selfhosted",
10+
"linux",
11+
"ubuntu-server",
12+
"docker"
13+
]
14+
}

posts/homelab-0-getting-started.md renamed to src/posts/homelab-0-getting-started.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
---
2-
title: Homelab - getting started
3-
slug: homelab-0-getting-started
4-
publishDate: 22 Nov 2025
5-
description: My homelab setup journey and documentation
6-
nextPost: "homelab-1-additional-configuration"
7-
tags: ["homelab"]
8-
---
9-
101
## How it all started
112

123
#### Ad blocking
@@ -46,7 +37,7 @@ For storage, I replaced the old DVD drive with an old 1TB hard disk with a caddy
4637
First, I removed the LCD screen from the laptop and made it headless. For OS, I decided to go with Ubuntu Server 24.04.03 LTS.
4738

4839
Here's how it looks as of now
49-
![Homelab server](../src/assets/blog/media/homelab-server.jpg)
40+
![Homelab server](../assets/blog/media/homelab-server.jpg)
5041

5142
#### OS installation
5243

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"title": "Homelab - Additional configuration",
3+
"slug": "homelab-1-additional-configuration",
4+
"publishDate": "24 Nov 2025",
5+
"description": "Additional system configuration to auto mount drives, move Docker volumes to different drive.",
6+
"prevPost": "homelab-0-getting-started",
7+
"nextPost": "homelab-2-install-pihole",
8+
"tags": [
9+
"homelab",
10+
"selfhosted",
11+
"linux",
12+
"ubuntu-server",
13+
"docker"
14+
]
15+
}

posts/homelab-1-additional-configuration.md renamed to src/posts/homelab-1-additional-configuration.md

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
1-
---
2-
title: Homelab - Additional configuration
3-
slug: homelab-1-additional-configuration
4-
publishDate: 24 Nov 2025
5-
description: My homelab setup journey and documentation
6-
prevPost: homelab-0-getting-started
7-
nextPost: homelab-2-install-pihole
8-
tags: ["homelab"]
9-
---
10-
111
## Assign a fixed IP
122

133
Once the server is ready, we need to assign a fixed IP to the server, as the router assigns IP addresses dynamically to connected devices, and we do not want to have a dynamic IP address to the server. So, we tell the router to allocate a fixed IP to the server by adding an Address Reservation entry in the router's DHCP Server settings. This will map the MAC address of the server to a fixed IP. I have assigned 192.168.0.153.
144

15-
![DHCP address reservation](../src/assets/blog/media/dhcp-server-settings.png)
5+
![DHCP address reservation](../assets/blog/media/dhcp-server-settings.png)
166

177
## Move Docker Volume
188

@@ -75,7 +65,7 @@ By default, Linux does not automount external drives. We can run `mount` command
7565

7666
This will show all drives, including the unmounted ones.
7767

78-
![output of lsblk -f](../src/assets/blog/media/lsblk-f.png)
68+
![output of lsblk -f](../assets/blog/media/lsblk-f.png)
7969
2. Grab the UUID of the drive (A12B-8FFC) and make an entry to fstab. Open the fstab file
8070

8171
```sh
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"title": "Homelab - Install Pi-hole",
3+
"slug": "homelab-2-install-pihole",
4+
"publishDate": "29 Nov 2025",
5+
"description": "Installing and setup Pi-hole for network-wide ad-blocking.",
6+
"prevPost": "homelab-1-additional-configuration",
7+
"tags": [
8+
"homelab",
9+
"selfhosted",
10+
"linux",
11+
"ubuntu-server",
12+
"docker",
13+
"pi-hole",
14+
"ad blocker"
15+
]
16+
}

posts/homelab-2-install-pihole.md renamed to src/posts/homelab-2-install-pihole.md

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
1-
---
2-
title: Homelab - Install Pi-hole
3-
slug: homelab-2-install-pihole
4-
publishDate: 29 Nov 2025
5-
description: My homelab setup journey and documentation
6-
prevPost: homelab-1-additional-configuration
7-
tags: ["homelab"]
8-
---
9-
10-
![Pi-hole Dashboard](../src/assets/blog/media/pihole-dashboard.png)
1+
![Pi-hole Dashboard](../assets/blog/media/pihole-dashboard.png)
112

123
## Install Pi-hole
134

@@ -64,6 +55,6 @@ We will use Docker and Docker Compose to set up Pi-hole and other services.
6455

6556
In the router admin page, we need to set the DNS endpoint to our Pi-hole server.
6657

67-
![Pi-hole server as DNS](../src/assets/blog/media/pihole-server-as-dns.png)
58+
![Pi-hole server as DNS](../assets/blog/media/pihole-server-as-dns.png)
6859

6960
After applying, all the DNS queries will be handled by our Pi-hole server.

0 commit comments

Comments
 (0)