diff --git a/lib/blog.ts b/lib/blog.ts
index 7362110..27cfcea 100644
--- a/lib/blog.ts
+++ b/lib/blog.ts
@@ -15,7 +15,7 @@ export interface Article {
publicKey?: string
hash?: string
canonical?: string
- tags?: string[]
+ tags?: { id: string; name: string }[]
projects?: string[]
}
@@ -71,7 +71,13 @@ export function getArticles(options?: {
return {
id,
...matterResult.data,
- tags: tags,
+ tags: tags.map((tag) => ({
+ id: tag
+ .toLowerCase()
+ .replace(/\s+/g, "-")
+ .replace(/[^a-z0-9-]/g, ""),
+ name: tag,
+ })),
content: matterResult.content,
}
} catch (error) {
@@ -92,7 +98,7 @@ export function getArticles(options?: {
// Filter by tag if provided
if (tag) {
filteredArticles = filteredArticles.filter((article) =>
- article.tags?.includes(tag)
+ article.tags?.some((t) => t.id === tag)
)
}
@@ -117,6 +123,28 @@ export function getArticles(options?: {
.filter((article) => article.id !== "_article-template")
}
+export const getArticleTags = () => {
+ const articles = getArticles()
+ const allTags =
+ articles
+ .map((article) => article.tags?.map((t) => t.name))
+ .flat()
+ .filter(Boolean) ?? []
+
+ return Array.from(new Set(allTags)) as string[]
+}
+
+export const getArticleTagsWithIds = () => {
+ const tags = getArticleTags()
+ return tags.map((tag) => ({
+ id: tag
+ .toLowerCase()
+ .replace(/\s+/g, "-")
+ .replace(/[^a-z0-9-]/g, ""),
+ name: tag,
+ }))
+}
+
export function getArticleById(slug?: string) {
// Note: This might need adjustment if you expect getArticleById to also have tags
// Currently relies on the base getArticles() which fetches all tags
diff --git a/state/useProjectFiltersState.ts b/state/useProjectFiltersState.ts
index 3a2ace3..76d392a 100644
--- a/state/useProjectFiltersState.ts
+++ b/state/useProjectFiltersState.ts
@@ -51,7 +51,6 @@ interface ProjectStateProps {
activeFilters: Partial
queryString: string
searchQuery: string
- currentCategory: ProjectCategory | null
}
interface SearchMatchByParamsProps {
@@ -72,7 +71,6 @@ interface ProjectActionsProps {
onFilterProject: (searchPattern: string) => void
onSelectTheme: (theme: string, searchPattern?: string) => void
sortProjectBy: (sortBy: ProjectSortBy) => void
- setCurrentCategory: (section: ProjectCategory | null) => void
}
const createURLQueryString = (params: Partial): string => {
@@ -236,7 +234,6 @@ const sortProjectByFn = ({
export const useProjectFiltersState = create<
ProjectStateProps & ProjectActionsProps
>()((set) => ({
- currentCategory: null,
sortBy: DEFAULT_PROJECT_SORT_BY,
projects: sortProjectByFn({
projects,
@@ -351,16 +348,4 @@ export const useProjectFiltersState = create<
}
})
},
- setCurrentCategory(category: ProjectCategory | null) {
- set((state: any) => {
- return {
- ...state,
- projects: projects.filter((project) => {
- if (category == null) return true // return all projects
- return project?.category === category
- }),
- currentCategory: category,
- }
- })
- },
}))