generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from tmayoff/small_tweaks
- Loading branch information
Showing
8 changed files
with
84 additions
and
208 deletions.
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
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
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,32 +1,34 @@ | ||
import { TFile, type TFolder } from "obsidian"; | ||
import type { Ingredient } from "parse-ingredient"; | ||
import { get_ingredients } from "./ingredients"; | ||
import { TFile, type TFolder } from 'obsidian'; | ||
import type { Ingredient } from 'parse-ingredient'; | ||
import { get_ingredients } from './ingredients'; | ||
|
||
export class Recipe { | ||
name: string; | ||
path: TFile; | ||
name: string; | ||
path: TFile; | ||
|
||
ingredients: Ingredient[]; | ||
ingredients: Ingredient[]; | ||
|
||
constructor(path: TFile, name: string = path.basename) { | ||
this.path = path; | ||
this.name = name; | ||
this.ingredients = new Array(); | ||
} | ||
constructor(path: TFile, name: string = path.basename) { | ||
this.path = path; | ||
this.name = name; | ||
this.ingredients = new Array(); | ||
} | ||
|
||
public async fill_ingredients() { | ||
this.ingredients = await get_ingredients(this.path); | ||
} | ||
public async fill_ingredients() { | ||
this.ingredients = await get_ingredients(this.path); | ||
} | ||
} | ||
|
||
export async function get_recipes(recipe_dir: TFolder) { | ||
const recipes: Recipe[] = new Array(); | ||
const recipes: Recipe[] = new Array(); | ||
|
||
for (const file of recipe_dir.children) { | ||
const recipe = new Recipe(file); | ||
await recipe.fill_ingredients(); | ||
recipes.push(recipe); | ||
for (const file of recipe_dir.children) { | ||
if (file instanceof TFile) { | ||
const recipe = new Recipe(file); | ||
await recipe.fill_ingredients(); | ||
recipes.push(recipe); | ||
} | ||
} | ||
|
||
return recipes; | ||
return recipes; | ||
} |
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,34 @@ | ||
import { TFile, type App } from 'obsidian'; | ||
|
||
export async function open_note_file(app: App, file: TFile) { | ||
open_note_path(app, file.path); | ||
} | ||
|
||
export async function open_note_path(app: App, file_path: string) { | ||
let found = false; | ||
|
||
const file_name = file_path.substring(file_path.lastIndexOf('/') + 1, file_path.lastIndexOf('.')); | ||
app.workspace.iterateAllLeaves((leaf) => { | ||
if (leaf.getDisplayText() === file_name) { | ||
app.workspace.setActiveLeaf(leaf); | ||
found = true; | ||
} | ||
}); | ||
|
||
if (!found) { | ||
await app.workspace.openLinkText(file_path, '', true); | ||
} | ||
} | ||
|
||
export function note_exists(app: App, file_path: string) { | ||
const file = app.vault.getAbstractFileByPath(file_path); | ||
return file != null && file instanceof TFile; | ||
} | ||
|
||
export function append_markdown_ext(file_path: string) { | ||
if (!file_path.endsWith('.md')) { | ||
file_path += '.md'; | ||
} | ||
|
||
return file_path; | ||
} |
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 @@ | ||
workspace.json |
This file was deleted.
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