Creating Labarum (Part 4): Initiating the Index

In the beginning of this series, we started off with an index page that was just a static page with one line that stated you were on the index page. When it comes to implementing this, I looked at the Hugo Themes Free as well as the theme gallery that Micro.blog provides.

Ultimately, I went with a simple structure that took advantage of the simplicity that I had in the Pure theme and the fact that we had already extracted the logic for articles into the partials.

{{- range ( .Paginate (where .Site.RegularPages "Type" "post")).Pages }}
{{ partial "article.html" . }}
{{ end }}

After that, we remove all the static <article> tags that we placed into our index to see how it renders. This looks ok, but the design that I have in mind calls for pagination1(being able to go to older posts).

Paging the index

I admit that I went down a rabbit hole of different examples of how to create the navigation that you see at the bottom of the page. A lot of the examples that I came across where hard coded or I couldn’t understand.

Ultimately, I went with the example that I had from my previous theme. I took the code and placed it into a file name partial\site-navigation.html so that I can track it later.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
{{ "<!-- Site Pagination -->" | safeHTML }}
{{ $paginator := .Paginate (where .Data.Pages.ByDate.Reverse "Type" "post") (index .Site.Params "archive-paginate" | default 10) }}
<nav class="pagination">
	{{- if $paginator.HasPrev -}}
	<p class="nav_prev">
		<a href="{{ $paginator.Prev.URL }}" title="Previous Page" rel="prev">
		← Newer Posts
		</a>
	</p>
	{{- end }}

	{{ if $paginator.HasNext -}}
	<p class="nav_next">
		<a href="{{ $paginator.Next.URL }}" title="Next Page" rel="next">
		Older Posts →
		</a>
	</p>
	{{- end }}
</nav>

On the first line, I’m adding a line that will show up in the final output of the generated site so I can see where Hugo is inserting the code.

The second line calls the default paginator to go over all the posts that the site has by whatever parameter that is given. If none is given, it will use 10.

Line 3 defines our semantic element for the navigation and give it a class for styling it later.

Line 4-10 tests to see if there is a previous page and then creates a link to the page when it exists.

Line 12-18 tests to see if there is a next page and creates everything that’s needed.

The navigation was another thing that I spent a lot of time looking into, but ultimately went with a simple ordered list of items.

The initial design did not have a link to the home page because I thought that anyone how came across the page would only be interested in that page and not the additional content, but after having to go to the address bar multiple times to navigate between the different pages, I decided to add it as the first item.

I placed this into a separate file called site-nav.html like I did for pagination for better tracking.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
{{ "<!-- site-nav.html -->" | safeHTML }}
<nav>
	<menu>
		{{ if ne .IsHome true }}
		<li><a href="{{ .Site.BaseURL }}" title="{{ .Site.Title }}">Home</a></li>
		{{ end }}
		{{- range .Site.Menus.main }} 
		<li><a href="{{ .URL | relLangURL | safeURL }}">{{ .Name }}</a></li>
		{{ end -}}
		<li><a href="{{ "feed.xml" | absURL }}" rel="feed" type="application/rss+xml" title="{{ $.Site.Title }}">RSS</a></li>
	</menu>
</nav>

On line 3, I used the <menu> semantic tag to give it some more meaning. It definitely felt that it took some time to On line 3, I used the <menu> semantic tag to give it some more meaning. It definitely felt that it took some time to get a consensus on whether I needed to add a <ul> or <ol> to make the syntax valid.

Line 4 does a test to see if the generated page is the home page. This is working to an extent, but fails when moving to the second index page.

Line 7 sorts through the different menu items. I had an issue trying to understand how Hugo puts together a menu on my local copy and what was being used in Micro.blog.

Line 10 gives a direct link to the RSS feed for the site. The RSS feed is inherited from the base blank theme that underlies of Micro.blog.

The next segment of this tutorial will be focused on the schema tags followed by accessibility and then a grab bag of different things.

