Merge pull request #66 from kiwix/Issue#65

Updated `README.md` file to demonstrate how devs can use generated binaries in their project.
This commit is contained in:
Kelson 2023-08-27 11:31:59 +07:00 committed by GitHub
commit f9dc43e177
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,7 +24,29 @@ Library for accessing [libkiwix](https://github.com/kiwix/libkiwix) and [libzim]
AAR file will be generated in directory `lib/build/outputs/aar` AAR file will be generated in directory `lib/build/outputs/aar`
### Load zim file ### Use the library in your project
First, locate the compiled/generated `lib-debug.aar` in the
`lib/build/outputs/aar` directory. Then open your project's Gradle
configuration file and import the .aar file as a dependency.
If you are using Kotlin for your Gradle file, add the following code snippet:
```kotlin
dependencies {
implementation(files("path-of-aar-file/lib-debug.aar"))
}
```
If you are using Groovy for your Gradle file, use this code snippet:
```kotlin
dependencies {
implementation files("path-to-your-aar-file/lib-debug.aar")
}
```
### Load ZIM file
To load a ZIM file you need to create an `Archive` object. To load a ZIM file you need to create an `Archive` object.
@ -32,12 +54,13 @@ To load a ZIM file you need to create an `Archive` object.
val archive = Archive("your-file-path") val archive = Archive("your-file-path")
``` ```
### Load main page ### Load ZIM main page
The `mainPage` property is used to retrieve the path of the main entry page for a Kiwix content archive. The `mainPage` property is used to retrieve the path of the main entry
If the main entry is a redirect, it will fetch the path of the redirected item; page for a Kiwix content archive. If the main entry is a redirect, it
otherwise, it will return the path of the main entry itself. will fetch the path of the redirected item; otherwise, it will return
If the main entry is not found, the archive will throw an `EntryNotFoundException`. the path of the main entry itself. If the main entry is not found,
the archive will throw an `EntryNotFoundException`.
```kotlin ```kotlin
val mainPage: String? val mainPage: String?
@ -53,7 +76,7 @@ val mainPage: String?
} }
``` ```
### Load an article via title ### Load a ZIM article via title
```kotlin ```kotlin
try { try {
@ -67,7 +90,7 @@ val mainPage: String?
} }
``` ```
### Load an Article via Path ### Load a ZIM article via path
Ensure that the URL path is properly decode before passing it to `hasEntryByPath`, Ensure that the URL path is properly decode before passing it to `hasEntryByPath`,
as `Libzim` does not support encoded URLs. as `Libzim` does not support encoded URLs.