Skip to content

Commit

Permalink
fix noscript fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
SapiensAnatis committed Jun 7, 2024
1 parent dd5a817 commit 07e32b4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
14 changes: 10 additions & 4 deletions MaintenanceWorker/src/web/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::shared::CloudflareVariables;
use time::{format_description::well_known::Iso8601, macros::format_description};
use time::macros::format_description;
use worker::*;

static PAGE_HTML: &str = include_str!("page.html");

pub fn get_html(
req: Request,
_req: Request,
_ctx: RouteContext<()>,
vars: CloudflareVariables,
) -> Result<Response> {
Expand All @@ -21,14 +21,20 @@ pub fn get_html(
}

fn format_html_with_date(vars: CloudflareVariables) -> std::result::Result<String, &'static str> {
let Ok(formatted_date) = vars.end_date.format(&Iso8601::DEFAULT) else {
let Ok(formatted_date) = vars.end_date.format(format_description!(
"[day]/[month]/[year] [hour]:[minute]:[second] +[offset_hour]:[offset_minute]"
)) else {
return Err("Failed to format parsed end date");
};

let final_html = PAGE_HTML
.replace("{{ title }}", &vars.title)
.replace("{{ body }}", &vars.body)
.replace("{{ end_date }}", &formatted_date);
.replace("{{ end_date }}", &formatted_date)
.replace(
"{{ timestamp }}",
&vars.end_date.unix_timestamp().to_string(),
);

return Ok(final_html);
}
10 changes: 6 additions & 4 deletions MaintenanceWorker/src/web/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,12 @@
return;
}

console.log(dateElement.textContent);
const timestamp = dateElement.getAttribute("data-timestamp");
if (!timestamp) {
return;
}

const dateObj = new Date(dateElement.textContent);
const dateObj = new Date(timestamp * 1000);
document.getElementById("date").textContent = dateObj.toLocaleString(undefined, {
dateStyle: "medium",
timeStyle: "medium"
Expand All @@ -94,8 +97,7 @@ <h1 class="title">{{ title }}</h1>
<br />
<div class="end-time">
<h2>Expected end time:</h2>
<p id="date" class="text">{{ end_date }}</p>
<p id="date-placeholder"></p>
<p id="date" class="text" data-timestamp="{{ timestamp }}">{{ end_date }}</p>
</div>
</div>
</body>
Expand Down

0 comments on commit 07e32b4

Please sign in to comment.