Files
2026-07-14 08:05:36 -07:00

1.9 KiB

<%* const recipeName = await tp.system.prompt("Enter Recipe Name", "New Recipe"); const meal = await tp.system.prompt("Enter Primary Meal Type", "Dinner"); if (!recipeName){ return; } if (!meal){ return; }

allTags = [];

const meals = [];
let newMeal;
while (
	newMeal = await tp.system.prompt("Enter additional meal (or leave blank to finish)")) {
		meals.push(newMeal.toLowerCase().replace(/\s+/g, '_'));
	};
formatedMeals = meals.map(meal => ` - ${meal}`).join('\n')

const cuisine = await tp.system.prompt("Enter cuisine type", "American");

const prepTime = await tp.system.prompt("Enter Prep Time (in hours and minutes)", "10 mins");
const cookTime = await tp.system.prompt("Enter Cook Time (in hours and minutes)", "10 mins");
const serves = await tp.system.prompt("Enter number of people served", "2");

let newTag; 
while (
	newTag = await tp.system.prompt("Enter a tag (or leave blank to finish)")) {
		allTags.push(newTag.toLowerCase().replace(/\s+/g, '_'));
	}

const tagsYAML = allTags.map(tag => ` - ${tag}`).join('\n');

sanitizedName = recipeName.toLowerCase().replace(/\s+/g, '_');
const recipeFolder = "Recipes";

const pageContent = `---

tags:

  • recipe ${tagsYAML} meals:
  • ${meal} ${formatedMeals} cuisine: ${cuisine} rating: 0 meal_prep_item: false prep_time: ${prepTime} cook_time: ${cookTime} serves: ${serves} created_date: ${tp.date.now("YYYY-MM-DD")}

${recipeName}

Prep Time Cook Time Serves
${prepTime} ${cookTime} ${serves}

Ingredients

Steps

`;

const newFilePath = `${recipeFolder}/${sanitizedName}.md`;
const newFile = await this.app.vault.create(newFilePath, pageContent);
await this.app.workspace.openLinkText(newFile.path, "", true); 
const currentFile = tp.file.config.target_file; 
await tp.sleep(100); 
await this.app.vault.delete(currentFile);

%>