Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add news section to website #149

Merged
merged 3 commits into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

<link data-trunk rel="css" href="css/tailwind.css" />
<link data-trunk rel="copy-dir" href="markdown" />
<link data-trunk rel="copy-dir" href="posts" />
<link data-trunk rel="copy-file" href="robots.txt" />
<link data-trunk rel="copy-file" href="google32773af3167b4156.html" />

Expand Down
89 changes: 89 additions & 0 deletions docs/posts/announcing-v0.5.0.md
Original file line number Diff line number Diff line change
@@ -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 <p>Hello, world!</p>
}
```

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!
44 changes: 33 additions & 11 deletions docs/src/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,18 @@ pub fn outline_view(outline: StateHandle<Vec<Outline>>) -> Template<G> {
}
}

pub struct ContentProps {
pub pathname: String,
pub show_sidebar: bool,
}

#[component(Content<G>)]
pub fn content(pathname: String) -> Template<G> {
pub fn content(
ContentProps {
pathname,
show_sidebar,
}: ContentProps,
) -> Template<G> {
let location = web_sys::window()
.unwrap()
.document()
Expand Down Expand Up @@ -138,23 +148,35 @@ pub fn content(pathname: String) -> Template<G> {
}));

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())
}
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion docs/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,15 @@ fn nav() -> Template<G> {
) {
"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",
Expand Down
19 changes: 18 additions & 1 deletion docs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ enum Routes {
Index,
#[to("/docs/<_>/<_>")]
Docs(String, String),
#[to("/news")]
NewsIndex,
#[to("/news/<_>")]
Post(String),
#[not_found]
NotFound,
}
Expand All @@ -21,6 +25,7 @@ fn app() -> Template<G> {
template! {
main {
BrowserRouter(|route: Routes| {
log::info!("{:?}", route);
template! {
div(class="mt-12") {
header::Header()
Expand All @@ -31,7 +36,19 @@ fn app() -> Template<G> {
}
},
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"
Expand Down
2 changes: 1 addition & 1 deletion packages/sycamore/src/flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ where
F: Fn(T) -> Template<G>,
K: Fn(&T) -> Key,
Key: Clone + Hash + Eq,
T: Clone + Eq + Hash,
T: Clone + Eq,
{
let KeyedProps {
iterable,
Expand Down