Skip to content

Commit

Permalink
go
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Reider committed Dec 16, 2024
1 parent 4076b98 commit 1d81d6c
Show file tree
Hide file tree
Showing 9 changed files with 445 additions and 3 deletions.
4 changes: 3 additions & 1 deletion config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
url = "https://mreider.github.io/krems/"
css = "cactus.css"
css = "styles.css"
quacker = false

68 changes: 68 additions & 0 deletions krems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,73 @@ def generate_header(base_url, front_matter)
"<li class='nav-item'><a class='nav-link' href='#{absolute_path(base_url, formatted_path)}'>#{entry['name']}</a></li>"
end.join

quacker_enabled = File.exist?(CONFIG_FILE) && TomlRB.load_file(CONFIG_FILE)['quacker'] == true
subscription_form = ""
if quacker_enabled
subscription_form = <<~HTML
<form id="subscription-form" class="d-flex ms-auto">
<input type="email" name="email" required placeholder="Enter your email" class="form-control me-2">
<button type="submit" class="btn btn-primary">Subscribe</button>
</form>
<p id="status-message" class="ms-auto mt-2 text-success" style="display: none;"></p>
<script>
const form = document.getElementById("subscription-form");
const statusMessage = document.getElementById("status-message");
const checkSubscriptionStatus = async (email) => {
const url = "https://quacker.eu/subscribe/1?email=" + encodeURIComponent(email);
try {
const response = await fetch(url);
if (response.ok) {
const data = await response.json();
return data.is_subscribed;
}
} catch (error) {
console.error("Error checking subscription status:", error);
}
return false;
};
form.addEventListener("submit", async (e) => {
e.preventDefault();
const emailInput = form.querySelector('input[name="email"]');
const button = form.querySelector("button");
const email = emailInput.value;
button.textContent = "Please wait...";
button.disabled = true;
emailInput.disabled = true;
try {
const isSubscribed = await checkSubscriptionStatus(email);
if (isSubscribed) {
form.style.display = "none";
statusMessage.style.display = "block";
statusMessage.textContent = "Already subscribed!";
return;
}
const url = "https://quacker.eu/subscribe/1";
const response = await fetch(url, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ email })
});
if (response.ok) {
form.style.display = "none";
statusMessage.style.display = "block";
statusMessage.textContent = "Subscribed successfully!";
} else {
form.style.display = "none";
statusMessage.style.display = "block";
statusMessage.textContent = "Something went wrong. Please try again later.";
}
} catch (error) {
console.error("Error submitting form:", error);
form.style.display = "none";
statusMessage.style.display = "block";
statusMessage.textContent = "Something went wrong. Please try again later.";
}
});
</script>
HTML
end

<<~HTML
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
Expand All @@ -187,6 +254,7 @@ def generate_header(base_url, front_matter)
<ul class="navbar-nav">
#{nav_links}
</ul>
#{subscription_form}
</div>
</div>
</nav>
Expand Down
62 changes: 62 additions & 0 deletions published/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,68 @@
<ul class="navbar-nav">
<li class='nav-item'><a class='nav-link' href='http://127.0.0.1:4567/index.html'>Home</a></li><li class='nav-item'><a class='nav-link' href='http://127.0.0.1:4567/example/post1.html'>First Post</a></li>
</ul>
<form id="subscription-form" class="d-flex ms-auto">
<label for="email" class="me-2">Subscribe:</label>
<input type="email" name="email" required placeholder="Enter your email" class="form-control me-2">
<button type="submit" class="btn btn-primary">Subscribe</button>
</form>
<p id="status-message" class="ms-auto mt-2 text-success" style="display: none;"></p>
<script>
const form = document.getElementById("subscription-form");
const statusMessage = document.getElementById("status-message");
const checkSubscriptionStatus = async (email) => {
const url = "https://quacker.eu/subscribe/1?email=" + encodeURIComponent(email);
try {
const response = await fetch(url);
if (response.ok) {
const data = await response.json();
return data.is_subscribed;
}
} catch (error) {
console.error("Error checking subscription status:", error);
}
return false;
};
form.addEventListener("submit", async (e) => {
e.preventDefault();
const emailInput = form.querySelector('input[name="email"]');
const button = form.querySelector("button");
const email = emailInput.value;
button.textContent = "Please wait...";
button.disabled = true;
emailInput.disabled = true;
try {
const isSubscribed = await checkSubscriptionStatus(email);
if (isSubscribed) {
form.style.display = "none";
statusMessage.style.display = "block";
statusMessage.textContent = "Already subscribed!";
return;
}
const url = "https://quacker.eu/subscribe/1";
const response = await fetch(url, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ email })
});
if (response.ok) {
form.style.display = "none";
statusMessage.style.display = "block";
statusMessage.textContent = "Subscribed successfully!";
} else {
form.style.display = "none";
statusMessage.style.display = "block";
statusMessage.textContent = "Something went wrong. Please try again later.";
}
} catch (error) {
console.error("Error submitting form:", error);
form.style.display = "none";
statusMessage.style.display = "block";
statusMessage.textContent = "Something went wrong. Please try again later.";
}
});
</script>

