Skip to content

Commit

Permalink
feat: Add VaultManifestClient and VaultManifest interfaces
Browse files Browse the repository at this point in the history
- 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
SakuraIsayeki committed Aug 5, 2023
1 parent 695bd1d commit b0cdb60
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 1 deletion.
38 changes: 38 additions & 0 deletions nodsoft_moltenobsidian_ssg_client/manifest-client.ts
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
) { }
}
12 changes: 12 additions & 0 deletions nodsoft_moltenobsidian_ssg_client/package.json
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"
}
}
9 changes: 9 additions & 0 deletions nodsoft_moltenobsidian_ssg_client/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion nodsoft_moltenobsidian_ssg_client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"module": "commonjs", /* Specify what module code is generated. */
// "rootDir": "./", /* Specify the root folder within your source files. */
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
"baseUrl": ".", /* Specify the base directory to resolve non-relative module names. */
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
Expand Down
50 changes: 50 additions & 0 deletions nodsoft_moltenobsidian_ssg_client/vault-manifest.ts
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;
}

0 comments on commit b0cdb60

Please sign in to comment.