Skip to content

Commit

Permalink
release v0.23.0 blog post (#873)
Browse files Browse the repository at this point in the history
* release v0.23.0 blog post

* PR feedback, fix typos, update issues link filter
  • Loading branch information
thescientist13 committed Feb 12, 2022
1 parent f4d225a commit d0914be
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 3 deletions.
Binary file added www/assets/blog-images/ssr.webp
Binary file not shown.
1 change: 1 addition & 0 deletions www/pages/blog/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ template: blog

# News and Announcements

- [Release: v0.23.0](/blog/release/v0-23-0/) 📝
- [Release: v0.21.0](/blog/release/v0-21-0/) 📝
- [Release: v0.20.0](/blog/release/v0-20-0/) 📝
- [Release: v0.19.0](/blog/release/v0-19-0/) 📝
Expand Down
2 changes: 1 addition & 1 deletion www/pages/blog/release/v0-15-0.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Being a developer is a lot of work. Being a designer is also lot of work. Bein
With Greenwood [_**Theme Packs**_](https://www.greenwoodjs.io/guides/theme-packs/), now developers and designers can create and share reusable HTML / CSS / JS as npm packages that other Greenwood users can pull into their Greenwood projects as a plugin. Now anyone can get up and running with a fully designed and themed site and all they have to do is just add the content! 🥳

## In Practice
For those unfamiliar with [**CSS Zen Garden**](http://www.csszengarden.com/), it is a site aimed at showcasing the power of CSS through static HTML.
For those unfamiliar with [**CSS Zen Garden**](http://www.csszengarden.com/), it is a site aimed at showcasing the power of CSS through static HTML.

> _The HTML remains the same, the only thing that has changed is the external CSS file. Yes, really._
Expand Down
121 changes: 121 additions & 0 deletions www/pages/blog/release/v0-23-0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
---
label: 'blog'
title: v0.23.0 Release
template: blog
---

# Greenwood v0.23.0

**Published: Feb 11, 2022**

## What's New

With this new release, the Greenwood team is excited to (soft) launch the ability to add Server Side Rendering (SSR) to your Greenwood project as well as support for using a custom renderer like [**Lit** SSR](https://www.npmjs.com/package/@lit-labs/ssr). Additionally, to enhance the ability of purely static sites to benefit from some build time templating, a new feature called "interpolate frontmatter" was introduced to easily reuse frontmatter similar to how you would use JavaScript interpolation, but in your HTML and markdown. Let's highlight them both below! 👇

## Server Side Rendering (SSR)

As mentioned above, we are soft launching the ability to incorporate server rendering into your Greenwood projects. By simply adding a JavaScript file to your project, you will be able to have server rendered content available when running `greenwood serve`. You can also combine static and server rendered content all in the same project for a hybrid application! Let's take a look at a quick example.

### How It Works
You can add a file to your project in the _pages/_ directory and implement either of the three supported APIs, and you will have a server rendered route available!
```shell
.
└── src
└── pages
├── artists.js
├── about.md
  └── index.html
```

```js
// artists.js
import fetch from 'node-fetch'; // this needs to be installed from npm

async function getBody(compilation) {
const artists = await fetch('http://www.example.com/api/artists').then(resp => resp.json());

return `
<body>
<h1>Hello from the server rendered artists page! 👋</h1>
<table>
<tr>
<th>Name</th>
<th>Image</th>
</tr>
${
artists.map((artist) => {
const { name, imageUrl } = artist;
return `
<tr>
<td>${name}</td>
<td><img src="${imageUrl}"/></td>
</tr>
`;
});
}
</table>
</body>
`
}

export { getBody }
```

You can then access `/artists/` and see the content! 💥

![Server Side Rendering example](/assets/blog-images/ssr.webp)

> _In the above screenshot, we can also see a demonstration of our custom rendering using LitSSR and the `<simple-greeting>` component._
## Interpolate Frontmatter
At the risk of (re) implementing a templating system (handlebars, nunjucks, etc) but still recognizing that having a JavaScript only solution though our [_graph.json_](/docs/data/) for static sites can be a bit cumbersome, the Greenwood team is introducing the `interpolateFrontmatter` feature. With this new feature, when setting the corresponding flag in your _greenwood.config.js_, frontmatter in your markdown will be available in your HTML or markdown similar to how variable interpolation works in JavaScript. Great for `<meta>` tags!

### How It Works
So given the following frontmatter
```md
---
template: 'post'
title: 'Git Explorer'
emoji: '💡'
date: '04.07.2020'
description: 'Local git repository viewer'
image: '/assets/blog-post-images/git.png'
---
```

And enabling the feature in _greenwood.config.js_
```js
export default {
interpolateFrontmatter: true
}
```

You access the frontmatter data in the markdown or HTML on a _per page instance_ following the convention of JavaScript [template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals), and Greenwood will interpolate those values at build time.

```md
# My Blog Post

<img src="${globalThis.page.image}" alt="Banner image for ${globalThis.page.description}">

Lorum Ipsum.
```

```html
<html>
<head>
<title>My Blog - ${globalThis.page.title}</title>
<meta property="og:title" content="My Blog">
<meta property="og:type" content="website">
<meta property="og:url" content="https://www.myblog.dev">
<meta property="og:image" content="https://www.myblog.dev/${globalThis.page.image}">
<meta property="og:description" content="My Blog - ${globalThis.page.description}">
</head>
<body>
<content-outlet></content-outlet>
</body>
</html>
```

## Learn More

To learn more about SSR and the full API please check out our docs on [SSR](/docs/server-rendering/) and [interpolateFrontmatter](/docs/config#interpolateFrontmatter). For custom SSR, we have [plugin docs](/plugins/renderer/) and a [Lit Renderer plugin](https://github.com/ProjectEvergreen/greenwood/tree/master/packages/plugin-renderer-lit) you can start using. As referenced at the start of the blog post, the SSR feature is brand new and we have many plans to incorporate new features and enhancements related to [hydration, statically exporting content from server routes, and more](https://github.com/ProjectEvergreen/greenwood/issues?q=is%3Aissue+is%3Aopen+label%3Assr)! Feedback is appreciated and we cant wait to see what you end building! 🙏
4 changes: 2 additions & 2 deletions www/pages/docs/server-rendering.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ index: 8
linkheadings: 3
---

## Server Rendering
## Server Rendering (Beta)

In addition to supporting [static and Single Page application project types](/docs/layouts/), you can also use Greenwood to author routes completely in JavaScript and host these on a server.

Expand All @@ -33,7 +33,7 @@ In your _[page].js_ file, Greenwood supports three functions you can `export` fo
- `getTemplate`: Effectively the same as a [page template](/docs/layouts/#page-templates).

```js
async function getFrontmatter(compilation, route, route, id) {
async function getFrontmatter(compilation, route, label, id) {
return { /* ... */ };
}

Expand Down

0 comments on commit d0914be

Please sign in to comment.