design min and cms fix

master
km0 3 years ago
parent a96de97410
commit aaf03f8910

122
cms.js

@ -1,86 +1,84 @@
const cookbook = document.getElementById("cookbook");
const cookbookInfo = document.getElementById("cookbookInfo");
fetch("./cms.json")
.then((response) => {
return response.json();
})
.then((data) => populateContents(data));
.then((data) => {
populateContents(data);
recipesInfo(data.recipes);
});
function populateContents(data) {
data.recipes.forEach((recipe) => addRecipe(recipe));
}
function addRecipe(recipe) {
let card = document.createElement('div')
card.classList.add('recipe')
let card = document.createElement("div");
card.classList.add("recipe");
// INFO
let info = document.createElement('div')
info.classList.add('info')
card.appendChild(info)
let title = document.createElement('h2')
title.classList.add('title')
title.innerHTML = recipe.title //si prende recipe come contenitore e ci butta dentro title
info.appendChild(title) //aggiungi title alle info
let info = document.createElement("div");
info.classList.add("info");
card.appendChild(info);
let description = document.createElement('div')
description.classList.add('description')
description.innerHTML = recipe.description
info.appendChild(description)
let title = document.createElement("h2");
title.classList.add("title");
title.innerHTML = recipe.title; //si prende recipe come contenitore e ci butta dentro title
info.appendChild(title); //aggiungi title alle info
let chef = document.createElement('div')
chef.classList.add('chef')
chef.innerHTML = recipe.chef
info.appendChild(chef)
let description = document.createElement("div");
description.classList.add("description");
description.innerHTML = recipe.description;
info.appendChild(description);
let chef = document.createElement("div");
chef.classList.add("chef");
chef.innerHTML = recipe.chef;
info.appendChild(chef);
// INGREDIENTS
let ingredients = document.createElement('div')
let ingredientsTitle = document.createElement('h3')
ingredientsTitle.innerHTML = 'Ingredients'
ingredients.appendChild(ingredientsTitle)
let ingredientsList = document.createElement('ul')
recipe.ingredients.forEach(item => {
let ingredient = document.createElement('li')
ingredient.innerHTML = item
ingredientsList.appendChild(ingredient)
})
ingredients.appendChild(ingredientsList)
card.appendChild(ingredients)
let ingredients = document.createElement("div");
ingredients.classList.add("ingredients");
let ingredientsTitle = document.createElement("h3");
ingredientsTitle.innerHTML = "Ingredients";
ingredients.appendChild(ingredientsTitle);
let ingredientsList = document.createElement("ul");
recipe.ingredients.forEach((item) => {
let ingredient = document.createElement("li");
ingredient.innerHTML = item;
ingredientsList.appendChild(ingredient);
});
ingredients.appendChild(ingredientsList);
card.appendChild(ingredients);
// INSTRUCTIONS
let instructions = document.createElement('div')
let instructionsTitle = document.createElement('h3')
instructionsTitle.innerHTML = 'Instructions'
instructions.appendChild(instructionsTitle)
let instructionsList = document.createElement('ol')
recipe.instructions.forEach(item => {
let instruction = document.createElement('li')
instruction.innerHTML = item
instructionsList.appendChild(instruction)
})
instructions.appendChild(instructionsList)
card.appendChild(instructions)
cookbook.appendChild(card)
let instructions = document.createElement("div");
instructions.classList.add("instructions");
let instructionsTitle = document.createElement("h3");
instructionsTitle.innerHTML = "Instructions";
instructions.appendChild(instructionsTitle);
let instructionsList = document.createElement("ol");
recipe.instructions.forEach((item) => {
let instruction = document.createElement("li");
instruction.innerHTML = item;
instructionsList.appendChild(instruction);
});
instructions.appendChild(instructionsList);
card.appendChild(instructions);
cookbook.appendChild(card);
}
function recipesInfo(recipes) {
let ingredients = [];
recipes.forEach((recipe) => (ingredients = [...ingredients, ...recipe.ingredients]));
let unique = [...new Set(ingredients)];
cookbookInfo.innerHTML = `There are ${recipes.length} recipes in the cookbook, with a total of ${unique.length} different ingredients`;
}

