ahmed
ahmed

Reputation: 350

How to delete page from an Eleventy website?

I want to remove a page I created in my Eleventy-generated website, let's call it a-post.md. And I don't know what's the right way to do it.

I just remove the "source" page and, sure enough, it disappeared from the site. However, the files it generates in the _site directory are still there. Am I supposed to "clean" these by hand or am I doing something wrong?

I know this kind of stuff shouldn't be a question on Stackoverflow ― but as a newbie in the world of Eleventy (and static sites generators), I was baffled by the lack of newbie-friendly documentation on the matter. There are also a lot of articles and posts on how to create and customize pages, but not on how to dispose of them correctly.

Upvotes: 1

Views: 539

Answers (1)

MoritzLost
MoritzLost

Reputation: 2829

The problem you're describing usually only happens during development on your local machines, where the site output sticks around in between builds. SSG are heavily geared towards atomic deploys. This means every deployment will be executed in it's own temporary container environment and the generated site will completely replace the previous build. This means that the newly deployed build will never contain files from a previous build. This is true for all SSG hosting providers like Netlify or Vercel.

The problem you're describing usually only occurs locally during development and if you're deploying new versions of your site manually by uploading it over SFTP or something like this.

Local development

It's best practice to remove your output folder before the build step so your local build matches the atomic deploy you will get in the live environment. You can put the clear command in your build script, this way you never have to think about it (assuming your output directory is dist):

"scripts": {
    "build": "rm -rf dist/ && eleventy"
}

Manual deploys

This is really not the best way to deploy your site, but if you're doing this I would try to mimic an atomic deploy:

  1. Upload the new build next to the webroot of your live site. For example, if your live site lives in htdocs, upload the new site as htdocs-new
  2. Delete the htdocs folder.
  3. Rename htdocs-new to htdocs.

This way, you will never get any remnants of previous builds sticking around. The downside is that between steps 2 & 3 your site will be unavailable, whereas atomic deployments on Netlify or Vercel have zero downtime.

Upvotes: 1

Related Questions