Skip to content

Commit

Permalink
Chore/vercel (#86)
Browse files Browse the repository at this point in the history
* demo: add vercel

* demo: config

* chore: demo workflow
  • Loading branch information
luoxiaozero authored Jan 17, 2024
1 parent 9aa2835 commit b75c9c9
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 66 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -25,18 +30,13 @@ jobs:
uses: jetli/[email protected]
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 }}
2 changes: 1 addition & 1 deletion demo/README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions demo/Trunk.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
8 changes: 6 additions & 2 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
<title>Thaw UI</title>
<link
rel="shortcut icon"
href="/thaw/favicon.ico"
href="/favicon.ico"
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/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" />
</head>
<body></body>
Expand Down
4 changes: 2 additions & 2 deletions demo/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub fn App() -> impl IntoView {
provide_meta_context();

view! {
<Router base="/thaw" set_is_routing>
<Router set_is_routing>
<TheProvider>
<TheRouter is_routing/>
</TheProvider>
Expand All @@ -33,7 +33,7 @@ fn TheRouter(is_routing: RwSignal<bool>) -> impl IntoView {
});

view! {
<Routes base="/thaw".to_string()>
<Routes>
<Route path="/" view=Home/>
<Route path="/guide" view=GuidePage>
<Route path="/installation" view=InstallationMdPage/>
Expand Down
30 changes: 0 additions & 30 deletions demo/src/assets/404.html

This file was deleted.

8 changes: 8 additions & 0 deletions demo/src/assets/vercel/vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"rewrites": [
{
"source": "/(.*)",
"destination": "/index.html"
}
]
}
2 changes: 1 addition & 1 deletion demo/src/components/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;");
Expand Down
12 changes: 6 additions & 6 deletions demo/src/components/site_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ pub fn SiteHeader() -> impl IntoView {
let navigate = use_navigate();
navigate("/", Default::default());
}>
<img src="/thaw/logo.svg" style="width: 36px"/>
<img src="/logo.svg" style="width: 36px"/>
<div class="demo-name">
"Thaw UI"
</div>
Expand Down Expand Up @@ -234,10 +234,10 @@ fn use_menu_value(change_theme: Callback<()>) -> RwSignal<String> {

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()
}
Expand All @@ -256,10 +256,10 @@ fn use_menu_value(change_theme: Callback<()>) -> RwSignal<String> {
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());
}
});
Expand Down
6 changes: 3 additions & 3 deletions demo/src/pages/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};
Expand All @@ -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());
}
});
Expand Down
4 changes: 2 additions & 2 deletions demo/src/pages/guide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
5 changes: 2 additions & 3 deletions demo/src/pages/nav_bar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn NavBarPage() -> impl IntoView {
<div style="display: flex">
<NavBarMdPage />
<div>
<MobilePage path="/thaw?path=/mobile/nav-bar"/>
<MobilePage path="/?path=/mobile/nav-bar"/>
</div>
</div>
}
Expand All @@ -32,11 +32,10 @@ pub fn NavBarDemoPage() -> impl IntoView {
on_click_right=on_click_right
>
<NavBarRight slot>
<Icon icon=icondata::Icon::from(icondata::AiIcon::AiCloseOutlined)/>
<Icon icon=icondata::Icon::from(icondata::AiIcon::AiCloseOutlined)/>
</NavBarRight>
</NavBar>
<div style="padding-top: 50px">{move || click_text.get()}</div>
</div>
}
}

2 changes: 1 addition & 1 deletion demo/src/pages/tabbar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub fn TabbarPage() -> impl IntoView {
<div style="display: flex">
<TabbarMdPage />
<div>
<MobilePage path="/thaw?path=/mobile/tabbar"/>
<MobilePage path="/?path=/mobile/tabbar"/>
</div>
</div>
}
Expand Down
2 changes: 1 addition & 1 deletion demo/src/pages/toast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn ToastPage() -> impl IntoView {
<div style="display: flex">
<ToastMdPage />
<div>
<MobilePage path="/thaw?path=/mobile/toast"/>
<MobilePage path="/?path=/mobile/toast"/>
</div>
</div>
}
Expand Down

0 comments on commit b75c9c9

Please sign in to comment.