diff --git a/.editorconfig b/.editorconfig index 8a0aafb..93354d0 100644 --- a/.editorconfig +++ b/.editorconfig @@ -13,7 +13,7 @@ insert_final_newline = true indent_style = tab [*.{c,h,cpp,cpp,hpp}] -indent_size = 4 +indent_size = 2 [*.{js,ts}] indent_size = 2 diff --git a/.env b/.env index 07a3e21..811a406 100644 --- a/.env +++ b/.env @@ -1 +1 @@ -LIBZIM_VERSION=9.5.1 +LIBZIM_VERSION=9.7.0 diff --git a/src/creator.h b/src/creator.h index 0be1ec7..7168b68 100644 --- a/src/creator.h +++ b/src/creator.h @@ -342,6 +342,29 @@ class Creator : public Napi::ObjectWrap { } } + void addAlias(const Napi::CallbackInfo &info) { + try { + auto env = info.Env(); + if (info.Length() < 3) { + throw Napi::Error::New(env, + "addAlias requires arguments: path, title, " + "targetPath, [hints]"); + } + + auto path = info[0].As().Utf8Value(); + auto title = info[1].As().Utf8Value(); + auto targetPath = info[2].As().Utf8Value(); + if (info[3].IsObject()) { + auto hints = Object2Hints(info[3].ToObject()); + creator_->addAlias(path, title, targetPath, hints); + } else { + creator_->addAlias(path, title, targetPath); + } + } catch (const std::exception &err) { + throw Napi::Error::New(info.Env(), err.what()); + } + } + void setMainPath(const Napi::CallbackInfo &info) { try { auto env = info.Env(); @@ -387,6 +410,7 @@ class Creator : public Napi::ObjectWrap { InstanceMethod<&Creator::addMetadata>("addMetadata"), InstanceMethod<&Creator::addIllustration>("addIllustration"), InstanceMethod<&Creator::addRedirection>("addRedirection"), + InstanceMethod<&Creator::addAlias>("addAlias"), InstanceMethod<&Creator::setMainPath>("setMainPath"), InstanceMethod<&Creator::setUuid>("setUuid"), diff --git a/src/index.d.ts b/src/index.d.ts index 21552a7..02c08b6 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -118,6 +118,7 @@ export class Creator { targetPath: string, hints?: Hint, ): void; + addAlias(path: string, title: string, targetPath: string, hints?: Hint): void; setMainPath(mainPath: string): void; setUuid(uuid: string): void; finishZimCreation(): Promise; diff --git a/test/zim.test.ts b/test/zim.test.ts index e45385b..0cc9d0b 100644 --- a/test/zim.test.ts +++ b/test/zim.test.ts @@ -222,6 +222,9 @@ describe("Creator", () => { creator.addRedirection("redirect/test1", "Redirect to test 1", "test1", { COMPRESS: 1, }); + creator.addAlias("alias/test1", "Alias to test 1", "test1", { + COMPRESS: 1, + }); creator.setMainPath("redirect/test1"); creator.setUuid("1234567890ABCDEF"); } finally {