How I made my blog cheap to host, customizable, and lightning-fast. —Part 3: Meet Scully, our Static Site Generator

Justin Miles
2 min readMar 27, 2021

--

Part 1: Setting up — Azure DevOps and Our Headless CMS
Part 2: Building out our Angular Site
Part 3: Meet Scully, our Static Site Generator — you are here
Part 4: Hosting on the Cheap
Part 5: Build and Deploy with Azure DevOps

antique letterpress letters
photo credit: Patrick Fore

At this point, you have an Angular site that is rendering your blog posts from the Headless CMS. Now we’re going to use Scully to make it into a static site. It’ll still have some JavaScript, but it won’t be a SPA. Each route will have a “physical” Html file, that does not need to be rendered at run time.

To do this we need to first add Scully to our project with this command:

ng add @scullyio/init

This will add a Scully config file to the root of your site. We’ll modify it later, but for now, it will look something like this:

You’ll also notice a folder called “scully” in the root of your site. We’ll be using that later too. For now we can run two commands:

ng build --prod

npm run scully -- --scanRoutes

When we run we should get a couple of routes mapped. If you look closely though you’ll see that no static files were created for our individual posts. This is because the route “/blog/:postSlug” has a route parameter in it, and Scully isn’t sure what to do with that. So we need to tell it. We do that with a plugin.

Our Custom Plugin

Scully allows for a few types of plugin. The type we’re going to use is called a router plugin. Scully already gives us a skeleton for a plugin in the “/scully/plugin.ts” file. We just need to modify it like so:

What we’re doing here is:

  1. Getting an auth token from Squidex
  2. using that auth tpoken to get all of our posts
  3. assembling an array of the potential routes based on the slugs
  4. returning that array

Now we just have to let scully know to use this plugin for our blog post routes. We do that by going into the scully config and modifying the routes section. Like so:

Now when Scully tries to parse the route with the parameter in it, it will look to its config and see that it should use the plugin to get the possible values.

Go ahead and run Scully again with :

ng build --prod

npm run scully -- --scanRoutes

You should now have static pages for every blog post in your /dist folder!

The only problem is that we have to run the above commands every time we save a blog post. We’ll fix that in Part 4!

< Part 2:Building out our Angular Site
Part 4: Hosting on the Cheap >

--

--

Justin Miles
Justin Miles

Written by Justin Miles

Full-stack developer, Dad. Passionate about clean code and constantly learning. Current interests: Angular, DevOps, Domain Driven Design, and birding.

No responses yet