Please let me know if you have any questions about the design so that I can make this better. I think I might put this all together in one LARGE post at the end.


  1. I’ve come across a couple sites that only have the index and then has the user search or go through an archive to find older material. The argument being that most users only want to read your most current entries or have something specific that they are looking for.

    I’m going to go with what I feel is a classic approach and revisit this later. ↩︎

Categories: Labarum

Published:

Debug

Site Properties

		&hugolib.SiteInfo{Authors:page.AuthorList(nil), Social:hugolib.SiteSocial(nil), hugoInfo:hugo.Info{CommitHash:"1798bd3f", BuildDate:"2021-12-23T15:33:34Z", Environment:"production"}, title:"Mandaris", RSSLink:"https://mandarismoore.com/feed.xml", Author:map[string]interface {}{"avatar":"https://micro.blog/mandaris/avatar.jpg", "name":"Mandaris Moore", "username":"mandaris"}, LanguageCode:"en", Copyright:"", permalinks:map[string]string{}, LanguagePrefix:"", Languages:langs.Languages{(*langs.Language)(0xc00080dba0)}, BuildDrafts:false, canonifyURLs:false, relativeURLs:false, uglyURLs:(func(page.Page) bool)(0x163ea20), owner:(*hugolib.HugoSites)(0xc0000ed600), s:(*hugolib.Site)(0xc000592d80), language:(*langs.Language)(0xc00080dba0), defaultContentLanguageInSubdir:false, sectionPagesMenu:""} 

		

site.Params Properties

		maps.Params{"description":"Follow <a href=\"https://micro.blog/mandaris\">@mandaris on Micro.blog</a>.", "feeds":maps.Params{"bookmarks_json":"https://micro.blog/feeds/mandaris/bookmarks/08117195b525afe4a55f.json"}, "github_username":"mandaris", "include_conversation":true, "instagram_username":"mandaris", "itunes_author":"Mandaris", "itunes_category":"Society & Culture", "itunes_cover":"https://micro.blog/mandaris/podcast.png", "itunes_description":"A High-quality stranger. I've considered myself a digital gofer. Y'know, go for this and go for that. I'm using micro.blog now to par down my technical projects and be part of an outstanding community.  Apple Game Center: MrMandaris  Email: Contact@MandarisMoore.com", "itunes_email":"podcast@mandarismoore.com", "itunes_subcategory":"Personal Journals", "mainSections":[]string{"replies"}, "mainsections":[]string{"replies"}, "paginate_categories":true, "paginate_home":true, "paginate_replies":true, "plugins_css":[]interface {}{}, "plugins_html":[]interface {}{}, "plugins_js":[]interface {}{}, "site_id":"661", "theme_seconds":"1675089916", "twitter_username":"mandaris"}
		

Permalink

		"https://mandarismoore.com/2023/01/11/creating-labarum-part.html" 

		

Params

		map[categories:[Labarum] date:2023-01-11 11:02:30 -0800 -0800 draft:%!s(bool=false) guid:http://mandaris.micro.blog/2023/01/11/creating-labarum-part.html iscjklanguage:%!s(bool=false) lastmod:2023-01-11 11:02:30 -0800 -0800 layout:post microblog:%!s(bool=false) publishdate:2023-01-11 11:02:30 -0800 -0800 title:Creating Labarum (Part 4): Initiating the Index type:post url:/2023/01/11/creating-labarum-part.html]
		

All variables scoped to the current context

		&hugolib.pageState{pageOutputs:[]*hugolib.pageOutput{(*hugolib.pageOutput)(0xc00273a6c0), (*hugolib.pageOutput)(0xc00273a7e0), (*hugolib.pageOutput)(0xc00273a900), (*hugolib.pageOutput)(0xc00273aa20), (*hugolib.pageOutput)(0xc00273ab40), (*hugolib.pageOutput)(0xc00273ac60), (*hugolib.pageOutput)(0xc00273ad80), (*hugolib.pageOutput)(0xc00273aea0)}, pageOutput:(*hugolib.pageOutput)(0xc00273a6c0), pageCommon:(*hugolib.pageCommon)(0xc00194c000)}