obsidian-dev-utils
Version:
This is the collection of useful functions that you can use for your Obsidian plugin development
75 lines (74 loc) • 2.15 kB
text/typescript
/**
* @packageDocumentation
*
* This module provides utility functions for processing and managing YAML front matter in Obsidian notes.
*/
import type { GenericObject } from '../ObjectUtils.cjs';
/**
* A combined front matter of a document.
* It is a union of custom front matter, Obsidian front matter, and additional properties.
*
* @typeParam CustomFrontmatter - The type of custom front matter.
*/
export type CombinedFrontmatter<CustomFrontmatter> = CustomFrontmatter & GenericObject & ObsidianFrontmatter;
/**
* A front matter of an Obsidian file.
*
* @see {@link https://help.obsidian.md/Editing+and+formatting/Properties#Default+properties}
*/
export interface ObsidianFrontmatter {
/**
* An array of aliases for the note.
*/
aliases?: string[];
/**
* An array of CSS classes to apply to the note.
*/
cssclasses?: string[];
/**
* An array of tags for the note.
*/
tags?: string[];
}
/**
* A front matter for publishing in Obsidian.
*
* @see {@link https://help.obsidian.md/Editing+and+formatting/Properties#Properties+for+Obsidian+Publish}
*/
export interface ObsidianPublishFrontmatter {
/**
* A cover image for the note.
*/
cover?: string;
/**
* A description for the note.
*/
description?: string;
/**
* An image for the note.
*/
image?: string;
/**
* A permanent link for the note.
*/
permalink?: string;
/**
* Whether the note is published.
*/
publish?: boolean;
}
/**
* Parses the front matter of a given content string.
*
* @param content - The content string to parse.
* @returns The parsed front matter.
*/
export declare function parseFrontmatter<CustomFrontmatter = unknown>(content: string): CombinedFrontmatter<CustomFrontmatter>;
/**
* Sets the front matter of a given content string.
*
* @param content - The content string to set the front matter in.
* @param newFrontmatter - The new front matter to set.
* @returns The new content string with the front matter set.
*/
export declare function setFrontmatter(content: string, newFrontmatter: object): string;