Skip to content

Commit 47a93c6

Browse files
authored
Merge pull request #83 from nurRiyad/content-v3
Update @nuxt/content to version 3.x and refactor content queries
2 parents 1aba5e1 + 820a380 commit 47a93c6

File tree

16 files changed

+22688
-15611
lines changed

16 files changed

+22688
-15611
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# This workflow will do a clean installation of node dependencies, check linting and build
2-
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
3-
41
name: Node.js CI
52

63
on:
@@ -17,23 +14,20 @@ jobs:
1714
- name: Checkout
1815
uses: actions/checkout@v4
1916

20-
- uses: pnpm/action-setup@v4
21-
name: Install pnpm
22-
2317
- name: Install Node.js
2418
uses: actions/setup-node@v4
2519
with:
2620
node-version: 22
27-
cache: 'pnpm'
21+
cache: 'npm'
2822

2923
- name: Install dependencies
30-
run: pnpm install
24+
run: npm ci
3125

3226
- name: Check Linting
33-
run: pnpm run lint
27+
run: npm run lint
3428

3529
- name: Check Format
36-
run: pnpm run format
30+
run: npm run format
3731

3832
- name: Playgourd build check
39-
run: pnpm run build
33+
run: npm run build

components/blog/Toc.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
22
const { path } = useRoute()
3-
const articles = await queryContent(path).findOne()
3+
const articles = await queryCollection('content').path(path).first()
44
55
const links = articles?.body?.toc?.links || []
66
</script>

components/main/recent.vue

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,42 @@
11
<script lang="ts" setup>
2+
import type { BlogPost } from '~/types/blog'
3+
4+
// Function to parse dates in the format "1st Mar 2023"
5+
function parseCustomDate(dateStr: string): Date {
6+
// Remove ordinal indicators (st, nd, rd, th)
7+
const cleanDateStr = dateStr.replace(/(\d+)(st|nd|rd|th)/, '$1')
8+
// Parse the date
9+
return new Date(cleanDateStr)
10+
}
11+
212
// Get Last 6 Publish Post from the content/blog directory
313
const { data } = await useAsyncData('recent-post', () =>
4-
queryContent('/blogs').limit(3).sort({ _id: -1 }).find(),
14+
queryCollection('content')
15+
.all()
16+
.then((data) => {
17+
return data
18+
.sort((a, b) => {
19+
const aDate = parseCustomDate(a.meta.date as string)
20+
const bDate = parseCustomDate(b.meta.date as string)
21+
return bDate.getTime() - aDate.getTime()
22+
})
23+
.slice(0, 3)
24+
}),
525
)
626
727
const formattedData = computed(() => {
828
return data.value?.map((articles) => {
29+
const meta = articles.meta as unknown as BlogPost
930
return {
10-
path: articles._path,
31+
path: articles.path,
1132
title: articles.title || 'no-title available',
1233
description: articles.description || 'no-description available',
13-
image: articles.image || '/not-found.jpg',
14-
alt: articles.alt || 'no alter data available',
15-
ogImage: articles.ogImage || '/not-found.jpg',
16-
date: articles.date || 'not-date-available',
17-
tags: articles.tags || [],
18-
published: articles.published || false,
34+
image: meta.image || '/not-found.jpg',
35+
alt: meta.alt || 'no alter data available',
36+
ogImage: meta.ogImage || '/not-found.jpg',
37+
date: meta.date || 'not-date-available',
38+
tags: meta.tags || [],
39+
published: meta.published || false,
1940
}
2041
})
2142
})

components/main/trending.vue

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
<script lang="ts" setup>
2-
// Get Last 6 Publish Post from the content/blog directory
2+
import type { BlogPost } from '~/types/blog'
3+
34
const { data } = await useAsyncData('trending-post', () =>
4-
queryContent('/blogs').limit(3).sort({ _id: 1 }).find(),
5+
queryCollection('content').limit(3).all(),
56
)
67
78
const formattedData = computed(() => {
89
return data.value?.map((articles) => {
10+
const meta = articles.meta as unknown as BlogPost
911
return {
10-
path: articles._path,
12+
path: articles.path,
1113
title: articles.title || 'no-title available',
1214
description: articles.description || 'no-description available',
13-
image: articles.image || '/not-found.jpg',
14-
alt: articles.alt || 'no alter data available',
15-
ogImage: articles.ogImage || '/not-found.jpg',
16-
date: articles.date || 'not-date-available',
17-
tags: articles.tags || [],
18-
published: articles.published || false,
15+
image: meta.image || '/not-found.jpg',
16+
alt: meta.alt || 'no alter data available',
17+
ogImage: meta.ogImage || '/not-found.jpg',
18+
date: meta.date || 'not-date-available',
19+
tags: meta.tags || [],
20+
published: meta.published || false,
1921
}
2022
})
2123
})

