Site Map
Prior to rendering the Site Render Engine will create a SiteMap containing searchable information
about all of the Collection and Page objects it has.
Searching the SiteMap
To search the SiteMap use the find method.
def find(
self,
value: str,
attr: str = "slug",
collection: str = None,
full_search: bool = False,
) -> SiteMapEntry | None:
Parameters
value: The value to search forattr: Optional attribute to search by. Options areslug,title,path_name. Defaults toslug.collection: Limit the search to a singleCollection. Defaults toNone.full_search: Search allPageandCollectionobjects. Defaults toFalse.
Notes:
- If
collectionis set the search will be limited to thatCollectionobject regardless of whetherfull_searchis set. - If
full_searchis set it will return the first match found. If you have 3 pages with the sameslug, 1 not in aCollectionand 2 others in differentCollectionobjects, the first one defined will be the one found.
Generating an HTML site map
The SiteMap object has an html property that will return an HTML sitemap with absolute URLs with the
Site's SITE_URL.
As a convenience, Render Engine will generate a site map page if the Site property of render_html_site_map
is True (it defaults to False.) Please note that this will not be templated. Should you wish the generated
site map to be on a template you can add the following to your app:
@app.page
class SiteMapPage(Page):
template = "site_map_template.html"
content = "{{ site_map.html }}"
skip_site_map = True
Please note the skip_site_map = True to avoid having a self-referential link to the site map.
Generating an XML site map
To have your site generate an XML site map set the render_xml_site_map property of your Site object
to True (defaults to False.) This will create the site_map.xml file in the root output directory
of your site.
The SiteMapEntry object
The SiteMap is a collection of SiteMapEntry objects. Each SiteMapEntry has the following attributes
and properties:
Attributes and Properties
slug- Theslugfor the referencedPageorCollection.title- Thetitlefor the referencedPageorCollection.path_name- Thepath_namefor the referencedPageorCollection.entries- A list ofSiteMapEntryobjects representing thePageobjects in a givenCollection. for aPagethis will be an emptylist.url_for- This property will provide the relative URL for the given entry.