Skip to content

Commit 514bd7d

Browse files
committed
adding wasm to webpage
1 parent 13a09bf commit 514bd7d

12 files changed

+135
-41
lines changed
27.2 KB
Binary file not shown.

files/main.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
<!-- End of Toast -->
5959

6060
<div id="daBod">
61-
<p class="mt-5 fs-5">Hello there! Welcome to my little nook. This page is a work in progress...</p>
61+
<p class="mt-5 fs-5">Hello there! Welcome to my little nook. This page is a work in progress... over-engineered using TypeScript and WASM.</p>
6262
<p class="t-5 fs-5">My name is Dan: I am a dad, a software development engineer, a lifelong learner,
6363
and a service member in the US Armed Forces.</p>
6464
<p class="mt-5 fs-5">I am a full stack developer with a heavier emphasis in the back-end and data science.</p>
@@ -83,6 +83,10 @@
8383
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/39/Kubernetes_logo_without_workmark.svg/1200px-Kubernetes_logo_without_workmark.svg.png" alt="" width="60" height="60">
8484
Kubernetes
8585
</li>
86+
<li class="list-group-item list-group-item-dark text-truncate">
87+
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/1/1f/WebAssembly_Logo.svg/600px-WebAssembly_Logo.svg.png" alt="" width="60" height="60">
88+
WebAssembly
89+
</li>
8690
<li class="list-group-item list-group-item-dark text-truncate">
8791
<img src="https://cdn4.iconfinder.com/data/icons/logos-and-brands/512/97_Docker_logo_logos-512.png" alt="" width="60" height="60">
8892
Docker
@@ -165,7 +169,7 @@
165169
</div>
166170
<div class="pt-5">
167171
<footer class="d-flex flex-wrap justify-content-between align-items-center py-3 my-4 border-top">
168-
<p class="col-md-4 mb-0 mt-0 text-muted">Last Updated: 2024-01-02</p>
172+
<p class="col-md-4 mb-0 mt-0 text-muted">Last Updated: 2024-02-18</p>
169173
<a href="./files/public-key.pem" class="btn btn-dark">Public Key</a>
170174
</footer>
171175
</div>

src/material.ts

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// import * as $ from "jquery";
2-
import {greeting} from "./time";
3-
import {vidGen} from "./video";
2+
import { greeting } from "./time";
3+
import { vidGen } from "./video";
44
import * as BS from "bootstrap";
55

