piranha / gostatic

Fast static site generator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[question] Generating sitemap with priority

opened this issue · comments

Hi,

I want to generate a sitemap.xml. I have this preliminary version:

<?xml version='1.0' encoding='UTF-8'?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{{ with .Site.Pages.Children "" }}
{{ range .Slice 0 50000 }}
<url>
  <loc>{{ .Site.Other.Url }}/{{ .Url }}</loc>
  <lastmod>{{ .ModTime.Format "2006-01-02T15:04:05Z07:00" }}</lastmod>
  <changefreq>weekly</changefreq>
</url>
{{ end }}
{{ end }}
</urlset>

But now I want to specify the priority. I want gostatic to put priority 0.8 in about page. This code:

  {{ if (.Url == "About") }}
  <priority>0.8</priority>
  {{ end }}

does not run. How can I achieve that?

Thanks a lot,

Sorry for not answering right away, I was somewhat overwhelmed with real life. :-)

How exactly it does not run? Does it display any errors? Anything else?

This is the output:

Error: Page sitemap.xml: template: ad-hoc:9: unexpected "=" in operand; missing space?
Error: sitemap.xml: runtime error: invalid memory address or nil pointer dereference
Rendering 1 changed pages of 18 total

My code:

<?xml version='1.0' encoding='UTF-8'?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{{ with .Site.Pages.Children "" }}
{{ range .Slice 0 50000 }}
<url>
  <loc>{{ .Site.Other.Url }}/{{ .Url }}</loc>
  <lastmod>{{ .ModTime.Format "2006-01-02T15:04:05Z07:00" }}</lastmod>
  <changefreq>weekly</changefreq>
  {{ if (.Url == "About") }}
  <priority>0.8</priority>
  {{ end }}
</url>
{{ end }}
{{ end }}
</urlset>

Ah! That's weird way of golang templates. If you look here in their docs, you can see there are functions like 'eq', 'ne', 'lt' and stuff like that. So just do {{ if eq .Url "About" }}.

OK. Thanks a lot for the documentation. Lately we have a lot of exciting
conversations.... ;)

2015-09-07 14:45 GMT+02:00 Alexander Solovyov notifications@github.com:

Ah! That's weird way of golang templates. If you look here
https://golang.org/pkg/text/template/#hdr-Functions in their docs, you
can see there are functions like 'eq', 'ne', 'lt' and stuff like that. So
just do {{ if eq .Url "About" }}.


Reply to this email directly or view it on GitHub
#52 (comment).

When will you push a new version? I want to download binary with new features...