-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Server action folder refactoring and meta type update for articles (#132
) * update on next.js version and unoptimized pug * update content and seo keywords * server action refactoring and changing meta tags --------- Co-authored-by: Arkar <[email protected]>
- Loading branch information
Showing
30 changed files
with
368 additions
and
288 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Category } from "@/types/articles"; | ||
import client from "@/utils/client"; | ||
import { cache } from "react"; | ||
|
||
export const getCategories = cache(async function (): Promise<Category[]> { | ||
const query = ` | ||
*[_type=='category']{ | ||
title, | ||
_id | ||
} | ||
`; | ||
return await client.fetch(query); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
"use server"; | ||
import client from "@/utils/client"; | ||
import { cache } from "react"; | ||
import type { ArticlCardType, ArticleDetailType } from "@/types/articles"; | ||
import type { Serie } from "@/types/series"; | ||
|
||
export const getLatestHomePosts = cache(async function (): Promise< | ||
ArticlCardType[] | ||
> { | ||
const query = `*[_type == "article"] | order(releasedAt desc) [0..4] { | ||
title, | ||
'slug':slug.current, | ||
releasedAt, | ||
description, | ||
'categories':categories[]->title, | ||
}`; | ||
return await client.fetch(query); | ||
}); | ||
|
||
export const getArticleSeries = cache(async function (): Promise<Serie[]> { | ||
const query = ` | ||
*[_type=='serie'] { | ||
_id, | ||
title, | ||
description, | ||
'articles':articles[]->{ | ||
title, | ||
'categories':categories[]->title, | ||
'slug':slug.current, | ||
releasedAt, | ||
}, | ||
}`; | ||
return await client.fetch(query); | ||
}); | ||
|
||
export const getArticles = cache(async function (): Promise<ArticlCardType[]> { | ||
let query = ` | ||
*[_type=='article'] | order(releasedAt desc) { | ||
'slug':slug.current, | ||
title, | ||
releasedat, | ||
description, | ||
mainImage, | ||
'categories':categories[]->title, | ||
} | ||
`; | ||
return await client.fetch(query); | ||
}); | ||
|
||
export const getArticleBySlug = cache(async function ( | ||
slug?: string, | ||
): Promise<ArticleDetailType> { | ||
const query = ` | ||
*[_type == "article" && slug.current == $slug][0]{ | ||
title, | ||
'slug':slug.current, | ||
releasedAt, | ||
description, | ||
'categories':categories[]->title, | ||
body[]{ | ||
..., | ||
asset->{ | ||
metadata, | ||
"_type":"reference", | ||
"_ref": _id | ||
} | ||
}, | ||
"related": *[_type == "article" && _id != ^._id && count(categories[@._ref in ^.^.categories[]._ref]) > 0] | order(releasedAt desc, _createdAt desc) [0..2] { | ||
title, | ||
_id, | ||
"mainImage":{ | ||
"asset":{ | ||
...mainImage.asset, | ||
"metadata":mainImage.asset->metadata | ||
}, | ||
}, | ||
"slug": slug.current, | ||
description | ||
} | ||
}`; | ||
return await client.fetch(query, { | ||
slug: slug, | ||
}); | ||
}); | ||
|
||
export const getArticleSEOContentBySlug = cache(async function ( | ||
slug?: string, | ||
): Promise<ArticleDetailType> { | ||
const seoQuery = ` | ||
*[_type == "article" && slug.current == $slug][0]{ | ||
title, | ||
'slug':slug.current, | ||
description, | ||
'categories':categories[]->title, | ||
'mainImage':mainImage.asset->{url}.url | ||
}`; | ||
return await client.fetch(seoQuery, { | ||
slug: slug, | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"use server"; | ||
|
||
import client from "@/utils/client"; | ||
import type { Project } from "@/types/projects"; | ||
import { cache } from "react"; | ||
|
||
export const getHomeProjects = cache( | ||
async function (): Promise<Project[]> { | ||
const query = ` | ||
*[_type=='project' && pinned==true][0..6]{ | ||
..., | ||
"slug": slug.current | ||
} | ||
`; | ||
|
||
return await client.fetch(query); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"use server"; | ||
|
||
import { ArticlCardType } from "@/types/articles"; | ||
import client from "@/utils/client"; | ||
import { cache } from "react"; | ||
|
||
export const getSnippets = cache(async function (): Promise<ArticlCardType[]> { | ||
let query = ` | ||
*[_type=='snippet'] | order(releasedAt desc) { | ||
title, | ||
'slug':slug.current, | ||
'categories':categories[]->title, | ||
description, | ||
releasedAt | ||
} | ||
`; | ||
return await client.fetch(query); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.