content.config.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { defineCollection, defineContentConfig } from '@nuxt/content'
2+
import { asRobotsCollection } from '@nuxtjs/robots/content'
3+
import { asSitemapCollection } from '@nuxtjs/sitemap/content'
4+
import { asOgImageCollection } from 'nuxt-og-image/content'
5+
6+
export default defineContentConfig({
7+
collections: {
8+
content: defineCollection({
9+
...asRobotsCollection({
10+
type: 'page',
11+
source: '**/*.md',
12+
}),
13+
...asSitemapCollection({
14+
type: 'page',
15+
source: '**/*.md',
16+
}),
17+
...asOgImageCollection({
18+
type: 'page',
19+
source: '**/*.md',
20+
}),
21+
}),
22+
},
23+
})

data/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const navbarData = {
55
export const footerData = {
66
author: 'Al Asad Nur Riyad',
77
aboutAuthor:
8-
'Hi! I am Riyad, a Tech enthusiast, problem solver and software engineer. Currently working at Appscode Inc.',
8+
'Hi! I am Riyad, a Tech enthusiast, problem solver and software engineer. Currently working at FieldNation LLC.',
99
authorInterest:
1010
"I have a fair amount of knowledge of Javascript, Typescript, VueJs, and Nuxt. If you have an interesting idea, either open source or paid let's connect.",
1111
aboutTheSite:
@@ -33,13 +33,13 @@ export const aboutPage = {
3333
title: 'Al Asad Nur Riyad',
3434
description: 'Software Engineer, Problem Solver, Web Enthusiast.',
3535
aboutMe:
36-
"Hello, fellow human! I'm a software wizard who spends most of his day crafting code spells at @AppsCode in the Bytebuilders team. When I'm not crafting code, you can find me summoning solutions to problems on online judges. Just don't ask me to cast any love spells, my magic only works on machines!",
36+
"Hello, fellow human! I'm a software wizard who spends most of his day crafting code spells at @FieldNation in the Workplace Operation team. When I'm not crafting code, you can find me summoning solutions to problems on online judges. Just don't ask me to cast any love spells, my magic only works on machines!",
3737
}
3838

3939
export const seoData = {
4040
title: `Riyad's Blog | Riyads Blog`,
4141
ogTitle: `Let's learn Javascript, Typescript, Vue, Nuxt, & Problem Solving - Riyads Blog | Riyad's Blog`,
42-
description: `Hi I am Riyad. A Software Engineer at AppsCode, with over 2.5+ years experience in software development. - Riyads Blog | Riyad's Blog`,
42+
description: `Hi I am Riyad. A Software Engineer at FieldNation, with over 3.5+ years experience in software development. - Riyads Blog | Riyad's Blog`,
4343
twitterDescription: `Riyad's Blog, where I play around with Nuxt, Vue, and more and showcase my blog, resources, etc - Riyads Blog | Riyad's Blog`,
4444
image:
4545
'https://res.cloudinary.com/dmecmyphj/image/upload/v1673548905/nuxt-blog/cover_ntgs6u.webp',

nuxt.config.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ export default defineNuxtConfig({
1010
'@nuxt/fonts',
1111
'@nuxt/eslint',
1212
'@vueuse/nuxt',
13-
'@nuxt/content',
14-
'nuxt-og-image',
1513
'@nuxtjs/robots',
1614
'@nuxtjs/sitemap',
15+
'nuxt-og-image',
16+
'@nuxt/content',
1717
'@nuxtjs/color-mode',
1818
'@nuxtjs/tailwindcss',
1919
'@formkit/auto-animate',
@@ -32,15 +32,12 @@ export default defineNuxtConfig({
3232
},
3333

3434
sitemap: {
35-
strictNuxtContentPaths: true,
35+
sources: [seoData.mySite],
3636
},
3737

3838
site: {
3939
url: seoData.mySite,
40-
identity: {
41-
type: 'Person',
42-
},
43-
twitter: seoData.twitterHandle,
40+
name: 'Al Asad Nur Riyad',
4441
},
4542

4643
typescript: {
@@ -61,8 +58,12 @@ export default defineNuxtConfig({
6158
},
6259

6360
content: {
64-
highlight: {
65-
theme: 'dracula',
61+
build: {
62+
markdown: {
63+
highlight: {
64+
theme: 'dracula',
65+
},
66+
},
6667
},
6768
},
6869
})

0 commit comments

Comments
 (0)