Also bundle css with bun so it busts caches
And updates the `build.rs` script so that it also builds a manifest.txt for css files.
This commit is contained in:
9
frontend/js/index.ts
Normal file
9
frontend/js/index.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { Application } from "@hotwired/stimulus";
|
||||
|
||||
import LocalTimeController from "./local_time_controller";
|
||||
|
||||
// import CSS so it gets named with a content hash that busts caches
|
||||
import "../css/styles.css";
|
||||
|
||||
window.Stimulus = Application.start();
|
||||
window.Stimulus.register("local-time", LocalTimeController);
|
||||
28
frontend/js/local_time_controller.ts
Normal file
28
frontend/js/local_time_controller.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { Controller } from "@hotwired/stimulus";
|
||||
|
||||
// Replaces all UTC timestamps with time formated for the local timezone
|
||||
export default class extends Controller {
|
||||
connect() {
|
||||
this.renderLocalTime();
|
||||
}
|
||||
|
||||
renderLocalTime() {
|
||||
this.element.textContent = this.localTimeString;
|
||||
}
|
||||
|
||||
get localTimeString(): string {
|
||||
if (this.utcTime) {
|
||||
return this.utcTime.toLocaleDateString(window.navigator.language, {
|
||||
year: "numeric",
|
||||
month: "long",
|
||||
day: "numeric",
|
||||
});
|
||||
}
|
||||
return "Unknown datetime"
|
||||
}
|
||||
|
||||
get utcTime(): Date | null {
|
||||
const utcString = this.element.getAttribute("datetime");
|
||||
return utcString ? new Date(utcString) : null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user