-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathquery.ts
More file actions
42 lines (38 loc) · 1.38 KB
/
query.ts
File metadata and controls
42 lines (38 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { type CollectionEntry, getCollection, getEntry } from "astro:content";
import type { Kind } from "./schema.ts";
export async function getProjects(kind: Kind | "all") {
return (await getCollection("projects"))
.filter((project) => kind === "all" || project.data.kind === kind)
.sort((a, b) => {
const a_order = a.data.order ?? Number.POSITIVE_INFINITY;
const b_order = b.data.order ?? Number.POSITIVE_INFINITY;
if (a_order !== b_order) {
return a_order - b_order;
}
if (b.data.date.getTime() !== a.data.date.getTime()) {
return b.data.date.getTime() - a.data.date.getTime();
}
return (a.filePath ?? "") < (b.filePath ?? "") ? -1 : 1;
});
}
export async function getArticles(options?: {
where?: (article: CollectionEntry<"articles">) => boolean;
}) {
let articles = (await getCollection("articles")).sort(
(a, b) => b.data.date.getTime() - a.data.date.getTime(),
);
if (options?.where) {
articles = articles.filter(options.where);
}
return articles;
}
export async function getMembers() {
const members = await getCollection("members");
return members.sort((m1, m2) => m2.data.joinYear - m1.data.joinYear);
}
export async function getMember(id: string) {
const member = await getEntry("members", id);
if (!member)
throw new Error(`member search error: member not found for ${id}`);
return member;
}