HUGO

Need Schema

<script type="application/ld+json">
{
    "@type": "Blog",
    "url": "{{.Site.BaseURL}}",
    "headline": "{{.Site.Title}}",
    "description": "{{.Site.Params.description}}",
    "blogPost": [
    {{ range (where .Site.Pages "Kind" "page") }}
        {
            "@type": "BlogPosting",
            "headline": "{{.Title}}",
            "name": "{{.Title}}",
            "url": "{{.Permalink}}",
            "mainEntityOfPage": "{{.Permalink}}",
            "dateModified": "{{.Params.updateDate}}",
            "datePublished": "{{.Date}}",
            "author": {
                "@type": "Person",
                "name": "{{.Site.Params.siteAuthor}}",
                "description": "{{.Site.Params.AuthorBio}}",
                "image": { "@type": "ImageObject", "url": "{{.Site.Params.AuthorImage | absURL }}"}
            },
            "publisher": { "@type": "Organization", "name": "{{.Site.Title}}", "logo": { "@type": "ImageObject", "url": "{{.Site.Params.image | absURL}}" } },
            "image": { "@type": "ImageObject", "url": "{{.Params.image | absURL}}"},
            "commentCount": "0",
            "comment": "",
            "wordCount": {{.WordCount}}
        },
    {{ end }}
    ]
}

Here’s the output

{
@type”: “Blog”,
“url”: “http://localhost:1313/”,
“headline”: “MY NEW HUGO WEBSITE”,
“description”: “HUGO DISCRIPTION”,
“blogPost”: [

            {
                "@type": "BlogPosting",
                "headline": "The Full Affiliate Package",
                "name": "The Full Affiliate Package",
                "url": "http:\/\/localhost:1313\/full-amazon-affiliate-package-theme\/",
                "mainEntityOfPage": "http:\/\/localhost:1313\/full-amazon-affiliate-package-theme\/",
                "dateModified": "2020-08-23T08:07:08.341Z",
                "datePublished": "2020-08-23 08:07:06.345 \u002b0000 UTC",
                "author": {
                    "@type": "Person",
                    "name": "Erik Bolinder",
                    "description": "There is your Authoer Bio",
                    "image": { "@type": "ImageObject", "url": "http:\/\/localhost:1313\/images\/author.png"}
                },
                "publisher": { "@type": "Organization", "name": "MY NEW HUGO WEBSITE", "logo": { "@type": "ImageObject", "url": "http:\/\/localhost:1313\/images\/site_banner.png" } },
                "image": { "@type": "ImageObject", "url": "http:\/\/localhost:1313\/uploads\/linux-laptop-for-programming.jpg"},
                "commentCount": "0",
                "comment": "",
                "wordCount":  838 
            },
        
            {
                "@type": "BlogPosting",
                "headline": "Website Title",
                "name": "Website Title",
                "url": "http:\/\/localhost:1313\/seo-selfie-website\/",
                "mainEntityOfPage": "http:\/\/localhost:1313\/seo-selfie-website\/",
                "dateModified": "2020-08-18T12:58:37.542Z",
                "datePublished": "2020-08-18 12:58:36.282 \u002b0000 UTC",
                "author": {
                    "@type": "Person",
                    "name": "Erik Bolinder",
                    "description": "There is your Authoer Bio",
                    "image": { "@type": "ImageObject", "url": "http:\/\/localhost:1313\/images\/author.png"}
                },
                "publisher": { "@type": "Organization", "name": "MY NEW HUGO WEBSITE", "logo": { "@type": "ImageObject", "url": "http:\/\/localhost:1313\/images\/site_banner.png" } },
                "image": { "@type": "ImageObject", "url": "http:\/\/localhost:1313\/uploads\/graphics-card-explained.jpeg"},
                "commentCount": "0",
                "comment": "",
                "wordCount":  1406 
            },
        
            {
                "@type": "BlogPosting",
                "headline": "Another Post Website Title",
                "name": "Another Post Website Title",
                "url": "http:\/\/localhost:1313\/another-post\/",
                "mainEntityOfPage": "http:\/\/localhost:1313\/another-post\/",
                "dateModified": "2020-08-18T12:30:48.667Z",
                "datePublished": "2020-08-18 12:30:48.646 \u002b0000 UTC",
                "author": {
                    "@type": "Person",
                    "name": "Erik Bolinder",
                    "description": "There is your Authoer Bio",
                    "image": { "@type": "ImageObject", "url": "http:\/\/localhost:1313\/images\/author.png"}
                },
                "publisher": { "@type": "Organization", "name": "MY NEW HUGO WEBSITE", "logo": { "@type": "ImageObject", "url": "http:\/\/localhost:1313\/images\/site_banner.png" } },
                "image": { "@type": "ImageObject", "url": "http:\/\/localhost:1313\/uploads\/operating-system-display.jpg"},
                "commentCount": "0",
                "comment": "",
                "wordCount":  1268 
            },
        
        ]
    }
</script>

I want to remove the comma in the last range, so that it doesn’t return an error!

Do something like this:

{{- $comma := false -}}
{{- range seq 5 -}}
  {{- if $comma -}},{{- end -}}{{ . }}
  {{- $comma = true -}}
{{- end -}}

To produce:

1,2,3,4,5
1 Like
{{- $comma := false -}}

<script type="application/ld+json">

    {

        "@context": "https://schema.org/",

        "@type": "SiteNavigationElement",

        "name": ["

            {{- range .Site.Menus.mainmenu -}}

            {{- if $comma -}},{{- end -}}{{ .Name }}

            {{- $comma = true -}}

            {{- end -}}"],

        "url": [ "{{- range .Site.Menus.mainmenu -}}

                {{- if $comma -}},{{- end -}}{{ .URL | absURL }}

                {{- $comma = true -}}

                {{- end -}} "]

    }

</script>

Tried It Sir, but the output is different now. Below is the output.

<script type="application/ld+json">
    {
        "@context": "https://schema.org/",
        "@type": "SiteNavigationElement",
        "name": [",Home,Knowledge Base,Reviews,News"],




        "url": [ ",http:\/\/localhost:1313\/,http:\/\/localhost:1313\/,http:\/\/localhost:1313\/,http:\/\/localhost:1313\/"]
    }
</script>

It’s output is another comma before the url and menu name.

Your logic is wrong. You have to initiate this variable before each loop.

In your code it is always true.

1 Like
{{ range $comma, $e := .Name }}
{{ if $comma }},{{ end }}

EXAMPLE:

// This is how I handle the end comma in my 'schema' 'JSON' nodes
{{ $part := .Params.hasPart }}

            "hasPart": [
            {{ if $part }}
            {{ range $comma, $e := $part }}
            {{ if $comma }},{{ end }}
            {
                "@type"         : "Clip",
                "name"          : {{ .clipName }},
                "startOffset"   : {{ .clipStart }},
                "endOffset"     : {{ .clipEnd }},
                "url"           : {{ .clipURL }}
            }
            {{ end }}
            {{ end }}
            ],