Add library push to website from the content editor
This commit is contained in:
1 parent
ec57bd73b3
commit
0f90babb7a
13 files changed
+281
-20
No files matched your search
@@ -2,7 +2,7 @@ import { error } from '@sveltejs/kit';
|
||||
import type { Book, BookSeries, BookShelf } from '#lib/content';
|
||||
import { timestamp, type SqlDatabase } from './database';
|
||||
import { hasImage, imageUrl, removeImage, syncImage } from './images';
|
||||
import { parseList, readChoice, readHistory, readNumber, readRating, readText, readTextList, type RequestBody } from './input';
|
||||
import { parseList, readChoice, readHistory, readNumber, readRating, readText, readTextList, type ExportedEntry, type RequestBody } from './input';
|
||||
|
||||
interface BookRow {
|
||||
goodreads_id: string;
|
||||
@@ -74,6 +74,30 @@ export function listBooks(database: SqlDatabase, imageIds: Set<string>): Book[]
|
||||
return rows.map((row) => toBook(row, imageIds.has(coverImageId(row.goodreads_id))));
|
||||
}
|
||||
|
||||
export function exportBooks(database: SqlDatabase): ExportedEntry[] {
|
||||
const rows = database.prepare('SELECT * FROM books ORDER BY goodreads_id').all() as BookRow[];
|
||||
return rows.map((row) => ({
|
||||
id: row.goodreads_id,
|
||||
fields: {
|
||||
title: row.title,
|
||||
authors: parseList(row.authors),
|
||||
description: row.description,
|
||||
pages: row.pages,
|
||||
published: row.published,
|
||||
genres: parseList(row.genres),
|
||||
averageRating: row.average_rating,
|
||||
ratingCount: row.rating_count,
|
||||
coverSource: row.cover_source,
|
||||
shelf: row.shelf,
|
||||
rating: row.rating,
|
||||
series: row.series_name ? { name: row.series_name, url: row.series_url, position: row.series_position } : null,
|
||||
added: row.added,
|
||||
started: row.started,
|
||||
finished: row.finished
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
function readSeries(body: RequestBody, existing: BookRow | null): Pick<BookRow, 'series_name' | 'series_url' | 'series_position'> {
|
||||
const current = {
|
||||
series_name: existing?.series_name ?? null,
|
||||
|
||||
Reference in new issue
Block a user