</div>
</div>
</nav>
Expand Down
4 changes: 2 additions & 2 deletions published/css/styles.css

Large diffs are not rendered by default.

62 changes: 62 additions & 0 deletions published/example/post1.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,68 @@
<ul class="navbar-nav">
<li class='nav-item'><a class='nav-link' href='http://127.0.0.1:4567/index.html'>Home</a></li><li class='nav-item'><a class='nav-link' href='http://127.0.0.1:4567/example/post1.html'>First Post</a></li>
</ul>
<form id="subscription-form" class="d-flex ms-auto">
<label for="email" class="me-2">Subscribe:</label>
<input type="email" name="email" required placeholder="Enter your email" class="form-control me-2">
<button type="submit" class="btn btn-primary">Subscribe</button>
</form>
<p id="status-message" class="ms-auto mt-2 text-success" style="display: none;"></p>
<script>
const form = document.getElementById("subscription-form");
const statusMessage = document.getElementById("status-message");
const checkSubscriptionStatus = async (email) => {
const url = "https://quacker.eu/subscribe/1?email=" + encodeURIComponent(email);
try {
const response = await fetch(url);
if (response.ok) {
const data = await response.json();
return data.is_subscribed;
}
} catch (error) {
console.error("Error checking subscription status:", error);
}
return false;
};
form.addEventListener("submit", async (e) => {
e.preventDefault();
const emailInput = form.querySelector('input[name="email"]');
const button = form.querySelector("button");
const email = emailInput.value;
button.textContent = "Please wait...";
button.disabled = true;
emailInput.disabled = true;
try {
const isSubscribed = await checkSubscriptionStatus(email);
if (isSubscribed) {
form.style.display = "none";
statusMessage.style.display = "block";
statusMessage.textContent = "Already subscribed!";
return;
}
const url = "https://quacker.eu/subscribe/1";
const response = await fetch(url, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ email })
});
if (response.ok) {
form.style.display = "none";
statusMessage.style.display = "block";
statusMessage.textContent = "Subscribed successfully!";
} else {
form.style.display = "none";
statusMessage.style.display = "block";
statusMessage.textContent = "Something went wrong. Please try again later.";
}
} catch (error) {
console.error("Error submitting form:", error);
form.style.display = "none";
statusMessage.style.display = "block";
statusMessage.textContent = "Something went wrong. Please try again later.";
}
});
</script>

