Rewrite recursive menu code with ancestors?

To close this topic, a rewrite of the last proposed file. Instead of listing the pages and sections at the root, I set the context at the home page. And I launch the recusivity.:

 {{ define "subpages" }}
    {{ $thePage := .currentPage }}
    <ul>
        {{ range .context.Pages }}
            <li>
                <a href="{{ .RelPermalink }}">{{ .RelPermalink }} </a>
                {{ if or (.IsAncestor $thePage) (eq . $thePage) }}
                    {{ template "subpages" (dict "context" . "currentPage" $thePage ) }} 
                {{ end }}
            </li>
        {{ end }}
    </ul>
{{ end }}


{{ $thePage := .Page }}
{{ $context := .GetPage "/" }}
{{ template "subpages" (dict "context" $context "currentPage" $thePage ) }}

With Hugo > 0.111 and the global page function:

{{ define "subpages" }}
    <ul>
        {{ range .Pages }}
            <li>
                <a href="{{ .RelPermalink }}">{{ .Title }}</a>
                {{ if or (.IsAncestor page) (eq . page) }}
                    {{ template "subpages" . }} 
                {{ end }}
            </li>
        {{ end }}
    </ul>
{{ end }}


{{ $context := .GetPage "/"}}
{{ template "subpages" $context }}