Calendar (ics) template

Not mine, but glad to see someone using the Custom Output Formats:

8 Likes

I’m trying to use this to generate an ICS file from a list on “event” entries for a colloquia page. I can’t seem to manage to generate the ICS file or the URL to include. Can you provide a pointer to where this is documented? Or a list of steps? There is very little I could find. I tried to add this in my site toml file

[outputs]
event =   ["HTML","RSS","Calendar"]
colloquia = ["HTML","RSS","Calendar"]
page = ["HTML"]

based on the fact that the URL for the page wit the list of events is:
http://localhost:58731/event/colloquia/

The colloquia bit is a taxonomy of events and all events have metadata like that:

---
title: "SQL on Structurally-Encrypted Databases"
date: 2017-10-02T12:30:00-13:30
draft: false
event : "colloquia"
---

I’ve seen posts mentioning _default/single.ics in layouts. I thought this was the above. But that does not seem to get me anywhere.

Hints?

Maybe I am missing something built-it. Where can I find a “single.ics” example? I have tried adding:
[outputs]
event = ["HTML","Calendar"]

to my config.toml file and I cannot get my build to create an ICS file. It does create the HTML file though.

I have also tried adding:
outputs:
- html
- calendar
to the frontmatter of the event md but that has no impact on the build either.

I have learned that if I cannot find an answer by googling around the docs and discourse that I am usually missing something built-in.
My site is structured:
content
-- blog
-- event
Is that the issue?

Answering my own question here, correct me if I am totally off base.
Under layouts\event\ I added single.ics with the following structure:

BEGIN:VCALENDAR
CALSCALE:GREGORIAN
METHOD:PUBLISH
VERSION:2.0
BEGIN:VEVENT
DTSTAMP:{{dateFormat "20060102T150405" .Date}}
STATUS:CONFIRMED
UID:{{dateFormat "20060102T150405" .Params.start}}@ableblue.com
DTSTART:{{dateFormat "20060102T150405" .Params.start}}
DTEND:{{dateFormat "20060102T150405" .Params.end}}
SUMMARY:{{.Title}}
DESCRIPTION:{{.Params.description}} (Info: {{with .Params.link}}{{.}}{{else}}{{.Permalink}}{{end}})
LOCATION:{{with .Params.location}}{{.}}{{else}}TBD{{end}}
X-ALT-DESC;FMTTYPE=text/html:{{.Title}}<br>Location: {{with .Params.location}}{{.}}{{else}}TBD{{end}}<br>{{with .Params.link}}{{.}}{{else}}{{.Permalink}}{{end}}
END:VEVENT
END:VCALENDAR

In the frontmatter of my event md content I added:

outputs: 
- HTML
- Calendar 

In the layouts/event/single.html file I added a link to the ics file with:

{{ with  .OutputFormats.Get "calendar" -}}
  <a href="{{ .Permalink | safeURL }}">Add this event to your calendar.</a>
{{- end }}

Finally, I didn’t like the default webcal:// protocol so I added the following to my config file:

[outputFormats.Calendar]
	protocol = "https://"

The more I work with Hugo the more impressed I am with the though and capability. It is really amazing. I hope this post helps someone in my situation.

I see where the confusion comes from, and we should fix that.t

Currently you can set output format either:

  • per “page kind” (which can be set per language if needed). This means that you can say “I want the home page (a kind) to be output as HTML and RSS” etc.
  • per page (as in your last post)

So, you can say “I want to output calendar for single pages” you cannot say “I want to output calendar for only pages in the event section”. That would be useful. A current workaround is possible to say:

[outputs]
page = [“HTML”,“Calendar”]

And then create the calendar single template in layouts/event. But adding it to directly to the front matter of the individual pages works, too.

@bep, thanks for the confirmation that I didn’t miss anything. If I did add:

[outputs]
page = ["HTML","Calendar"]

That would create an *.ics for my blog posts too, right?

In the mean time I just added the

To my event archetype.

Now I just need to figure out how to get the time zones working in the ICS file. I added -0700 to the time output but it’s not quite right.

I think it will try … but if you put the ics template in /event only, it will fail … which may get you what you want; which would be rather hacky …

Agreed…

And while we’re talking about hacky, I “solved” the timezone issue with a partial that forces the ics entry for the selected time zone. For a conference in Haarlem I have this in my single.ics file:

BEGIN:VTIMEZONE{{- partial "timezone.html" .Params -}}END:VTIMEZONE

…and this is just one entry in my partial.

{{ $tz := .timezone }}
{{ with (eq $tz "W. Europe Standard Time") }}
TZID:W. Europe Standard Time
BEGIN:STANDARD
DTSTART:16011028T030000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:16010325T020000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
END:DAYLIGHT
{{ end }}

I added entries for the US and UK/European Countries I needed, but there must be a better way.

HI,
I want to list all events with .ics format like url - https://www.example.com/events.ics

single.ics is working fine for me, but still struggling with listing of all events in a page with .ics format.