From 8bfddbc361b83726c42e96035140e5d9926b436b Mon Sep 17 00:00:00 2001 From: Finn Bear Date: Thu, 30 Nov 2023 17:01:03 -0800 Subject: [PATCH] Add github pages WIP. --- .github/workflows/build.yml | 44 ++++++++++++++++++---- .gitignore | 3 +- pages/.gitignore | 2 + pages/Cargo.toml | 22 +++++++++++ pages/Trunk.prod.toml | 4 ++ pages/index.html | 18 +++++++++ pages/src/main.rs | 74 +++++++++++++++++++++++++++++++++++++ 7 files changed, 158 insertions(+), 9 deletions(-) create mode 100644 pages/.gitignore create mode 100644 pages/Cargo.toml create mode 100644 pages/Trunk.prod.toml create mode 100644 pages/index.html create mode 100644 pages/src/main.rs diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 66941a9..13e26ac 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,23 +5,51 @@ on: branches: [ master ] pull_request: branches: [ master ] + workflow_dispatch: + +permissions: + contents: read + pages: write + id-token: write + +concurrency: + group: "pages" + cancel-in-progress: false env: CARGO_TERM_COLOR: always jobs: build: - + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - toolchain: nightly - override: true - components: rustfmt, clippy + - uses: actions/checkout@v3 + with: + persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token. + fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. - name: Data run: curl https://raw.githubusercontent.com/vzhou842/profanity-check/master/profanity_check/data/clean_data.csv --output test.csv - name: Test - run: cargo test --release --features width \ No newline at end of file + run: cargo test --release --features width + - name: Add wasm32 target + run: rustup target add wasm32-unknown-unknown + - name: Install Trunk + uses: baptiste0928/cargo-install@v2 + with: + crate: trunk + version: 0.15.0 + - name: Build Pages + run: cd pages && trunk --config Trunk.prod.toml build --release --filehash=false + - name: Setup Pages + uses: actions/configure-pages@v3 + - name: Upload artifact + uses: actions/upload-pages-artifact@v2 + with: + path: './pages/dist/' + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v2 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 45ebd8e..5c1d3a2 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,5 @@ src/unicode_confusables.txt ttf/ .idea -*.iml \ No newline at end of file +*.iml +.vscode/ \ No newline at end of file diff --git a/pages/.gitignore b/pages/.gitignore new file mode 100644 index 0000000..92d6b77 --- /dev/null +++ b/pages/.gitignore @@ -0,0 +1,2 @@ +dist/ +target/ \ No newline at end of file diff --git a/pages/Cargo.toml b/pages/Cargo.toml new file mode 100644 index 0000000..168886f --- /dev/null +++ b/pages/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "pages" +version = "0.1.0" +edition = "2021" + +[dependencies] +rustrict = { path = "..", features = ["width"] } +yew = { version = "0.21", features = ["csr"] } + +[dependencies.web-sys] +version = "0.3" +features = [ + 'HtmlInputElement', + 'HtmlTextAreaElement', +] + +[profile.release] +codegen-units = 1 +lto = true +opt-level = "z" +panic = "abort" +strip = "debuginfo" \ No newline at end of file diff --git a/pages/Trunk.prod.toml b/pages/Trunk.prod.toml new file mode 100644 index 0000000..d4dfb89 --- /dev/null +++ b/pages/Trunk.prod.toml @@ -0,0 +1,4 @@ +[build] +target = "index.html" +release = true +public_url = "/rustrict/" \ No newline at end of file diff --git a/pages/index.html b/pages/index.html new file mode 100644 index 0000000..c77788c --- /dev/null +++ b/pages/index.html @@ -0,0 +1,18 @@ + + + + + Rustrict + + + + + + + + \ No newline at end of file diff --git a/pages/src/main.rs b/pages/src/main.rs new file mode 100644 index 0000000..d1781bc --- /dev/null +++ b/pages/src/main.rs @@ -0,0 +1,74 @@ +use web_sys::{HtmlInputElement, window, InputEvent, HtmlTextAreaElement, wasm_bindgen::JsCast}; +use yew::{html, Html, Callback, function_component, TargetCast}; +use rustrict::Censor; + +#[function_component(App)] +fn app() -> Html { + let oninput = Callback::from(move |event: InputEvent| { + if let Some(input) = event.target_dyn_into::() { + let uncensored = input.value(); + let analysis_element = window().unwrap().document().unwrap().get_element_by_id("analysis").unwrap(); + let censored_element = window().unwrap().document().unwrap().get_element_by_id("censored").unwrap().dyn_into::().unwrap(); + if uncensored.is_empty() { + analysis_element.set_inner_html("N/A"); + censored_element.set_value(""); + } else { + let (censored, analysis) = Censor::from_str(&uncensored).censor_and_analyze(); + let width = rustrict::width_str(&uncensored); + let result = format!("{analysis:?} (width = {width})"); + analysis_element.set_inner_html(&result); + censored_element.set_value(&censored); + } + } + }); + html! {<> +

{"Rustrict"}

+

{"Input"}

+ +

{"Analysis"}

+

{"N/A"}

+

{"Output"}

+ + } +} + +/* + +*/ + +fn main() { + yew::Renderer::::new().render(); +} \ No newline at end of file