mirror of
https://github.com/andwati/personal-website.git
synced 2026-11-19 17:25:15 +00:00
Add Bookshelf component for displaying book collection with navigation
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import { getMdxContent, MaybeContent } from "./mdx";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
|
||||
export interface Book {
|
||||
title: string;
|
||||
author: string;
|
||||
date: string;
|
||||
rating: number;
|
||||
coverImage: string;
|
||||
spineColor: string;
|
||||
textColor: string;
|
||||
slug: string;
|
||||
summary: string;
|
||||
}
|
||||
|
||||
export function getAllBooks(): Book[] {
|
||||
return JSON.parse(
|
||||
fs.readFileSync(
|
||||
path.join(process.cwd(), "content", "books", "index.json"),
|
||||
"utf8",
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getAllSlugs(): string[] {
|
||||
const data = getAllBooks();
|
||||
return data.map((item) => item.slug);
|
||||
}
|
||||
|
||||
export async function getBook(slug: string): Promise<MaybeContent<Book>> {
|
||||
const book = await getMdxContent<Book>("books", `${slug}.mdx`);
|
||||
if (!book) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return {
|
||||
...book,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user