mirror of
https://github.com/morten-olsen/morten-olsen.github.io.git
synced 2026-02-08 01:46:28 +01:00
rewrite
This commit is contained in:
32
src/data/data.experiences.ts
Normal file
32
src/data/data.experiences.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { getCollection, getEntry } from "astro:content";
|
||||
|
||||
class Experiences {
|
||||
public getAll = async () => {
|
||||
const collection = await getCollection('experiences');
|
||||
return collection.sort(
|
||||
(a, b) => new Date(b.data.startDate).getTime() - new Date(a.data.startDate).getTime(),
|
||||
);
|
||||
}
|
||||
|
||||
public get = async (id: string) => {
|
||||
const entry = await getEntry('experiences', id);
|
||||
if (!entry) {
|
||||
throw new Error(`Experience ${id} not found`);
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
||||
public getCurrent = async () => {
|
||||
const all = await this.getAll();
|
||||
return all.find((experience) => !experience.data.endDate);
|
||||
}
|
||||
|
||||
public getPrevious = async () => {
|
||||
const all = await this.getAll();
|
||||
return all.filter((experience) => experience.data.endDate);
|
||||
}
|
||||
}
|
||||
|
||||
const experiences = new Experiences();
|
||||
|
||||
export { experiences }
|
||||
Reference in New Issue
Block a user