Fix #7 - Added new Type definition and filter by status where we are on dev or prod (#8)
All checks were successful
CodyOps Core Builder / build-conteiner (push) Successful in 2m54s
All checks were successful
CodyOps Core Builder / build-conteiner (push) Successful in 2m54s
Reviewed-on: #8 Co-authored-by: Luciano Giacchetta <giacchetta-@outlook.com> Co-committed-by: Luciano Giacchetta <giacchetta-@outlook.com>
This commit is contained in:
parent
5715c7cc11
commit
dea6ab6823
@ -1,11 +1,29 @@
|
|||||||
import directus from "./directus";
|
import directus from "./directus";
|
||||||
import { readItems } from "@directus/sdk";
|
import { readItems, type Query } from "@directus/sdk";
|
||||||
|
import type { Post, DirectusSchema } from "../types/codyops-post";
|
||||||
|
|
||||||
|
const isDev = import.meta.env.DEV; // Astro's way to check for development mode
|
||||||
|
|
||||||
export const posts = await directus.request(
|
export const posts = await directus.request(
|
||||||
readItems("codyops_posts", {
|
readItems<DirectusSchema, 'codyops_posts', Query<DirectusSchema, Post>>("codyops_posts", {
|
||||||
fields: ['*']
|
fields: [
|
||||||
|
'slug',
|
||||||
|
'status',
|
||||||
|
'sort',
|
||||||
|
'user_created',
|
||||||
|
'user_updated',
|
||||||
|
'date_created',
|
||||||
|
'date_updated',
|
||||||
|
'title',
|
||||||
|
'description',
|
||||||
|
'tags',
|
||||||
|
'cover_image',
|
||||||
|
'content'
|
||||||
|
],
|
||||||
|
filter: {
|
||||||
|
status: isDev ? { '_neq': 'archived' } : { '_eq': 'published' }
|
||||||
}
|
}
|
||||||
)
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
export function getAllPosts() {
|
export function getAllPosts() {
|
||||||
@ -21,4 +39,3 @@ export function getUniqueTags(posts: any ) {
|
|||||||
export function filterPostsByTag(posts: any, tag: any) {
|
export function filterPostsByTag(posts: any, tag: any) {
|
||||||
return posts.filter((post: any) => post.tags.includes(tag));
|
return posts.filter((post: any) => post.tags.includes(tag));
|
||||||
};
|
};
|
||||||
|
|
18
src/types/codyops-post.ts
Normal file
18
src/types/codyops-post.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
export interface Post {
|
||||||
|
slug: string;
|
||||||
|
status: string;
|
||||||
|
sort: number | null;
|
||||||
|
user_created: string | null;
|
||||||
|
user_updated: string | null;
|
||||||
|
date_created: string | null;
|
||||||
|
date_updated: string | null;
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
tags: string[];
|
||||||
|
cover_image: string | null;
|
||||||
|
content: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DirectusSchema {
|
||||||
|
codyops_posts: Post[];
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user