From b75c9c9ab3b4aa21c72d41e0f0e8adf6433e43ea Mon Sep 17 00:00:00 2001
From: luoxiaozero <48741584+luoxiaozero@users.noreply.github.com>
Date: Wed, 17 Jan 2024 16:53:28 +0800
Subject: [PATCH] Chore/vercel (#86)
* demo: add vercel
* demo: config
* chore: demo workflow
---
.github/workflows/demo.yml | 24 ++++++++++++------------
demo/README.md | 2 +-
demo/Trunk.toml | 4 ++--
demo/index.html | 8 ++++++--
demo/src/app.rs | 4 ++--
demo/src/assets/404.html | 30 ------------------------------
demo/src/assets/vercel/vercel.json | 8 ++++++++
demo/src/components/demo.rs | 2 +-
demo/src/components/site_header.rs | 12 ++++++------
demo/src/pages/components.rs | 6 +++---
demo/src/pages/guide.rs | 4 ++--
demo/src/pages/nav_bar/mod.rs | 5 ++---
demo/src/pages/tabbar/mod.rs | 2 +-
demo/src/pages/toast/mod.rs | 2 +-
14 files changed, 47 insertions(+), 66 deletions(-)
delete mode 100644 demo/src/assets/404.html
create mode 100644 demo/src/assets/vercel/vercel.json
diff --git a/.github/workflows/demo.yml b/.github/workflows/demo.yml
index 69163f8..6011088 100644
--- a/.github/workflows/demo.yml
+++ b/.github/workflows/demo.yml
@@ -15,6 +15,11 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
+ - name: Setup Node
+ uses: actions/setup-node@v4
+ with:
+ node-version: 18
+ cache: "npm"
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
@@ -25,18 +30,13 @@ jobs:
uses: jetli/trunk-action@v0.4.0
with:
version: "v0.17.5"
- - name: Deploy GitHub Pages
+ - name: Build
run: |
cd demo
trunk build --release
- git worktree add gh-pages
- git config user.name "Deploy demo from CI"
- git config user.email ""
- cd gh-pages
- # Delete the ref to avoid keeping history.
- git update-ref -d refs/heads/gh-pages
- rm -rf *
- mv ../dist/* .
- git add .
- git commit -m "Deploy demo $GITHUB_SHA to gh-pages"
- git push --force --set-upstream origin gh-pages
+ - name: Deploy
+ run: npx vercel --token ${VERCEL_TOKEN} --prod
+ env:
+ VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
+ VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
+ VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
diff --git a/demo/README.md b/demo/README.md
index 8870332..707596e 100644
--- a/demo/README.md
+++ b/demo/README.md
@@ -1,6 +1,6 @@
## Used
-Run the `trunk serve` command and then open the `http://127.0.0.1:6421/thaw` URL
+Run the `trunk serve` command and then open the `http://127.0.0.1:6421` URL
## Docs
diff --git a/demo/Trunk.toml b/demo/Trunk.toml
index a57c26a..46041aa 100644
--- a/demo/Trunk.toml
+++ b/demo/Trunk.toml
@@ -1,8 +1,8 @@
[build]
target = "index.html"
-public_url = "/thaw/"
+# public_url = "/thaw/"
# release = true
-filehash = false
+# filehash = false
[watch]
watch = ["../thaw", "./src", "../demo_markdown"]
diff --git a/demo/index.html b/demo/index.html
index d0b683e..a1879b1 100644
--- a/demo/index.html
+++ b/demo/index.html
@@ -7,12 +7,16 @@
Thaw UI
-
+
diff --git a/demo/src/app.rs b/demo/src/app.rs
index c1bf021..ff7e5c8 100644
--- a/demo/src/app.rs
+++ b/demo/src/app.rs
@@ -13,7 +13,7 @@ pub fn App() -> impl IntoView {
provide_meta_context();
view! {
-
+
@@ -33,7 +33,7 @@ fn TheRouter(is_routing: RwSignal) -> impl IntoView {
});
view! {
-
+
diff --git a/demo/src/assets/404.html b/demo/src/assets/404.html
deleted file mode 100644
index a96962d..0000000
--- a/demo/src/assets/404.html
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
-
-
-
-
- Thaw UI
-
-
-
-
-
-
-
-
-
-
diff --git a/demo/src/assets/vercel/vercel.json b/demo/src/assets/vercel/vercel.json
new file mode 100644
index 0000000..7cf4c77
--- /dev/null
+++ b/demo/src/assets/vercel/vercel.json
@@ -0,0 +1,8 @@
+{
+ "rewrites": [
+ {
+ "source": "/(.*)",
+ "destination": "/index.html"
+ }
+ ]
+}
diff --git a/demo/src/components/demo.rs b/demo/src/components/demo.rs
index 8ab0750..82d1d7b 100644
--- a/demo/src/components/demo.rs
+++ b/demo/src/components/demo.rs
@@ -13,7 +13,7 @@ pub struct DemoCode {
pub fn Demo(demo_code: DemoCode, children: Children) -> impl IntoView {
let theme = use_theme(Theme::light);
let style = create_memo(move |_| {
- let mut style = String::from("background-image: url(/thaw/grid_dot.svg); background-repeat: repeat; background-size: 1.5rem; margin-top: 1rem; padding: 1rem; border-top-left-radius: 0.5rem; border-top-right-radius: 0.5rem;");
+ let mut style = String::from("background-image: url(/grid_dot.svg); background-repeat: repeat; background-size: 1.5rem; margin-top: 1rem; padding: 1rem; border-top-left-radius: 0.5rem; border-top-right-radius: 0.5rem;");
theme.with(|theme| {
if theme.common.color_scheme == "dark" {
style.push_str("border: 1px solid #383f52;");
diff --git a/demo/src/components/site_header.rs b/demo/src/components/site_header.rs
index 8daa5f7..dacbb75 100644
--- a/demo/src/components/site_header.rs
+++ b/demo/src/components/site_header.rs
@@ -126,7 +126,7 @@ pub fn SiteHeader() -> impl IntoView {
let navigate = use_navigate();
navigate("/", Default::default());
}>
-
+
"Thaw UI"
@@ -234,10 +234,10 @@ fn use_menu_value(change_theme: Callback<()>) -> RwSignal {
let menu_value = create_rw_signal({
let mut pathname = loaction.pathname.get_untracked();
- if pathname.starts_with("/thaw/components/") {
- pathname.drain(17..).collect()
- } else if pathname.starts_with("/thaw/guide/") {
+ if pathname.starts_with("/components/") {
pathname.drain(12..).collect()
+ } else if pathname.starts_with("/guide/") {
+ pathname.drain(7..).collect()
} else {
String::new()
}
@@ -256,10 +256,10 @@ fn use_menu_value(change_theme: Callback<()>) -> RwSignal {
menu.iter()
.any(|group| group.children.iter().any(|item| &item.value == name))
}) {
- if !pathname.eq(&format!("/thaw/guide/{name}")) {
+ if !pathname.eq(&format!("/guide/{name}")) {
navigate(&format!("/guide/{name}"), Default::default());
}
- } else if !pathname.eq(&format!("/thaw/components/{name}")) {
+ } else if !pathname.eq(&format!("/components/{name}")) {
navigate(&format!("/components/{name}"), Default::default());
}
});
diff --git a/demo/src/pages/components.rs b/demo/src/pages/components.rs
index fbf55f2..76d7bd8 100644
--- a/demo/src/pages/components.rs
+++ b/demo/src/pages/components.rs
@@ -12,8 +12,8 @@ pub fn ComponentsPage() -> impl IntoView {
let select_name = create_rw_signal(String::new());
create_effect(move |_| {
let mut pathname = loaction.pathname.get();
- let name = if pathname.starts_with("/thaw/components/") {
- pathname.drain(17..).collect()
+ let name = if pathname.starts_with("/components/") {
+ pathname.drain(12..).collect()
} else {
String::new()
};
@@ -22,7 +22,7 @@ pub fn ComponentsPage() -> impl IntoView {
_ = select_name.watch(move |name| {
let pathname = loaction.pathname.get_untracked();
- if !pathname.eq(&format!("/thaw/components/{name}")) {
+ if !pathname.eq(&format!("/components/{name}")) {
navigate(&format!("/components/{name}"), Default::default());
}
});
diff --git a/demo/src/pages/guide.rs b/demo/src/pages/guide.rs
index a0962e6..89ac8da 100644
--- a/demo/src/pages/guide.rs
+++ b/demo/src/pages/guide.rs
@@ -11,8 +11,8 @@ pub fn GuidePage() -> impl IntoView {
let loaction = use_location();
let mut pathname = loaction.pathname.get_untracked();
- if pathname.starts_with("/thaw/guide/") {
- pathname.drain(12..).collect()
+ if pathname.starts_with("/guide/") {
+ pathname.drain(7..).collect()
} else {
String::new()
}
diff --git a/demo/src/pages/nav_bar/mod.rs b/demo/src/pages/nav_bar/mod.rs
index 90514a5..6623349 100644
--- a/demo/src/pages/nav_bar/mod.rs
+++ b/demo/src/pages/nav_bar/mod.rs
@@ -10,7 +10,7 @@ pub fn NavBarPage() -> impl IntoView {
}
@@ -32,11 +32,10 @@ pub fn NavBarDemoPage() -> impl IntoView {
on_click_right=on_click_right
>
-
+
{move || click_text.get()}
}
}
-
diff --git a/demo/src/pages/tabbar/mod.rs b/demo/src/pages/tabbar/mod.rs
index 8d6589c..beee429 100644
--- a/demo/src/pages/tabbar/mod.rs
+++ b/demo/src/pages/tabbar/mod.rs
@@ -9,7 +9,7 @@ pub fn TabbarPage() -> impl IntoView {
}
diff --git a/demo/src/pages/toast/mod.rs b/demo/src/pages/toast/mod.rs
index 293d574..9cdcd75 100644
--- a/demo/src/pages/toast/mod.rs
+++ b/demo/src/pages/toast/mod.rs
@@ -11,7 +11,7 @@ pub fn ToastPage() -> impl IntoView {
}