Astro is a SSG that… well, before going too technical - Keep reading if:

The Astro Project

Astro is a relatively new SSG that aims to combine the simplicity of static sites with the power of modern JavaScript frameworks

What is Astro?

Astro stands as a beacon of modern web development, empowering developers to craft lightning-fast, scalable, and secure web applications.

Key Features of Astro

Discover the stellar features that set Astro apart:

  • Static Site Generation (SSG): Experience the speed and security of static sites, effortlessly generated by Astro.
  • Server-Side Rendering (SSR): Elevate your content with dynamic server-side rendering, enhancing SEO and user experience.
  • Integration with Popular Frameworks: Seamlessly incorporate Astro into your projects, leveraging the power of React, Vue (and more) to build robust web applications.

Use your favorite JavaScript framework and automatically ship the bare-minimum amount of JavaScript—by default.

So basically…

  • Modern Web Development: Astro offers a modern approach to web development, ensuring speed, * scalability, and security.
  • Versatility: From static site generation to server-side rendering, Astro caters to a wide range of development needs.
  • Integration: With support for leading frameworks, Astro empowers developers to craft exceptional web experiences with ease.

Why Astro?

  1. Built on JavaScript: Astro is built on JavaScript, specifically leveraging the Node.js ecosystem. This allows developers to use familiar tools and libraries from the JavaScript ecosystem.
  2. Component-based: Astro embraces a component-based architecture, similar to modern JavaScript frameworks like React or Vue.js. This makes it easy to create reusable UI components and build complex user interfaces.
  3. Hybrid rendering: One of the key features of Astro is its hybrid rendering approach. It can pre-render static content at build time while also allowing components to hydrate into fully interactive components at runtime. This enables dynamic behavior without sacrificing performance.
  4. Framework agnostic: Astro is framework agnostic, meaning you can use it with any JavaScript framework or library of your choice, such as React, Vue.js, Svelte, or even vanilla JavaScript.

Yet another JS framework. Right… but not quite.