@ -27,7 +27,7 @@
"🍗",
"🍚",
"funghetti",
"🍠",
"🍉",
"🥗"
],
"instructions": [

@ -1,67 +1,68 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css" />
<script src="cms.js" defer></script>
<title>🥣</title>
</head>
<body>
</head>
<body>
<div class="intro">
<div class="description">
<h1>Soup Generator</h1>
each soup has:
1. a title <br>
2. a list of ingredients <br>
3. a list of instructions <br>
4. a chef <br>
5. an image ? TODO ? ahah <br>
<br>
so we haveee:
<br>
name is a string
ingredients are an array of strings
recipe is an array of strings (first this, second this, third this, ecc)
and the chef (usually who upload the recipe) is a string again ? or maybe we can avoid this? idk is funny
<br>
ask to michael: what is the best solution to add images??
</div>
<div class="cookbook" id="cookbook">
<!-- structure of the recipes -->
<!-- <div class="recipe">
<div class="recipe">
<div class="info">
<h2 class="title">Soup name</h2>
<div class="description">Incididunt Lorem magna cillum aliquip laborum nisi anim eu.</div>
<div class="chef">giraffa anonima</div>
<h2 class="title">A. Title [string]</h2>
<div class="description">B. Description [string]</div>
<div class="chef">C. Chef [string]</div>
</div>
<div class="ingredients">
<h3>Ingredients</h3>
<h3>D. List of ingredients [array of strings]</h3>
<ul>
<li>First ingredient</li>
<li>Second ingredient</li>
</ul>
</div>
<div class="instructions">
<h3>Instructions</h3>
<h3>E. List of instructions [array of strings]</h3>
<ol>
<li>First instruction</li>
<li>Second instruction</li>
</ol>
</div>
</div> -->
</div>
<div class="todo">
<ul>
<em>TODO short term:</em>
<li>💻 Receive recipe as a form ?</li>
<li>🔍 Ingredients list and filter!!! (like chat reader)</li>
<li>💬 Different types of entries for the cms: recipe, diary, ecc.</li>
<li>📷 Add recipe picture ?</li>
<li>🎨 Design</li>
<em>TODO long term:</em>
<li>💾 Better CMS (and not just a JSON file ah ah)</li>
<li>🦥 Recipes lazy loading :P</li>
<li>📔 Web to print design</li>
<li>📃 Soup pagination</li>
</ul>
</div>
</body>
Ask to Michael: what is the best solution to add images??
</div>
<div class="cookbook">
<h2>Soup Gen Cookbook</h2>
<div class="cookbook-info" id="cookbookInfo"></div>
<div class="recipes" id="cookbook"></div>
</div>
</body>
</html>

@ -1,26 +1,84 @@
body{
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
font-size: 1.25rem;
}
.intro {
margin: 16px;
}
.intro .recipe {
border: 1px solid currentColor;
}
h1,
h2,
h3 {
margin: 0;
}
ul,
ol {
padding: 0;
list-style-position: inside;
}
em {
display: block;
margin: 1em 0;
font-weight: bold;
}
/* COOCKBOOK */
.cookbook {
margin: 16px;
padding: 24px;
background-color: #cec;
border-radius: 16px;
}
.cookbook-info {
margin: 16px 0;
font-style: italic;
}
.recipes {
display: flex;
flex-direction: row;
flex-wrap: wrap;
row-gap: 16px;
column-gap: 16px;
}
.recipe {
margin: 16px;
flex: 1;
display: inline-block;
width: 120ch;
border: 1px solid currentColor;
background-color: #ffffff;
width: 80ch;
border-radius: 16px;
padding: 1ch;
}
.recipe .title {
margin-bottom: 8px;
}
.recipe .info {
margin: 16px 0;
}
.recipe .ingredients {
margin: 16px 0;
}
.recipe ul,
.recipe ol {
margin: 0;
}
.intro .recipe {
margin: 16px 0;
}

Loading…
Cancel
Save