Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/HananoshikaYomaru/Obsidian-Frontmatter-Generator
A plugin for Obsidian that generates frontmatter for notes
https://github.com/HananoshikaYomaru/Obsidian-Frontmatter-Generator
Last synced: 2 months ago
JSON representation
A plugin for Obsidian that generates frontmatter for notes
- Host: GitHub
- URL: https://github.com/HananoshikaYomaru/Obsidian-Frontmatter-Generator
- Owner: HananoshikaYomaru
- License: mit
- Created: 2023-09-27T05:15:10.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-11-30T17:01:17.000Z (about 1 year ago)
- Last Synced: 2024-08-08T00:44:36.042Z (6 months ago)
- Language: TypeScript
- Size: 210 KB
- Stars: 28
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- project-awesome - HananoshikaYomaru/Obsidian-Frontmatter-Generator - A plugin for Obsidian that generates frontmatter for notes (TypeScript)
- jimsghstars - HananoshikaYomaru/Obsidian-Frontmatter-Generator - A plugin for Obsidian that generates frontmatter for notes (TypeScript)
README
# Obsidian frontmatter generator
Generate your frontmatter on save.
✅ Powerful, dead simple
## Usage
1. after install the plugin, visit the setting of the plugin
2. change the frontmatter templatefor example, the following frontmatter template
```ts
{
folder: file.parent.path,
title: file.basename,
test: ["1", "2"]
}
```will generate this in the file `Good recipes/scrambled egg.md` on save.
```yaml
folder: Good recipes
title: scrambled egg
test:
- '1'
- '2'
```3. install [obsidian-custom-save](https://github.com/HananoshikaYomaru/obsidian-custom-save) and add the `frontmatter-generator: run file` command to the custom save actions
- Basic Demo:
- Tag properties demo:## Advanced usage
### conditional expression
```ts
file.properties?.type === 'kanban'
? {
folder: file.parent.path,
title: file.basename
}
: {}
```### function
```ts
{
test: (() => {
return { test: 'test' }
})()
}
```### Dataview
```ts
{
numberOfPages: dv.pages('#ai').length
}
```## Syntax of the frontmatter template
It could be a json or a javascript expression that return an object.
![](https://share.cleanshot.com/nfW5nV8L+)
^ even functions work
## Variable that it can access
- `file`, the [`TFile`](https://docs.obsidian.md/Reference/TypeScript+API/TFile/TFile) object
- `file.properties` will access the yaml object of the current file
- `file.tags` , a `string[]` which will access the tags of the current file. For example `["#book", "#movie"]`
- `dv`, the [dataview](https://blacksmithgu.github.io/obsidian-dataview/) object (you can only access this if you install and enable the dataview plugin)
- `z`, the zod object## Installation
### Install on obsidian plugin marketplace
You can find it on obsidian plugin marketplace.
### Manual Install
1. cd to `.obsidian/plugins`
2. git clone this repo
3. `cd obsidian-frontmatter-generator && bun install && bun run build`
4. there you go 🎉## Note
1. to stop generate on a file, you can put `yaml-gen-ignore: true` on the frontmatter. You can also ignore the whole folder in the seting.
2. the context that you can access is [TFile](https://docs.obsidian.md/Reference/TypeScript+API/TFile/TFile). This can be update in the future. It is extremely flexible.
3. This plugin also comes with some command to run in folder and in the whole vault.
4. If you want to contribute, first open an issue.
5. 🚨 This plugin is still under development, don't try to hack it by using weird keywords or accessing global variables in the template. It should not work but if you figure out a way to hack it, it will just break your own vault.