</div>
</div>
</nav>
Expand Down
62 changes: 62 additions & 0 deletions published/example/post2.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,68 @@
<ul class="navbar-nav">
<li class='nav-item'><a class='nav-link' href='http://127.0.0.1:4567/index.html'>Home</a></li><li class='nav-item'><a class='nav-link' href='http://127.0.0.1:4567/example/post1.html'>First Post</a></li>
</ul>
<form id="subscription-form" class="d-flex ms-auto">
<label for="email" class="me-2">Subscribe:</label>
<input type="email" name="email" required placeholder="Enter your email" class="form-control me-2">
<button type="submit" class="btn btn-primary">Subscribe</button>
</form>
<p id="status-message" class="ms-auto mt-2 text-success" style="display: none;"></p>
<script>
const form = document.getElementById("subscription-form");
const statusMessage = document.getElementById("status-message");
const checkSubscriptionStatus = async (email) => {
const url = "https://quacker.eu/subscribe/1?email=" + encodeURIComponent(email);
try {
const response = await fetch(url);
if (response.ok) {
const data = await response.json();
return data.is_subscribed;
}
} catch (error) {
console.error("Error checking subscription status:", error);
}
return false;
};
form.addEventListener("submit", async (e) => {
e.preventDefault();
const emailInput = form.querySelector('input[name="email"]');
const button = form.querySelector("button");
const email = emailInput.value;
button.textContent = "Please wait...";
button.disabled = true;
emailInput.disabled = true;
try {
const isSubscribed = await checkSubscriptionStatus(email);
if (isSubscribed) {
form.style.display = "none";
statusMessage.style.display = "block";
statusMessage.textContent = "Already subscribed!";
return;
}
const url = "https://quacker.eu/subscribe/1";
const response = await fetch(url, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ email })
});
if (response.ok) {
form.style.display = "none";
statusMessage.style.display = "block";
statusMessage.textContent = "Subscribed successfully!";
} else {
form.style.display = "none";
statusMessage.style.display = "block";
statusMessage.textContent = "Something went wrong. Please try again later.";
}
} catch (error) {
console.error("Error submitting form:", error);
form.style.display = "none";
statusMessage.style.display = "block";
statusMessage.textContent = "Something went wrong. Please try again later.";
}
});
</script>

</div>
</div>
</nav>
Expand Down
62 changes: 62 additions & 0 deletions published/fun/everything-animal.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,68 @@
<ul class="navbar-nav">
<li class='nav-item'><a class='nav-link' href='http://127.0.0.1:4567/index.html'>Home</a></li><li class='nav-item'><a class='nav-link' href='http://127.0.0.1:4567/example/post1.html'>First Post</a></li>
</ul>
<form id="subscription-form" class="d-flex ms-auto">
<label for="email" class="me-2">Subscribe:</label>
<input type="email" name="email" required placeholder="Enter your email" class="form-control me-2">
<button type="submit" class="btn btn-primary">Subscribe</button>
</form>
<p id="status-message" class="ms-auto mt-2 text-success" style="display: none;"></p>
<script>
const form = document.getElementById("subscription-form");
const statusMessage = document.getElementById("status-message");
const checkSubscriptionStatus = async (email) => {
const url = "https://quacker.eu/subscribe/1?email=" + encodeURIComponent(email);
try {
const response = await fetch(url);
if (response.ok) {
const data = await response.json();
return data.is_subscribed;
}
} catch (error) {
console.error("Error checking subscription status:", error);
}
return false;
};
form.addEventListener("submit", async (e) => {
e.preventDefault();
const emailInput = form.querySelector('input[name="email"]');
const button = form.querySelector("button");
const email = emailInput.value;
button.textContent = "Please wait...";
button.disabled = true;
emailInput.disabled = true;
try {
const isSubscribed = await checkSubscriptionStatus(email);
if (isSubscribed) {
form.style.display = "none";
statusMessage.style.display = "block";
statusMessage.textContent = "Already subscribed!";
return;
}
const url = "https://quacker.eu/subscribe/1";
const response = await fetch(url, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ email })
});
if (response.ok) {
form.style.display = "none";
statusMessage.style.display = "block";
statusMessage.textContent = "Subscribed successfully!";
} else {
form.style.display = "none";
statusMessage.style.display = "block";
statusMessage.textContent = "Something went wrong. Please try again later.";
}
} catch (error) {
console.error("Error submitting form:", error);
form.style.display = "none";
statusMessage.style.display = "block";
statusMessage.textContent = "Something went wrong. Please try again later.";
}
});
</script>

</div>
</div>
</nav>
Expand Down
Loading

0 comments on commit 1d81d6c

Please sign in to comment.