It has received recently an update to v4: https://astro.build/blog/astro-4/

  • It is a SSG - Similarly to HUGO, it creates static files.
    • The good thing is that JS does not take over unless it is needed in some island (they add interactivity just when is needed - kind of Just in Time for Webs) - which is great for performance
  • Astro is library agnostic (React, Solid, Vue, Svelt…or none of them) and we can create many kind of Apps: landing pages, blogs…and recently even with [APIs](#How REST and GraphQL compares?)
  • Content-first websites: Fetch data from your CMS or work locally with type-safe Markdown and MDX APIs
  • Last but not least, Astro 4 is here

How to use Astro

  1. Choose a Theme
  2. Tweak the Astro Theme
  3. Deploy Astro (Share it online!)

Astro Themes

In general, you can find Astro Free Themes here. You might be interested in the Site Speed.

But you can also find them on Github:

MDX Support

The theme makes a great summary: https://github.com/isooosi/VisVrs

export const title = 'My first MDX post'

# {title}

# {frontmatter.title}

Simply put - MDX == Leverage

See https://docs.astro.build/en/guides/markdown-content/#using-components-in-mdx

Deploying Astro

There are several options well documented in their official page: https://docs.astro.build/en/guides/deploy/

I created a step by step guide with the following:

👉 https://www.youtube.com/watch?v=sOXW0ZnJxbQ

Astro + Github Actions to Github Pages

The easiest and quickest way to have your project docs or public profile on your Github.

Astro + Firebase

Build locally. Push to Firebase.

Your project files will remain private and you can use your custom domain.

If you are worried about vendor lock-in, you can always check how to SelfHost Static Sites.

Astro + SelfHosting + Cloudflare

If you want to have everything under your control. This approach is for you.

Tweaking Astro Themes

Getting Started with ASTRO

We need 3 simple steps:

  1. To have nodejs installed in the computer https://nodejs.org/en
  2. To have a theme selected and cloned in a local folder: https://astro.build/themes/

Tweaking an Astro Theme - Example: Tailscast

I found a great theme at https://github.com/matt765/Tailcast, lets have a look how to customize it.

Tweaking Another Astro Theme - BigSpring

The theme uses Tailwind CSS for styling. You can learn more about Tailwind CSS here: https://tailwindcss.com/.

Tweaking Astro - Example 3: Ovidius Theme

Tweaking an Astro Theme - Example4: Pacamara

I found a great theme at https://github.com/palmiak/pacamara-astro, lets have a look how to customize it.

Tweaking an Astro Theme - Example 5: StarFunnel

I found a great theme at https://github.com/unfolding-io/StarFunnel, lets have a look how to customize it.


FAQ

Deploying Astro to GH Pages

https://docs.astro.build/en/guides/deploy/github/

Modify: astro.config.ts

import { defineConfig } from 'astro/config';
import mdx from '@astrojs/mdx';
import sitemap from '@astrojs/sitemap';
import tailwind from '@astrojs/tailwind';

// https://astro.build/config
export default defineConfig({
    site: 'https://jalcocert.github.io',
    base: '/ovidius-astro-theme',
    integrations: [mdx(), sitemap(), tailwind()]
});
name: Deploy to GitHub Pages

on:
  # Trigger the workflow every time you push to the `main` branch
  # Using a different branch name? Replace `main` with your branch’s name
  push:
    branches: [ main ]
  # Allows you to run this workflow manually from the Actions tab on GitHub.
  workflow_dispatch:

# Allow this job to clone the repo and create a page deployment
permissions:
  contents: read
  pages: write
  id-token: write

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout your repository using git
        uses: actions/checkout@v3
      - name: Install, build, and upload your site
        uses: withastro/action@v1
        # with:
          # path: . # The root location of your Astro project inside the repository. (optional)
          # node-version: 18 # The specific version of Node that should be used to build your site. Defaults to 18. (optional)
          # package-manager: pnpm@latest # The Node package manager that should be used to install dependencies and build your site. Automatically detected based on your lockfile. (optional)

  deploy:
    needs: build
    runs-on: ubuntu-latest
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v1

What it is a headless CMS?

If heard that Astro is compatible with Headless CMS, that’s true. For example with Strapi CMS.

It means that you will be able to interact with some Astro Themes through the CMS to write your content through the UI.

Astro + Strapi

To use Strapi with Astro, you can follow the steps below:

  1. First, create a new Strapi project or use an existing one.
  2. Next, create a new content type in Strapi and add the fields you need for your Astro site.
  3. Then, start your Strapi server and populate your content type with data.
  4. In your Astro project, create a new .env file in the root directory and add the following variable: STRAPI_URL="<your-strapi-url>".
  5. In your Astro project, install the @astrojs/source-strapi package using npm install @astrojs/source-strapi.
  6. In your Astro project, create a new .astro file and import the source-strapi package.
  7. Use the source-strapi package to fetch your content from Strapi and render it in your Astro site.

Here is an example of how to use source-strapi in your Astro project:

import { Strapi } from '@astrojs/source-strapi';

export const getStaticPaths = async () => {
  const strapi = new Strapi(process.env.STRAPI_URL);
  const posts = await strapi.getEntries('posts');

  return {
    paths: posts.map((post) => ({
      params: {
        slug: post.slug,
      },
    })),
    fallback: false,
  };
};

export const getStaticProps = async ({ params }) => {
  const strapi = new Strapi(process.env.STRAPI_URL);
  const post = await strapi.getEntry('posts', { slug: params.slug });

  return {
    props: {
      post,
    },
  };
};

export default function Post({ post }) {
  return (
    <div>
      <h1>{post.title}</h1>
      <p>{post.content}</p>
    </div>
  );
}

This code fetches the posts content type from Strapi and renders it in your Astro site. You can customize this code to fit your specific needs.

I hope this helps!

What other F/OSS SSGs Alternatives I have?

You can always have a look at jamstack or to this Streamlit App that tracks SSG’s Popularity.

How to Replace Google Analytics with F/OSS?

Add it in the base.astro or baselayout.astro

Here you can also include the sitemap (need to be configured as in VisVrs theme - as dependencies in astro.config.mjs, package-lock.json and package.json)

How REST and GraphQL compares?

REST and GraphQL are two distinct approaches to designing API for exchanging data over the internet.

  • REST enables client applications to exchange data with a server using HTTP verbs, which is the standard communication protocol of the internet. RESTful APIs or REST APIs are developed with REST.

  • GraphQL is an API query language that defines specifications of how a client application should request data from a remote server. You can use GraphQL in your API calls without relying on the server-side application to define the request. GraphQL APIs are simply GraphQL APIs.

How to Get Better at Astro?

You can have some ideas from:

How to Implement Search for Astro Sites

  • Using the PageFind static site search.

Pagefind is a fully static search library that aims to perform well on large sites, while using as little of your users’ bandwidth as possible, and without hosting any infrastructurwe - https://pagefind.app/

https://github.com/cloudcannon/pagefind https://github.com/cloudcannon/pagefind?tab=MIT-1-ov-file#readme

Static low-bandwidth search at scale

The installation process is always the same: Pagefind only requires a folder containing the built static files of your website, so in most cases no configuration is needed to get started.

To Configure Our Astro Site Search with PageFind, we just need:

How to Add Sign In to Astro?

Improving Astro SEO

Astro Site Map

  • Make sure to have your sitemap generated and give it to: https://search.google.com/search-console/sitemaps
    • Example Theme with SiteMap - The theme VisVRS: you need to pay attention to: astro.config.mjs, package-lock.json and package.json
    • The NPM JS package we will use: https://www.npmjs.com/package/sitemap - (MIT Licensed ❤️)
  integrations: [
    sitemap(),
    ...
  ]
"@astrojs/sitemap": "^3.1.5",

Astro Robots.txt

Generally, The robots.txt file informs search engines which pages on your website should be crawled.

For Astro project you usually create the robots.txt in a text editor and place it to the public/ directory.

In that case you must manually synchronize site option in astro.config.* with Sitemap: record in robots.txt.

But we can use this npm package instead: https://www.npmjs.com/package/astro-robots-txt#why-astro-robots-txt (MIT Licensed ❤️)

npx astro add astro-robots-txt #npm install astro-robots-txt

It adds it automatically as integrations in your astro.config.mjs and also as dependency at package.json.

Make sure that you have a deployment / site URL for generation in the astro config mjs:

import { defineConfig } from 'astro/config';
import robotsTxt from 'astro-robots-txt';

export default defineConfig({
  site: 'https://example.com',

  integrations: [robotsTxt()],
});

Now just build the site:

astro build #npm run build

And the robots.txt file will be generated at /dist ready to be pushed when deploying the Astro Site

Astro Must Know CLI

npm run dev
npm run build
npm run preview

How to create Presentations with astro

You will be shocked when you discover the power of Astro & RevealJS

Say goodbye to the old ppt’s