SVGs, Break Statements & HUGO | 220923


220923

_0121

Quick add to the project list page to pull the think Github link form the projects front matter, then just in case in the link. Use a dictionary to pass the values to a partial to dictate the size of the svg

<!-- /ed-m/layouts/notes/list.html -->
...
<!--If there is github in the project index front matter then makes pull the github svg and put in the link to the projects base github-->
{{with  .Param  "github"}}
	{{  $githubAsset := resources.Get  "/svgs/github.svg"  }}
	<a  class="github-svg"  href={{.}}>
		<!-- Simple Dictonary insert for the nessary values for for the SVG size -->
		{{  partial  "github-svg.html" (dict  "width"  30  "height"  30 ) }}
	</a>
{{end}}
...

Side note: I notice I keep finding my self on this one site to better understand basic css implementation and wanted to share it. https://css-tricks.com/snippets/css/ . I know the URL looks like bullshit site, but some of the new articles are full of digrams and example code that I find really helpful.

_0651 Current Progress.

0651

Trying to get the post count for a given project

So while trying to fill up some space I thought of a few project stats I could do with out writing a webhook into github(maybe another day). So I am trying to use the index version of range in hugo with where as well but getting some errors. I kinda expected this.

<!-- Expected input project name -->
{{with  .Param  "projectName"  }}

	<!-- Set the Current Project Name that we will looking for it's Pages-->

	{{$projectname := .}}
	{{$index := 1}}

	{{range  where  $index, site.Pages  "Params.project"  $projectname}}

		{{$index}}
	{{end}}
{{end}}

Leads to it not knowing why the common is there

issue

And if you take it out

another error

It tries to iterate over the set index. So i am going out limb guess you can’t use range where with an index as well.

That’s fine. I can use Scratch to count for me.

With a few more lines of hugo funky code we can count.

<!--/ed-m/layouts/partials/num-post-for-project.html -->
<!-- Expected in put project name -->
{{with  .Param  "projectName"  }}

	<!-- Set the Current Project Name that we will looking for it's Pages-->
	{{$projectname := .}}
	<!-- Had to use Scratch to count for us cause I could'nt get the index to work with where-->
	{{  $.Scratch.Set "betterIndex"  0  }}
	{{range  where site.Pages  "Params.project"  $projectname}}
		{{  $.Scratch.Set "betterIndex" (add 	($.Scratch.Get "betterIndex") 1) }}
	{{end}}
	<!--Displays the Total number Post for the given project -->
	{{$.Scratch.Get "betterIndex"}}
{{end}}

Finished result

I know this is a simple things, but I know once I move on from working on this site, I am going to forget how hugo works.

I idea of counting the elements iterated over a loop is not a diffcult one, but how to do this in hugo sytanx is a little hard. I am learning it now, but can’t see myself working with everyday once the project is completed my knowledge gains of may become a skill leakage point.


_0831

Hugo has no break statement…

yeah

I mean that post is from 2017. They could have put in by now. Yeah… I can’t find it anywhere in the docs. or external sites so woo.

but it does let me do dumb things like this.

<!-- /ed-m/layouts/partials/last-date-of-post-for-project.html -->
{{with  .Param  "projectName"  }}
	{{$projectname := .}}
	{{$WTFisABreakStatment := true}}
	{{range  where site.Pages.ByDate  "Params.project"  $projectname  }}
		{{if  $WTFisABreakStatment}}
			<time>{{  .Date.Format  "Mon, Jan 2, 2006"  }}</time>
		{{else}}
			<!-- Do fuck all -->
		{{end}}
	{{$WTFisABreakStatment = false}}
	{{end}}
{{end}}

Elegant: No Efficient Computationally or Memory wise: No Kinda Goofy to write: Yes…