Category: PHP, git

I’ve previously written about the benefits of static sites and how to layer dynamic functionality on top of them. In this article I want to introduce a simple technique for adding a sitemap to your static site.

You can experiment with the data you wish to include, but in this example, I’ll be including the following: In theory, you can update your sitemap file manually, in a text editor, just as you might edit your HTML files.

For example, you can trim the document root prefix from your file’s full path, prepend your domain, and remove the file extension.Line 46: Get the modification time using filemtime(): Note that an alternative, if you store your files in a revision control system such as git, is to fetch the time of the last commit for that file.

Running the script generates a sitemap file containing details of each valid page in the site: Adapt this command to your local environment depending on the location of your site’s document root and the generate.php script you downloaded.Note that the final file should be named exactly sitemap.xml and should reside at the top-level of your document root so that if your site is example.org, its URL will be https://example.org/sitemap.xml.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners