Grabbing the right Meta description from Config.toml?

Hello!
WARNING: Mucho pasta! Spaghetti code below, mmm mama mia!

How can I grab the right string of text for a meta description from my Config.toml?

This is what I am doing so far to achieve this:

My pages are made into .Section (/about/, /support/ etc). Each at its own folder in the root. Some of them are under /content/, some under partials/pages/ as templates. (It isn’t all over the place, its done like this for a reason.)

I want to grab the string from my Config.toml

[params.pages]
	about =     "This is a description for the about page."
...

And here is my meta description from my header.html

<meta name="description" content="
	{{- if .IsHome -}}
		{{- $.Site.Params.description -}}  /// this is for the main site
	{{- else if .IsSection -}}
		{{- if eq .Section "about" -}}
			{{- $.Site.Params.Pages.about -}}
		{{- else if eq .Section "support" -}}
			{{- $.Site.Params.Pages.support -}}
		{{- else if eq .Section "privacy" -}}
			{{- $.Site.Params.Pages.privacy -}}
		{{ else if eq .Section "site_map" -}}
			{{- $.Site.Params.Pages.site_map -}}
		{{- else if eq .Section "press_room" -}}
			{{- $.Site.Params.Pages.press_room -}}
		{{- else if eq .Section "video_policy" -}}
			{{- $.Site.Params.Pages.video_policy -}}
		{{- else if eq .Section "support" -}}
			{{- $.Site.Params.Pages.support -}}
		{{- else if eq .Section "contact" -}}
			{{- $.Site.Params.Pages.contact -}}
		{{- else if eq .Section "publishing" -}}
			{{- $.Site.Params.Pages.publishing -}}			
		{{- end -}}
	{{- .Params.description -}}
	{{ else }}
		{{- .Params.description -}}
	{{- end -}}">

Behold. This works. But since some of my pages are in content/blog/ and others are at the root, I have to access the config.toml with $.Site.Params., otherwise it won’t work. No biggie.

Can someone lend a hand and let me know how can I do this code I posted, as a function or something, in a more elegant way? Because really, i am no fan of spaghetti code.

Do you need to put that information in the config.toml file? Looks like it would make more sense in the frontmatter and then you could do something like

{{ with .Params.description }} {{ . }} {{ end }}

1 Like