Chore/vercel (#86)

* demo: add vercel

* demo: config

* chore: demo workflow
This commit is contained in:
luoxiaozero 2024-01-17 16:53:28 +08:00 committed by GitHub
parent 9aa2835cd8
commit b75c9c9ab3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 47 additions and 66 deletions

View file

@ -15,6 +15,11 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 18
cache: "npm"
- name: Setup Rust - name: Setup Rust
uses: actions-rs/toolchain@v1 uses: actions-rs/toolchain@v1
with: with:
@ -25,18 +30,13 @@ jobs:
uses: jetli/trunk-action@v0.4.0 uses: jetli/trunk-action@v0.4.0
with: with:
version: "v0.17.5" version: "v0.17.5"
- name: Deploy GitHub Pages - name: Build
run: | run: |
cd demo cd demo
trunk build --release trunk build --release
git worktree add gh-pages - name: Deploy
git config user.name "Deploy demo from CI" run: npx vercel --token ${VERCEL_TOKEN} --prod
git config user.email "" env:
cd gh-pages VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
# Delete the ref to avoid keeping history. VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
git update-ref -d refs/heads/gh-pages VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
rm -rf *
mv ../dist/* .
git add .
git commit -m "Deploy demo $GITHUB_SHA to gh-pages"
git push --force --set-upstream origin gh-pages

View file

@ -1,6 +1,6 @@
## Used ## 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 ## Docs

View file

@ -1,8 +1,8 @@
[build] [build]
target = "index.html" target = "index.html"
public_url = "/thaw/" # public_url = "/thaw/"
# release = true # release = true
filehash = false # filehash = false
[watch] [watch]
watch = ["../thaw", "./src", "../demo_markdown"] watch = ["../thaw", "./src", "../demo_markdown"]

View file

@ -7,12 +7,16 @@
<title>Thaw UI</title> <title>Thaw UI</title>
<link <link
rel="shortcut icon" rel="shortcut icon"
href="/thaw/favicon.ico" href="/favicon.ico"
type="image/x-icon" type="image/x-icon"
/> />
<link data-trunk rel="copy-file" href="./src/assets/svg/grid_dot.svg" /> <link data-trunk rel="copy-file" href="./src/assets/svg/grid_dot.svg" />
<link data-trunk rel="copy-file" href="./src/assets/favicon.ico" /> <link data-trunk rel="copy-file" href="./src/assets/favicon.ico" />
<link data-trunk rel="copy-file" href="./src/assets/404.html" /> <link
data-trunk
rel="copy-file"
href="./src/assets/vercel/vercel.json"
/>
<link data-trunk rel="copy-file" href="../logo.svg" /> <link data-trunk rel="copy-file" href="../logo.svg" />
</head> </head>
<body></body> <body></body>

View file

@ -13,7 +13,7 @@ pub fn App() -> impl IntoView {
provide_meta_context(); provide_meta_context();
view! { view! {
<Router base="/thaw" set_is_routing> <Router set_is_routing>
<TheProvider> <TheProvider>
<TheRouter is_routing/> <TheRouter is_routing/>
</TheProvider> </TheProvider>
@ -33,7 +33,7 @@ fn TheRouter(is_routing: RwSignal<bool>) -> impl IntoView {
}); });
view! { view! {
<Routes base="/thaw".to_string()> <Routes>
<Route path="/" view=Home/> <Route path="/" view=Home/>
<Route path="/guide" view=GuidePage> <Route path="/guide" view=GuidePage>
<Route path="/installation" view=InstallationMdPage/> <Route path="/installation" view=InstallationMdPage/>

View file

@ -1,30 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Thaw UI</title>
<link
rel="shortcut icon"
href="/thaw/favicon.ico"
type="image/x-icon"
/>
<link rel="stylesheet" href="/thaw/index.css" />
<link
rel="preload"
href="/thaw/demo_bg.wasm"
as="fetch"
type="application/wasm"
crossorigin=""
/>
<link rel="modulepreload" href="/thaw/demo.js" />
</head>
<body>
<script type="module">
import init from "/thaw/demo.js";
init("/thaw/demo_bg.wasm");
</script>
</body>
</html>

View file

@ -0,0 +1,8 @@
{
"rewrites": [
{
"source": "/(.*)",
"destination": "/index.html"
}
]
}

View file

@ -13,7 +13,7 @@ pub struct DemoCode {
pub fn Demo(demo_code: DemoCode, children: Children) -> impl IntoView { pub fn Demo(demo_code: DemoCode, children: Children) -> impl IntoView {
let theme = use_theme(Theme::light); let theme = use_theme(Theme::light);
let style = create_memo(move |_| { 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| { theme.with(|theme| {
if theme.common.color_scheme == "dark" { if theme.common.color_scheme == "dark" {
style.push_str("border: 1px solid #383f52;"); style.push_str("border: 1px solid #383f52;");

View file

@ -126,7 +126,7 @@ pub fn SiteHeader() -> impl IntoView {
let navigate = use_navigate(); let navigate = use_navigate();
navigate("/", Default::default()); navigate("/", Default::default());
}> }>
<img src="/thaw/logo.svg" style="width: 36px"/> <img src="/logo.svg" style="width: 36px"/>
<div class="demo-name"> <div class="demo-name">
"Thaw UI" "Thaw UI"
</div> </div>
@ -234,10 +234,10 @@ fn use_menu_value(change_theme: Callback<()>) -> RwSignal<String> {
let menu_value = create_rw_signal({ let menu_value = create_rw_signal({
let mut pathname = loaction.pathname.get_untracked(); let mut pathname = loaction.pathname.get_untracked();
if pathname.starts_with("/thaw/components/") { if pathname.starts_with("/components/") {
pathname.drain(17..).collect()
} else if pathname.starts_with("/thaw/guide/") {
pathname.drain(12..).collect() pathname.drain(12..).collect()
} else if pathname.starts_with("/guide/") {
pathname.drain(7..).collect()
} else { } else {
String::new() String::new()
} }
@ -256,10 +256,10 @@ fn use_menu_value(change_theme: Callback<()>) -> RwSignal<String> {
menu.iter() menu.iter()
.any(|group| group.children.iter().any(|item| &item.value == name)) .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()); 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()); navigate(&format!("/components/{name}"), Default::default());
} }
}); });

View file

@ -12,8 +12,8 @@ pub fn ComponentsPage() -> impl IntoView {
let select_name = create_rw_signal(String::new()); let select_name = create_rw_signal(String::new());
create_effect(move |_| { create_effect(move |_| {
let mut pathname = loaction.pathname.get(); let mut pathname = loaction.pathname.get();
let name = if pathname.starts_with("/thaw/components/") { let name = if pathname.starts_with("/components/") {
pathname.drain(17..).collect() pathname.drain(12..).collect()
} else { } else {
String::new() String::new()
}; };
@ -22,7 +22,7 @@ pub fn ComponentsPage() -> impl IntoView {
_ = select_name.watch(move |name| { _ = select_name.watch(move |name| {
let pathname = loaction.pathname.get_untracked(); 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()); navigate(&format!("/components/{name}"), Default::default());
} }
}); });

View file

@ -11,8 +11,8 @@ pub fn GuidePage() -> impl IntoView {
let loaction = use_location(); let loaction = use_location();
let mut pathname = loaction.pathname.get_untracked(); let mut pathname = loaction.pathname.get_untracked();
if pathname.starts_with("/thaw/guide/") { if pathname.starts_with("/guide/") {
pathname.drain(12..).collect() pathname.drain(7..).collect()
} else { } else {
String::new() String::new()
} }

View file

@ -10,7 +10,7 @@ pub fn NavBarPage() -> impl IntoView {
<div style="display: flex"> <div style="display: flex">
<NavBarMdPage /> <NavBarMdPage />
<div> <div>
<MobilePage path="/thaw?path=/mobile/nav-bar"/> <MobilePage path="/?path=/mobile/nav-bar"/>
</div> </div>
</div> </div>
} }
@ -39,4 +39,3 @@ pub fn NavBarDemoPage() -> impl IntoView {
</div> </div>
} }
} }

View file

@ -9,7 +9,7 @@ pub fn TabbarPage() -> impl IntoView {
<div style="display: flex"> <div style="display: flex">
<TabbarMdPage /> <TabbarMdPage />
<div> <div>
<MobilePage path="/thaw?path=/mobile/tabbar"/> <MobilePage path="/?path=/mobile/tabbar"/>
</div> </div>
</div> </div>
} }

View file

@ -11,7 +11,7 @@ pub fn ToastPage() -> impl IntoView {
<div style="display: flex"> <div style="display: flex">
<ToastMdPage /> <ToastMdPage />
<div> <div>
<MobilePage path="/thaw?path=/mobile/toast"/> <MobilePage path="/?path=/mobile/toast"/>
</div> </div>
</div> </div>
} }