From 542d84eff0b425d224c11b61d63c5239530bd6aa Mon Sep 17 00:00:00 2001 From: Luke Chu <37006668+lukechu10@users.noreply.github.com> Date: Tue, 6 Jul 2021 21:23:44 -0700 Subject: [PATCH 1/3] Remove Hash bound for Keyed T --- packages/sycamore/src/flow.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sycamore/src/flow.rs b/packages/sycamore/src/flow.rs index 27d1c62da..49fc491fe 100644 --- a/packages/sycamore/src/flow.rs +++ b/packages/sycamore/src/flow.rs @@ -53,7 +53,7 @@ where F: Fn(T) -> Template, K: Fn(&T) -> Key, Key: Clone + Hash + Eq, - T: Clone + Eq + Hash, + T: Clone + Eq, { let KeyedProps { iterable, From 1d4bbc45ae7b79232c522213429a183a1a46f8c3 Mon Sep 17 00:00:00 2001 From: Luke Chu <37006668+lukechu10@users.noreply.github.com> Date: Wed, 7 Jul 2021 11:29:16 -0700 Subject: [PATCH 2/3] v0.5.0 release post --- docs/index.html | 1 + docs/posts/announcing-v0.5.0.md | 89 +++++++++++++++++++++++++++++++++ docs/src/content.rs | 44 ++++++++++++---- docs/src/main.rs | 19 ++++++- 4 files changed, 141 insertions(+), 12 deletions(-) create mode 100644 docs/posts/announcing-v0.5.0.md diff --git a/docs/index.html b/docs/index.html index 91df9af8f..fa3af4caa 100644 --- a/docs/index.html +++ b/docs/index.html @@ -15,6 +15,7 @@ + diff --git a/docs/posts/announcing-v0.5.0.md b/docs/posts/announcing-v0.5.0.md new file mode 100644 index 000000000..5fdefae40 --- /dev/null +++ b/docs/posts/announcing-v0.5.0.md @@ -0,0 +1,89 @@ +# Announcing Sycamore v0.5.0! + +_SSR + Routing_ + +Hello everybody! Sycamore is a library for building isomorphic web applications in Rust and +WebAssembly. + +I'm happy to announce that we've just release v0.5.0. This is the biggest release yet with loads of +new features and bug fixes. + +(By the way, if you are looking for another library called "Maple", you found it. Maple is now +called Sycamore because Maple was already a trademarked name for another software product. The new +crate name is [`sycamore`](https://crates.io/crates/sycamore) on crates.io.). + +## What's New? + +### Server Side Rendering + +Yep! That's right. Sycamore now supports server side rendering. A big shoutout to +[`@lights0123`](https://github.com/lights0123) for taking initiative to implement this feature in +[this Pull Request](https://github.com/sycamore-rs/sycamore/pull/67). + +The hello world for SSR is just as simple for rendering to the DOM: + +```rust +use sycamore::prelude::*; + +fn main() { + let string = sycamore::render_to_string(|| template! { + p { "Hello, world!" } + }); + println!("{}", string); // Prints

Hello, world!

+} +``` + +Just use `sycamore::render_to_string` instead of `sycamore::render` and you're good to go. + +Check out the docs on [server side rendering](https://sycamore-rs.netlify.app/docs/advanced/ssr) for +more information. + +### Routing + +This release also introduces a full-featured routing system. Routing is provided by the +[`sycamore-router`](https://crates.io/crates/sycamore-router) crate. Creating a router is as easy as +pie! + +```rust +use sycamore_router::Route; + +#[derive(Route)] +enum MyRoutes { + #[to("/")] + Index, + #[to("/about")] + About, + #[not_found] + NotFound, +} +``` + +Just slap `#[derive(Route)]` on your enum and there you have it. Your very own router. + +Check out the docs on [routing](https://sycamore-rs.netlify.app/docs/advanced/routing) to learn +more. + +### New documentation website + +The new documentation website is ready to roll. It is completely built with Sycamore. In fact, the +source code is available right here: +[github.com/sycamore-rs/sycamore/tree/master/docs](https://github.com/sycamore-rs/sycamore/tree/master/docs). + +Check out the new documentation website at +[sycamore-rs.netlify.app](https://sycamore-rs.netlify.app). + +### Conclusion + +As always, a big thanks to all the +[contributors](https://github.com/sycamore-rs/sycamore/graphs/contributors) who made this release +possible! This would not have been possible without you. + +For more detailed changes, check out the +[changelog](https://github.com/sycamore-rs/sycamore/blob/master/CHANGELOG.md#-050-2021-07-06). + +If you are interested in contributing to Sycamore, check out the issues labeled with +[`good first issue`](https://github.com/sycamore-rs/sycamore/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) +on our GitHub repository. Don't hesitate to swing by our +[Discord server](https://discord.gg/vDwFUmm6mU) too! See you there. + +Thanks! diff --git a/docs/src/content.rs b/docs/src/content.rs index 41ec1c259..0db7ac948 100644 --- a/docs/src/content.rs +++ b/docs/src/content.rs @@ -56,8 +56,18 @@ pub fn outline_view(outline: StateHandle>) -> Template { } } +pub struct ContentProps { + pub pathname: String, + pub show_sidebar: bool, +} + #[component(Content)] -pub fn content(pathname: String) -> Template { +pub fn content( + ContentProps { + pathname, + show_sidebar, + }: ContentProps, +) -> Template { let location = web_sys::window() .unwrap() .document() @@ -138,23 +148,35 @@ pub fn content(pathname: String) -> Template { })); wasm_bindgen_futures::spawn_local(cloned!((markdown) => async move { - log::info!("Getting documentation at {}", pathname); + log::info!("Getting markdown at {}", pathname); - let url = format!("{}/markdown{}.md", location.origin().unwrap(), pathname); + let url = format!("{}{}", location.origin().unwrap(), pathname); let text = fetch_md(&url).await.as_string().unwrap(); markdown.set(text); })); template! { div(class="flex w-full") { - div(class="flex-none") { - crate::sidebar::Sidebar() - } - div(ref=docs_container_ref, class="content flex-1 min-w-0 pr-4 mb-2 lg:mr-44") { - "Loading..." - } - div(class="outline flex-none hidden lg:block lg:w-44 fixed right-0") { - OutlineView(outline.handle()) + (if show_sidebar { + template! { + div(class="flex-none") { + crate::sidebar::Sidebar() + } + } + } else { + template! {} + }) + div(class="flex-1 container mx-auto") { + div( + ref=docs_container_ref, + class=format!("content min-w-0 pr-4 mb-2 lg:mr-44 {}", + if show_sidebar { "" } else { "container mx-auto lg:ml-auto lg:mr-44" }), + ) { + "Loading..." + } + div(class="outline flex-none hidden lg:block lg:w-44 fixed right-0 top-0 mt-12") { + OutlineView(outline.handle()) + } } } } diff --git a/docs/src/main.rs b/docs/src/main.rs index ca2ea6c81..c78a5f9e5 100644 --- a/docs/src/main.rs +++ b/docs/src/main.rs @@ -12,6 +12,10 @@ enum Routes { Index, #[to("/docs/<_>/<_>")] Docs(String, String), + #[to("/news")] + NewsIndex, + #[to("/news/<_>")] + Post(String), #[not_found] NotFound, } @@ -21,6 +25,7 @@ fn app() -> Template { template! { main { BrowserRouter(|route: Routes| { + log::info!("{:?}", route); template! { div(class="mt-12") { header::Header() @@ -31,7 +36,19 @@ fn app() -> Template { } }, Routes::Docs(a, b) => template! { - content::Content(format!("/{}/{}", a, b)) + content::Content(content::ContentProps { + pathname: format!("/markdown/{}/{}.md", a, b), + show_sidebar: true, + }) + }, + Routes::NewsIndex => template! { + "News" + }, + Routes::Post(post) => template! { + content::Content(content::ContentProps { + pathname: format!("/posts/{}.md", post), + show_sidebar: false, + }) }, Routes::NotFound => template! { "404 Not Found" From d45dcba916ff9ae5cc19711074dc0a9bb6fcb1ba Mon Sep 17 00:00:00 2001 From: Luke Chu <37006668+lukechu10@users.noreply.github.com> Date: Wed, 7 Jul 2021 11:31:40 -0700 Subject: [PATCH 3/3] Add news to navbar --- docs/src/header.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/src/header.rs b/docs/src/header.rs index 69489db7c..58015609a 100644 --- a/docs/src/header.rs +++ b/docs/src/header.rs @@ -35,10 +35,15 @@ fn nav() -> Template { ) { "API" } + a(class="py-2 px-3 text-sm hover:text-gray-800 hover:underline transition", + href="/news", + ) { + "News" + } a(class="py-2 px-3 text-sm hover:text-gray-800 hover:underline transition", href="https://github.com/sycamore-rs/sycamore", ) { - "Repository" + "GitHub" } a(class="py-2 px-3 text-sm hover:text-gray-800 hover:underline transition", href="https://discord.gg/vDwFUmm6mU",