Update Home
42
Home.md
42
Home.md
@@ -22,9 +22,49 @@ Then this window should pop up 
|
||||
|
||||
## How to edit recipes?
|
||||
Unfortunatly, there is no UI for editing recipies yet.
|
||||
|
||||
## How to edit recipes?
|
||||
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 });
|
||||
});
|
||||
});
|
||||
```
|
Reference in New Issue
Block a user