Skip to content

Commit

Permalink
feat: more author info
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed Feb 27, 2023
1 parent ca7a864 commit 7ddfd9f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
8 changes: 4 additions & 4 deletions packages/core/src/bundle/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ export function makePackageDocument(opf: PackageDocument): string {
'dc:title': opf.title(),
'dc:language': opf.language(),
'dc:creator': {
'@_id': 'creator',
'#text': opf.creator()
'@_id': opf.creator().uid,
'#text': opf.creator().name
},
'dc:date': toISO8601String(opf.metadata().date),
'dc:description': opf.metadata().description,
Expand All @@ -154,9 +154,9 @@ export function makePackageDocument(opf: PackageDocument): string {
'#text': toISO8601String(opf.metadata().lastModified)
},
{
'@_refines': '#creator',
'@_refines': '#' + opf.creator().uid,
'@_property': 'file-as',
'#text': opf.creator()
'#text': opf.creator()?.fileAs ?? ''
}
]
};
Expand Down
23 changes: 18 additions & 5 deletions packages/core/src/epub/opf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,22 @@ const defu = createDefu((obj: any, key, value: any) => {
}
});

export interface Author {
name: string;

fileAs?: string;

role?: string;

uid?: string;
}

export interface PackageDocumentMeta {
title: string;
language: string;
contributor: string[];
contributor: Author[];
coverage: string;
creator: string;
creator: Author;
date: Date;
description: string;
format: string;
Expand All @@ -42,9 +52,12 @@ export class PackageDocument {
private _metadata: PackageDocumentMeta = {
title: '',
language: 'zh-CN',
contributor: [] as string[],
contributor: [],
coverage: '',
creator: 'unknown',
creator: {
name: 'unknown',
uid: 'creator'
},
date: new Date(),
description: '',
format: '',
Expand Down Expand Up @@ -151,7 +164,7 @@ export class PackageDocument {
return this._identifier;
}

public setIdentifier(identifier: string, uniqueIdentifier: string) {
public setIdentifier(identifier: string, uniqueIdentifier: string = 'uuid') {
this._identifier = identifier;
this._uniqueIdentifier = uniqueIdentifier;
}
Expand Down
6 changes: 5 additions & 1 deletion packages/core/test/__snapshots__/bundle.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ PackageDocument {
"_metadata": {
"contributor": [],
"coverage": "",
"creator": "XLor",
"creator": {
"fileAs": "XLor",
"name": "XLor",
"uid": "creator",
},
"date": 2023-02-01T11:00:00.000Z,
"description": "for test usage",
"format": "",
Expand Down
13 changes: 8 additions & 5 deletions packages/core/test/bundle.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Html } from './../src/epub/item';
import { describe, it, expect } from 'vitest';

import { Epub } from '../src';
import { makeContainer, makePackageDocument } from '../src/bundle';
import { Html } from '../src/epub/item';
import { buildTocNav } from '../src/epub/nav';
import { XHTMLBuilder } from '../src/bundle/xhtml';
import { makeContainer, makePackageDocument } from '../src/bundle';

describe('Bundle Epub', () => {
it('generate container.xml', () => {
Expand All @@ -30,7 +30,7 @@ describe('Bundle Epub', () => {
language: 'zh-CN',
date: new Date('2023-02-01T11:00:00.000Z'),
lastModified: new Date('2023-02-26T11:00:00.000Z'),
creator: 'XLor',
creator: { name: 'XLor', fileAs: 'XLor' },
description: 'for test usage',
source: 'imagine'
});
Expand Down Expand Up @@ -69,7 +69,7 @@ describe('Bundle Epub', () => {
title: 'Test Book',
date: new Date('2023-02-01T11:00:00.000Z'),
lastModified: new Date('2023-02-26T11:00:00.000Z'),
creator: 'XLor',
creator: { name: 'XLor', fileAs: 'XLor' },
description: 'for test usage',
source: 'imagine'
});
Expand Down Expand Up @@ -105,7 +105,10 @@ describe('Bundle Epub', () => {
title: 'Test Book',
date: new Date('2023-02-01T11:00:00.000Z'),
lastModified: new Date('2023-02-26T11:00:00.000Z'),
creator: 'XLor',
creator: {
name: 'XLor',
fileAs: 'XLor'
},
description: 'for test usage',
source: 'imagine'
});
Expand Down

0 comments on commit 7ddfd9f

Please sign in to comment.