Generate tag cloud from post of some author

I need to generate a tag cloud from a list of pages.

I can’t use the built in grouping methods, because I need to filter the pages before grouping.

What I need to do is to display a list of tags, sorted by occurence in posts, for a specific author.

I solved this by doing a very uggly script, but what a I want is a cleaner solution.

{{ $author := index .Site.Taxonomies.authors $authorKey }}
<h2>Tags</h2>
<ul>
{{ $.Scratch.Set "tagsMap" (dict) }}
{{ range $author.Pages }}
    {{ if (isset .Params "tags") }}
        {{ range .Params.tags }}
            {{ $value := default 0 ( index ($.Scratch.Get "tagsMap") . ) }}
            {{ $.Scratch.SetInMap "tagsMap" . ( add $value 1 ) }}
        {{ end }}
    {{ end }}
{{ end }}
{{ range $key, $value := $.Scratch.Get "tagsMap" }}
    {{ $.Scratch.Add "tagsArray" ( slice ( print ( printf "%09d" $value ) ":" $key ) ) }}
{{ end }}
{{ range sort ( $.Scratch.Get "tagsArray" ) }}
    {{ $vals :=  split . ":" }}   
    {{ $value := int ( ( index $vals 0 ) | strings.TrimLeft "0" ) }}
    {{ $label :=  index $vals 1 }}
    <li>{{$label}}</li>
{{ end }} 
</ul>