From 2bf34ed62434e1a4cc7077092b646678e4fe1e76 Mon Sep 17 00:00:00 2001 From: "theis.gaedigk" Date: Sat, 14 Jun 2025 15:29:53 +0200 Subject: [PATCH] Update Home --- Home.md | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/Home.md b/Home.md index 338b6fb..0692ea5 100644 --- a/Home.md +++ b/Home.md @@ -22,9 +22,49 @@ Then this window should pop up ![image](https://git.the1s.de/theis.gaedigk/Cookb In this window, you can type everything you want! ## How to delete recipes? +Currently there exists no way to delete recipes via an UI. +But you can delete recipes by deleting the recipe file. These files can you find in the recipes directory. To go in that directory you must open the Cookbook folder then go through these directorys: ```backend --> database --> recipes``` or ```/backend/database/recipes```. + +In this directory you can find all of the recipes that you have created. They are all stored in ```.txt``` files. ## How to load recipes? +To load recipes, simply click on ![image](https://git.the1s.de/theis.gaedigk/Cookbook/src/branch/imgs/img/sync.png) +## How to edit recipes? +Unfortunatly, there is no UI for editing recipies yet. -## How to edit recipes? \ No newline at end of file +But you can edit your recipes, by going in to the recipes directory. To go in that directory you must open the Cookbook folder then go through these directorys: ```backend --> database --> recipes``` or ```/backend/database/recipes```. + +There you will find all of your recipes stored in different ```.txt``` files. The title of your recipe will always be the filename of the ```.txt``` file. The content of your recipes is of course in the ```.txt``` file. + +### For instance, here is the model to load the recipes. +[Extract from ```server.js```]([url](https://git.the1s.de/theis.gaedigk/Cookbook/src/branch/main/backend/server.js)) (there is more code below and before): +```js +app.get("/", (req, res) => { + // sync recipes + const recipesFolder = path.join(basePath, "database", "recipes"); + + if (!fs.existsSync(recipesFolder)) { + fs.mkdirSync(recipesFolder, { recursive: true }); + } + + fs.readdir(recipesFolder, (err, files) => { + if (err) { + return res.status(500).send("Error by reading recipe files!"); + } + + const txtFiles = files.filter((file) => file.endsWith(".txt")); + + const recipes = txtFiles.map((file) => { + const content = fs.readFileSync(path.join(recipesFolder, file), "utf8"); + return { + title: path.basename(file, ".txt"), + content: marked.parse(content), + }; + }); + + res.render("index", { recipes }); + }); +}); +``` \ No newline at end of file