66
// window.showem = function(iden) {
@@ -12,10 +12,11 @@ import * as BS from "bootstrap";
1212
// let mCollection = new Object;
1313
//
1414
function timer(ms: number) {
15-
return new Promise(resolve => setTimeout(() => resolve(true), ms));
15+
return new Promise(resolve => setTimeout(() => resolve(true), ms));
1616
}
17+
1718
async function startToast(x: number) {
18-
await timer(x);
19+
await timer(x);
1920
let toastLive = document.getElementById('liveToast');
2021
let toastbody = document.querySelector('#liveToast .toast-body');
2122
let toastheader = document.querySelector('#liveToast .me-auto');
@@ -26,24 +27,28 @@ async function startToast(x: number) {
2627
let toast = new BS.Toast(toastLive);
2728
toast.show();
2829
}
30+
31+
vidGen().then(() => {
32+
startToast(5000).then(() => console.log("Toast has launched!"));
33+
});
2934
// async function closeSidebar(x) {
3035
// await timer(x);
3136
// mCollection.sidenav[0].close();
3237
// }
3338
//
34-
document.addEventListener('DOMContentLoaded', function() {
35-
// let elems = [
36-
// document.querySelectorAll('.collapsible'),
37-
// document.querySelectorAll('.tooltipped'),
38-
// document.querySelectorAll('.sidenav'),
39-
// ];
40-
// mCollection.collInst = M.Collapsible.init(elems[0]);
41-
// mCollection.toolInst = M.Tooltip.init(elems[1], {"position": "right"});
42-
// mCollection.sidenav = M.Sidenav.init(elems[2]);
43-
startToast(5000).then(() => console.log("Toast has launched!"));
44-
vidGen();
45-
console.log("STARTING!");
46-
});
39+
// document.addEventListener('DOMContentLoaded', function() {
40+
// // let elems = [
41+
// // document.querySelectorAll('.collapsible'),
42+
// // document.querySelectorAll('.tooltipped'),
43+
// // document.querySelectorAll('.sidenav'),
44+
// // ];
45+
// // mCollection.collInst = M.Collapsible.init(elems[0]);
46+
// // mCollection.toolInst = M.Tooltip.init(elems[1], {"position": "right"});
47+
// // mCollection.sidenav = M.Sidenav.init(elems[2]);
48+
// startToast(5000).then(() => console.log("Toast has launched!"));
49+
// vidGen();
50+
// console.log("STARTING!");
51+
// });
4752
//
4853
// document.querySelector("#menu").addEventListener("click", function() {
4954
// //console.log(this.getAttribute("class"));

src/pweb/.github/dependabot.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: cargo
4+
directory: "/"
5+
schedule:
6+
interval: daily
7+
time: "08:00"
8+
open-pull-requests-limit: 10

src/pweb/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/target
2+
**/*.rs.bk
3+
Cargo.lock
4+
bin/
5+
pkg/
6+
wasm-pack.log

src/pweb/Cargo.toml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[package]
2+
name = "pweb"
3+
version = "0.1.0"
4+
authors = ["Daniel Choi <[email protected]>"]
5+
edition = "2018"
6+
7+
[lib]
8+
crate-type = ["cdylib", "rlib"]
9+
10+
[features]
11+
default = ["console_error_panic_hook"]
12+
13+
[dependencies]
14+
wasm-bindgen = "0.2.84"
15+
16+
# The `console_error_panic_hook` crate provides better debugging of panics by
17+
# logging them with `console.error`. This is great for development, but requires
18+
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
19+
# code size when deploying.
20+
console_error_panic_hook = { version = "0.1.7", optional = true }
21+
chrono = { version = "0.4.34", features = ["wasmbind"] }
22+
23+
[dev-dependencies]
24+
wasm-bindgen-test = "0.3.34"
25+
26+
[profile.release]
27+
# Tell `rustc` to optimize for small code size.
28+
opt-level = "s"

src/pweb/src/lib.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
mod utils;
2+
3+
use chrono::Timelike;
4+
use wasm_bindgen::prelude::*;
5+
6+
#[wasm_bindgen]
7+
pub fn greet() -> String {
8+
utils::set_panic_hook();
9+
10+
let time = chrono::offset::Local::now();
11+
let hour = time.hour();
12+
13+
if (4..12).contains(&hour) {
14+
// morning
15+
"m".to_string()
16+
} else if (12..17).contains(&hour) {
17+
// afternoon
18+
"a".to_string()
19+
} else if (0..4).contains(&hour) {
20+
// evening
21+
"l".to_string()
22+
} else {
23+
// late
24+
"e".to_string()
25+
}
26+
}

src/pweb/src/utils.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
pub fn set_panic_hook() {
2+
// When the `console_error_panic_hook` feature is enabled, we can call the
3+
// `set_panic_hook` function at least once during initialization, and then
4+
// we will get better error messages if our code ever panics.
5+
//
6+
// For more details see
7+
// https://github.com/rustwasm/console_error_panic_hook#readme
8+
#[cfg(feature = "console_error_panic_hook")]
9+
console_error_panic_hook::set_once();
10+
}

src/pweb/tests/web.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//! Test suite for the Web and headless browsers.
2+
3+
#![cfg(target_arch = "wasm32")]
4+
5+
extern crate wasm_bindgen_test;
6+
use wasm_bindgen_test::*;
7+
8+
wasm_bindgen_test_configure!(run_in_browser);
9+
10+
#[wasm_bindgen_test]
11+
fn pass() {
12+
assert_eq!(1 + 1, 2);
13+
}

src/time.ts

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
1+
import { greet } from "./pweb/pkg/pweb";
2+
13
// Get the time when the site was first opened...
2-
let d = new Date;
3-
let theHour = d.getHours();
4-
let theMin = d.getMinutes();
54
let greeting: string;
65

76
// Greetings
8-
let theStringMin: string;
9-
if (theMin < 10) {
10-
theStringMin = '0' + theMin;
11-
} else {
12-
theStringMin = theMin.toString();
13-
}
7+
let category = greet();
148

15-
if (theHour >= 0 && theHour < 4) {
16-
if (theHour == 0) {
17-
greeting = `Wow it's 12:${theMin} in the morning... you're up late.`;
18-
} else {
19-
greeting = `Wow it's ${theHour}:${theStringMin} in the morning... you're up late.`;
20-
}
21-
} else if (theHour >= 4 && theHour < 12) {
22-
greeting = "Good Morning!";
23-
} else if (theHour >= 12 && theHour < 15) {
24-
greeting = "Good Afternoon!";
9+
if (category === "m") {
10+
greeting = "Good Morning!";
11+
} else if (category === "a") {
12+
greeting = "Good Afternoon!";
13+
} else if (category === "e") {
14+
greeting = "Good Evening!";
2515
} else {
26-
greeting = "Good Evening!";
16+
greeting = "You're up late!";
2717
}
2818

29-
export {greeting};
19+
export { greeting };

webpack.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ module.exports = {
2424
resolve: {
2525
extensions: ['.tsx', '.ts', '.js'],
2626
},
27+
experiments: {
28+
asyncWebAssembly: true,
29+
syncWebAssembly: true,
30+
},
2731
module: {
2832
rules: [{
2933
test: /\.ts|\.js$/,

0 commit comments

Comments
 (0)