Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a random recipe button #919

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions content/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ layout: single

## What do you want to cook?

<div class="search js-only">
<input type="text" id="search" placeholder="Search ALL Recipes...">
<button id="clear-search">
<svg xmlns="http://www.w3.org/2000/svg" class="ionicon" viewBox="0 0 512 512"><title>Backspace</title><path d="M135.19 390.14a28.79 28.79 0 0021.68 9.86h246.26A29 29 0 00432 371.13V140.87A29 29 0 00403.13 112H156.87a28.84 28.84 0 00-21.67 9.84v0L46.33 256l88.86 134.11z" fill="none" stroke="currentColor" stroke-linejoin="round" stroke-width="32"></path><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M336.67 192.33L206.66 322.34M336.67 322.34L206.66 192.33M336.67 192.33L206.66 322.34M336.67 322.34L206.66 192.33"></path></svg>
<div class="search-container js-only">
<div class="search">
<input type="text" id="search" placeholder="Search ALL Recipes...">
<button id="clear-search">
<svg xmlns="http://www.w3.org/2000/svg" class="ionicon" viewBox="0 0 512 512"><title>Backspace</title><path d="M135.19 390.14a28.79 28.79 0 0021.68 9.86h246.26A29 29 0 00432 371.13V140.87A29 29 0 00403.13 112H156.87a28.84 28.84 0 00-21.67 9.84v0L46.33 256l88.86 134.11z" fill="none" stroke="currentColor" stroke-linejoin="round" stroke-width="32"></path><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M336.67 192.33L206.66 322.34M336.67 322.34L206.66 192.33M336.67 192.33L206.66 322.34M336.67 322.34L206.66 192.33"></path></svg>
</button>
</div>
<button id="random">
Random
</button>
</div>

Expand All @@ -26,6 +31,13 @@ document.addEventListener("DOMContentLoaded", () => {
const oldheading = document.getElementById("newest-recipes");
const clearSearch = document.getElementById("clear-search");
const artlist = document.getElementById("artlist");
const random = document.getElementById("random");

random.addEventListener("click", () => {
const recipe = recipes[Math.floor(Math.random() * recipes.length)];
const url = recipe.getElementsByTagName("a")[0].href
window.location.href = url;
})

search.addEventListener("input", () => {
// grab search input value
Expand Down
23 changes: 22 additions & 1 deletion static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,19 @@ input#search {
width: 100%;
}

.search {
.search-container {
width: 400px;
max-width: 85vw;
position: relative;
margin: 0.5rem auto 1.2rem;
display: flex;
gap: .5rem;
}

.search {
position: relative;
display: flex;
flex-grow: 1;
}

button#clear-search {
Expand All @@ -169,6 +176,20 @@ button#clear-search:hover {
color: #eee;
}

button#random {
all: unset;
background: #222;
color: #888;
border-radius: 5px;
padding: .7rem 1rem;
height: 100%;
cursor: pointer;
transition: color 180ms ease-in-out;
}

button#random:hover {
color: #eee;
}

.matched-recipe {
font-size: x-large ;
Expand Down