-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add VaultManifestClient and VaultManifest interfaces
- Added a new file `manifest-client.ts` which contains the implementation of the `VaultManifestClient` class. - The `VaultManifestClient` class provides methods for resolving assets from a MoltenObsidian vault's manifest. - Created two static methods in `VaultManifestClient`: `fromManifest()` and `fromPath()`. - The `fromManifest()` method creates a new instance of `VaultManifestClient` from an existing manifest object. - The `fromPath()` method fetches the manifest from a given URL or relative path, and returns a promise that resolves to a new instance of `VaultManifestClient`. - Updated the package.json file with dependencies and devDependencies related to the project. - Added the pnpm-lock.yaml file with dependency resolutions for '@types/mime-types' and 'typescript'. - Created two new files: 'vault-manifest.ts' which defines the interfaces for VaultManifest and VaultFile. These interfaces represent the structure of a MoltenObsidian vault's manifest. This commit adds support for working with MoltenObsidian vault manifests through the newly added classes and interfaces.
- Loading branch information
1 parent
695bd1d
commit b0cdb60
Showing
5 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import {VaultFile, VaultManifest} from 'vault-manifest' | ||
|
||
/** | ||
* Represents a client for resolving a MoltenObsidian vault's assets from its manifest. | ||
* @class | ||
* @public | ||
*/ | ||
export class VaultManifestClient { | ||
public static fromManifest(manifest: VaultManifest): VaultManifestClient { | ||
return new VaultManifestClient(manifest); | ||
} | ||
|
||
public static async fromPath(path: string | URL): Promise<VaultManifestClient> { | ||
// Check if the path is a string | ||
if (typeof path === 'string') { | ||
// Check if the path is an absolute URL | ||
if (path.startsWith('http://') || path.startsWith('https://')) { | ||
path = new URL(path); | ||
} else { | ||
// Assume the path is a relative path, from base URL (defined in <base> tag) | ||
path = new URL(path, document.baseURI ?? window.location.href); | ||
} | ||
} | ||
|
||
// Fetch the manifest from the URL | ||
const response = await fetch(path.toString()); | ||
if (!response.ok) { | ||
throw new Error(`Failed to fetch manifest from ${path.toString()}: ${response.statusText}`); | ||
} | ||
|
||
const manifest = await response.json() as VaultManifest; | ||
return VaultManifestClient.fromManifest(manifest); | ||
} | ||
|
||
protected constructor( | ||
public readonly Manifest: VaultManifest | ||
) { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
{ | ||
"name": "moltenobsidian-ssg-client", | ||
"author": "Nodsoft Systems", | ||
"description": "SSG Client for MoltenObsidian vaults", | ||
"license": "ISC", | ||
"scripts": { | ||
"build": "tsc" | ||
}, | ||
|
||
"devDependencies": { | ||
"typescript": "^5.1.6" | ||
}, | ||
|
||
"dependencies": { | ||
"@types/mime-types": "^2.1.1" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Represents a manifest for a MoltenObsidian vault. | ||
* @interface | ||
*/ | ||
export interface VaultManifest { | ||
/** | ||
* The name of the vault. | ||
* @type {string} | ||
*/ | ||
name: string; | ||
|
||
/** | ||
* List of files in the vault. | ||
* @type {VaultFile[]} | ||
*/ | ||
files: VaultFile[]; | ||
} | ||
|
||
/** | ||
* Represents a file in a MoltenObsidian vault manifest | ||
* @interface | ||
*/ | ||
export interface VaultFile { | ||
/** | ||
* The path of the file. | ||
* @type {string} | ||
* @example "README.md" | ||
* @example "super/secret/file.md" | ||
*/ | ||
path: string; | ||
|
||
/** | ||
* The size of the file in bytes. | ||
* @type {number} | ||
*/ | ||
size: number; | ||
|
||
/** | ||
* The hash of the file. | ||
* @type {string} | ||
*/ | ||
hash: string | null; | ||
|
||
/** | ||
* The content type of the file, as a MIME type. | ||
* @type {string} | ||
* @example "text/markdown" | ||
*/ | ||
contentType: string | null; | ||
} |