DEV Community

Yusuf B
Yusuf B

Posted on

Adding SEO to a SleekCMS site

Building a website using SleekCMS static site builder is simple. In this post, I will provide the steps to SEO-enable your website in a few quick steps.

First, let's start by creating a Block named SEO. The following could be the schema for the block.

title: text
description: text
image: image
keywords: text
no_index: boolean
no_follow: boolean
Enter fullscreen mode Exit fullscreen mode

Now, let's attach an EJS template to this block using built-in utility methods.

<%
  if (item.no_index) {
    meta({name: "robots", content: "noindex"});
  }
  if (item.no_follow) {
    meta({name: "robots", content: "nofollow"});
  }
  let path = path(item);
  if (path) {
    meta({rel: "canonical", href: path});
  }
  if (item.title) {
    meta({property: "og:title", content: item.title});
    meta({name: "twitter:title", content: item.title});
    title(item.title);
  }
  if (item.description) {
    meta({name: "description", content: item.description});
    meta({property: "og:description", content: item.description});
    meta({name: "twitter:description", content: item.description});
  }
  if (item.image && item.image.url) {
    meta({property: "og:image", content: img(item.image, "1200x630")});
    meta({name: "twitter:image", content: img(item.image, "1200x630")});
    meta({name: "twitter:card", content: "summary_large_image"});
  }
  if (item.keywords) {
    meta({name: "keywords", content: item.keywords});
  }
%>
Enter fullscreen mode Exit fullscreen mode

Next, we will add this block as a field to every page model on our site.

Block model YAML

This adds a section for SEO on every page that SEO content authors can access and update.

Block edit view

Now, we can update our layout EJS templates to ensure the SEO template is executed and relevant metadata is added to every page generated.

<% if (item.seo) render(item.seo) %>
Enter fullscreen mode Exit fullscreen mode

That is it. With that, your entire website is SEO-enabled and ready for boosting search placements.

Top comments (0)