Assets and files
Assets
Section titled “Assets”When Inkweaver builds your novel, it renames each asset based on its contents. For example, act-1.fountain might become 4c76-4803-c0be-a50c.fountain, and the name changes whenever the file does. Use these functions to find an asset’s built file from its original path.
resolve
Section titled “resolve”Returns the built URL for an asset path.
resolve<T extends RequestInfo | URL>(url: T, locale?: string): T| Parameter | Description |
|---|---|
url | The asset’s path in your workspace. To find a plugin’s asset, start the path with the plugin’s name, like shop-plugin:assets/inventory.json. |
locale | The locale to find. Defaults to the version of the file with no locale. |
If the file doesn’t have the requested locale, resolve returns the version with no locale if there is one, and otherwise the first locale it has. See Localization for how to localize files.
Example
const url = resolve("/assets/shop.json");resolveOwn
Section titled “resolveOwn”Returns the built URL for one of the calling plugin’s own files.
resolveOwn(path: string, locale?: string): stringThis is the same as calling resolve with the plugin’s name in front of the path.
Example
const url = resolveOwn("assets/inventory.json");
// Same as:const sameUrl = resolve(`${getPluginName()}:assets/inventory.json`);getPluginName
Section titled “getPluginName”Returns the calling plugin’s name, from its plugin.json.
getPluginName(): stringExample
console.log(`${getPluginName()} is ready`);getProjectSettings
Section titled “getProjectSettings”Returns the settings from your workspace’s project.json.
getProjectSettings(): ProjectSettings
interface ProjectSettings { exports?: BuildExports; locales?: Array<string>; main?: string; startup: { bootstrapCommand?: string; startLabel: string; }; version: string;}locales lists the IETF language tags your novel supports. See declaring supported locales.
Example
const { locales } = getProjectSettings();These functions read and write files on the reader’s device. Files are stored in the browser’s IndexedDB.
readFile
Section titled “readFile”Reads a file.
readFile(input: RequestInfo | URL, init?: RequestInit): Promise<Response>Example
const response = await readFile("/notes.txt");const text = await response.text();writeFile
Section titled “writeFile”Writes a file.
writeFile(input: RequestInfo | URL, data: any, init?: RequestInit): Promise<Response>Example
await writeFile("/notes.txt", "The butler did it.");