Skip to content

Commit

Permalink
feat: generate more metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed Mar 5, 2023
1 parent fb7dc43 commit bb76947
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
24 changes: 15 additions & 9 deletions packages/epubook/src/epubook.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { NavList, NavOption } from './../../core/src/epub/nav';
import * as path from 'node:path';

import type { DefaultTheme, DefaultThemePageTemplate } from '@epubook/theme-default';

import {
type Theme,
type Author,
type NavList,
type NavOption,
type PageTemplate,
type ImageExtension,
type ImageMediaType,
Expand All @@ -13,14 +18,11 @@ import {
Style
} from '@epubook/core';

import type { DefaultTheme, DefaultThemePageTemplate } from '@epubook/theme-default';

import * as path from 'node:path';

import { Cover } from './pages';
import { EpubookError } from './error';

export interface EpubookOption<T extends Theme<{}> = Awaited<ReturnType<typeof DefaultTheme>>> {
export interface EpubookOption<T extends Theme<{}> = Awaited<ReturnType<typeof DefaultTheme>>>
extends PackageDocumentMeta {
title: string;

description: string;
Expand All @@ -38,7 +40,7 @@ const ImageDir = 'images';
export class Epubook<P extends Record<string, PageTemplate> = DefaultThemePageTemplate> {
private theme!: Theme<P>;

private _option: Omit<EpubookOption<Theme<P>>, 'theme'>;
private _option: Partial<Omit<EpubookOption<Theme<P>>, 'theme'>>;

private _container: Epub;

Expand All @@ -63,7 +65,11 @@ export class Epubook<P extends Record<string, PageTemplate> = DefaultThemePageTe
...option
};

this._container = new Epub(this._option);
this._container = new Epub({
creator: this._option.author![0],
contributor: this._option.author!.slice(1),
...this._option
});
}

public static async create<P extends Record<string, PageTemplate> = DefaultThemePageTemplate>(
Expand Down Expand Up @@ -179,7 +185,7 @@ export class Epubook<P extends Record<string, PageTemplate> = DefaultThemePageTe
}
return render(file, props)
.style(...this._styles)
.language(this._option.language);
.language(this._option.language ?? 'zh-CN');
}

public page<T extends string & keyof Theme<P>['pages']>(
Expand Down
9 changes: 7 additions & 2 deletions packages/epubook/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ import { Epubook } from '../src';
describe('epubook', () => {
it('should write epub with cover', async () => {
const book = await Epubook.create({
title: 'cover',
title: 'epubook test',
description: 'This is generated for testing cover image',
language: 'zh-CN'
language: 'zh-CN',
author: [{ name: 'XLor', fileAs: 'xlor' }],
date: new Date('2023-02-28'),
lastModified: new Date('2023-03-05'),
subject: 'novel',
publisher: 'XLor Books'
});

const cover = await book.cover('../../assets/cover.jpg');
Expand Down

0 comments on commit bb76947

Please sign in to comment.