HTML Sitemap - easy way of doing it?

I should probably already know this already, but it has been sometime since I have had to create an HTML sitemap for a client (seems a bit old school to me - and is a hot debate of its requirements in the SEO world).

Anyways, is there an easy way of outputting all pages (pages, custom modules, etc.) that have been tagged to “Show for Search Engines” into a list that can then be outputted via liquid?

I know the more manual method I’d have to do if I need to segment the list based on the navigation, but thought maybe knew of a simple way - almost like taking the XML file and using the links within that to output on a page.

Long ago I used a service such as https://www.xml-sitemaps.com/ to create an html sitemap. Maybe that might work for you.

@A3CS your comment about using the XML file gave me an idea to use a Liquid include to call in the XML file and manipulate it from there.

This seems to work ok:

{% capture sitemapData %}{% include '/sitemap.xml' %}{% endcapture %}
{% assign sitemapArray = sitemapData | split: '<loc>' %}

<ul>
{% for i in sitemapArray offset:1 %}
{% assign locArray = i | split: '</loc>' %}
{% assign locUrl = locArray | first %}
{% assign locTitle = locUrl | split: '/' | last | replace: '-', ' ' | titlecase %}
    <li><a href="{{locUrl}}">{{locTitle}}</a></li>
{% endfor %}
</ul>

It will display a list of links and uses the page slug to create the page name (because that’s all we have available in the XML).
If you wanted the true page title or more page data, you could do a Page look-up within each loop based on the URL. But if there are a lot of pages this could get pretty inefficient.

Perhaps this is usable :slight_smile:
Otherwise, a 3rd party service like @hopestew mentioned is probably best.

1 Like

@Adam.Wilson as usual you have great ideas!

1 Like

Totally worked! Thanks Adam!

1 Like

Sweet!
I’ll try to improve it a little and add it to the Treehouse Code snippets.

1 Like