Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
LIBZIM_VERSION=9.5.1
LIBZIM_VERSION=9.7.0
24 changes: 24 additions & 0 deletions src/creator.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,29 @@ class Creator : public Napi::ObjectWrap<Creator> {
}
}

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<Napi::String>().Utf8Value();
auto title = info[1].As<Napi::String>().Utf8Value();
auto targetPath = info[2].As<Napi::String>().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();
Expand Down Expand Up @@ -387,6 +410,7 @@ class Creator : public Napi::ObjectWrap<Creator> {
InstanceMethod<&Creator::addMetadata>("addMetadata"),
InstanceMethod<&Creator::addIllustration>("addIllustration"),
InstanceMethod<&Creator::addRedirection>("addRedirection"),
InstanceMethod<&Creator::addAlias>("addAlias"),
InstanceMethod<&Creator::setMainPath>("setMainPath"),
InstanceMethod<&Creator::setUuid>("setUuid"),

Expand Down
1 change: 1 addition & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>;
Expand Down
3 changes: 3 additions & 0 deletions test/zim.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down