Create a sitemap in Phoenix 1.7+

165
clicks
Create a sitemap in Phoenix 1.7+

Source: andrewian.dev

Type: Post

The blog post describes a method of creating a sitemap for a website developed in Phoenix 1.7, the latest version of the Phoenix web framework, which has undergone significant changes, such as the removal of the traditional view layer. The author opts to manually maintain a small, fixed series of pages for a sitemap, rather than dynamically generating it from Ecto models. The post details how to set up a controller and an HTML module for the sitemap, making use of Phoenix 1.7's compile-time verified routes which provides immediate feedback on any errors in the routing. A sample code is included for creating the XML sitemap template, defining pages with a sigil for compile-time safety, and using a macro to set the last modified date to the current date at compilation time. The author concludes by showing how to add the controller to the router, thereby completing the setup of a manually maintained sitemap in a Phoenix 1.7+ application. An example output of the sitemap can be found at catnip.vip/sitemap.

© HashMerge 2024