Sub-Section Unique Tag Collection | 220928
220928
Current Progress
The "{{.IsDescendant $anotherPage}}" is still working from yesterday to change the layout for depending of depth dir in notes.
Getting all tags for a given project and counting the occurrences
_1001
I would like get all the tags for a given project and then have a number for how many times they appeared to do things. I am not positive yet if just going to be a weight thing or just throw the number next to it. then if you click on it do something.
Attempt 1
So I tired to have a slice of dictators with the key word being the term it self and value being how many times it has occurred. Well that was the plan anyway, but when I tired to use the in keyword in hugo to try and search the slice for the maps key it doesn’t work that nice
<!-- Note this does not work -->
<div class="project all-tags container">
{{$sliceName := slice}}
{{$d1 := dict "tagName1" 4}}
{{$d2 := dict "tagName2" 2}}
{{$d3 := dict "tagName3" 7}}
{{$sliceName = append $d1 $sliceName}}
{{$sliceName = append $d2 $sliceName}}
{{$sliceName = append $d3 $sliceName}}
<div>Output of Slice Name: {{$sliceName}}</div>
{{if in $sliceName "tagName1"}}
| true |
{{else}}
| false |
{{end}}
</div>
Output: Output of Slice Name: [map[tagName1:4] map[tagName2:2] map[tagName3:7]] | false |
I am going to play with this for a while to see if can get something similar to work.
Attempt 1.1
Try with Scratch
Gotta play with this a little
Does the NewScratch Overwrite maps with same key or throw an error?
{{$data:= newScratch}}
{{$data.SetInMap "projectTags" "tagName1" 5 }}
{{$data.SetInMap "projectTags" "tagName1" 7 }}
{{$data}}
Output: >{map[projectTags:map[tagName1:7]] {{0 0} 0 0 0 0}}
It overwrites
Just found out that Hugo does not have a get via key function. So it looks like I will have to create my own
Go and hug your normal programming language
Nevermind it kind does have a Get function for slices and maps. It’s call index (for some reason…)
Attempt 2
_1057
{{$data:= newScratch}}
{{$data.SetInMap "projectTags" "tagName1" 5 }}
{{$data.SetInMap "projectTags" "tagName1" 7 }}
{{$data.SetInMap "projectTags" "tagName2" 69 }}
{{$data.SetInMap "projectTags" "tagName3" 420 }}
{{$temp := $data.Get "projectTags"}}
Collection of maps:s{{$temp}}<br/>
Whats at "tagName1" : {{index $temp "tagName1"}}<br/>
Whats at "tagName666" : {{index $temp "tagName666"}}<br/>
{{if (index $temp "tagName1") }}
The Check for key "tagName1" has found something: {{index $temp "tagName1"}}<br/>
{{else}}
The Check for key "tagName1" has found NOTHING <br/>
{{end}}
{{if (index $temp "tagName666") }}
The Check for key "tagName666" has found something<br/>
{{else}}
The Check for key "tagName666" has found Nothing {{index $temp "tagName666"}}<br/>
{{end}}
Output: Collection of maps:smap[tagName1:7 tagName2:69 tagName3:420]
Whats at “tagName1” : 7
Whats at “tagName666” :
The Check for key “tagName1” has found something: 7
The Check for key “tagName666” has found Nothing
Alright will this experimentation complete I think have all the necessary understanding to do this in combination with my tag work prior to this.
Complete Base Logic Complete
_1242
{{with .Param "projectName" }}
<!-- Set the Current Project Name that we will looking for it's Pages-->
{{$projectname := .}}
<!-- Intilize a newScratch to hold the collections of maps of tags them self and number of times they appear in the project's notes -->
{{$projectTagsCollection:= newScratch}}
<!--These 2 need to be Intilized and set or you'll get some nil errors-->
{{$projectTagsCollection.SetInMap "projectTags" "DELETE-ME" "Once Done - Use me and throw me away" }}
{{$tempMap := dict "Just-Need-To-Initialize-This" 666 }}
<!-- Loop over each of the Pages matching the given projectname -->
{{range where site.Pages "Params.project" $projectname}}
<!-- Loop over each of the tags for a given Page -->
{{ range .Params.tags }}
<!--Set tempMap to the "projectTags" from inside projectTagsCollection-->
{{$tempMap = $projectTagsCollection.Get "projectTags"}}
<!-- Check to see if Tag is in the collection of maps-->
{{if (index $tempMap .)}}
<!-- If the current Tag is already in the Collection of maps Key-->
<!-- We take the value at that tag and add one to it and set it to a temp-->
{{$plusOne := add (index $tempMap .) 1}}
<!-- Then the new couter value is overwritten at the current tags key value in the collection of project tags -->
{{$projectTagsCollection.SetInMap "projectTags" . $plusOne}}
{{else}}
<!-- If the current Tag is NOT in the Collection of maps Key-->
<!-- Then we add to the collection with value of 1 -->
{{$projectTagsCollection.SetInMap "projectTags" . 1}}
<!-- I want to limit the exposer place holder DeleteMe so I delete it as soon as there is another key inserted -->
<!-- Yes I am aware that its a waste to keep this here for every new tag-->
{{$projectTagsCollection.DeleteInMap "projectTags" "DELETE-ME"}}
{{end}} <!--end of if -->
{{end}}<!-- end of range of tags -->
{{end}}<!-- end of pages that make project name -->
{{$projectTagsCollection.Get "projectTags"}}
{{end}}
Output: map[bitnami:1 devblog:2 ingress:1 keycloak:2 kubernetes:1 local-dns:1 minikube:1 postgres:1]
With my current number of post/notes these tags do indeed add up.
_1309
Alright I am done with that side quest