Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generating feeds with files not ending in xml/html #2772

Open
seam345 opened this issue Jan 13, 2025 · 7 comments
Open

Generating feeds with files not ending in xml/html #2772

seam345 opened this issue Jan 13, 2025 · 7 comments

Comments

@seam345
Copy link

seam345 commented Jan 13, 2025

Bug Report

Environment

Zola version: zola 0.19.2

Expected Behavior

I can put any file extension in the templates folder and it be counted as a template, or failing that entering it as a feed_filename should convert it to a template for rendering feeds

Current Behavior

sean@little-my ~/G/G/R/website (master)> zola serve
Building site...
Checking all internal links with anchors.
> Successfully checked 0 internal link(s) with anchors.
-> Creating 6 pages (0 orphan) and 3 sections
Error: Failed to serve the site
Error: Tried to render `cal.ics` but the template wasn't found
sean@little-my ~/G/G/R/website (master) [1]> ls -l templates/cal.ics
-rw-r--r-- 1 sean users 716 Jan 13 13:37 templates/cal.ics

Step to reproduce

  1. change feed filenames to feed_filenames = [ "atom.xml", "cal.ics"]
  2. create a file in templates named cal.ics
  3. zola serve will fail with the above error

Optionally clone and zola serve https://gitlab.com/rust-manchester/website

Additionally I forked zola to see if what I was attempting was possible and got a working version using
seam345@0cb8148
This was very hacked together though and only works for .ics extensions I imagine there are many more plain text formats that could be used to generate feeds in the same way

Did work though :D https://rustmanchester.co.uk/events/cal.ics

@seam345
Copy link
Author

seam345 commented Jan 13, 2025

#2768 is related but a much more narrow use case

@Keats
Copy link
Collaborator

Keats commented Jan 13, 2025

For feeds I prefer to keep the control a bit tight around it. I think adding calendar support would be cool though

@seam345
Copy link
Author

seam345 commented Jan 14, 2025

oki, are you thinking about having it as a builtin then?

If so I can work on improving the template for a PR

if someone else with more zola experience worked on the code side that would be ace, otherwise I'll try properly develop my hacked solution after finalising the ics template

@seam345
Copy link
Author

seam345 commented Jan 19, 2025

my current working template is

{# NOTE: lines need to be terminated with CRLF, use unix2dos if on linux #}
{# for now I have ignored timezones, I didn't really understand them #}
{%- if feed_url is containing("events") -%}
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//zola/{{ config.title }}

{%- for page in pages %}
BEGIN:VEVENT
UID:{{ page.permalink | safe }}

{#- DTSTAMP, when the calender entry was made #}
{#- I pondered page.date, but I wanted to set the page date as the date of the event... it made sense for current rss
feed and for prepending file name to know the dates of the page events, but then doesnt work here for when the event was published
  however it probably wouldnt break anything if we go back to page.date#}
DTSTAMP:{{ page.extra.cal_published | date(format="%Y%m%dT%H%M%S") }}
LAST-MODIFIED:{{ page.updated | default(value=page.date) | date(format="%Y%m%dT%H%M%S") }}

{%- if page.extra.start_date %}
DTSTART:{{ page.extra.start_date | date(format="%Y%m%dT%H%M%S") }}
{%- endif %}

{%- if page.extra.end_date %}
DTEND:{{ page.extra.end_date | date(format="%Y%m%dT%H%M%S") }}
{%- endif %}

{#- make breakline #}
SUMMARY:{{ page.title }}

{%- if page.summary %}
DESCRIPTION:{{ page.summary }}
{% else %}
DESCRIPTION:{% for char in page.content | linebreaksbr | replace(from="<br>", to="\n") | striptags -%}
{{ char }}
{#- cap lines at 75 chars (really wants 75 octets, so this works for english but different unicodes will likely break this)
 tested with japanese kanji and validating with https://icalendar.org/validator.html didn't give any errors -#}
{%- if loop.index / 73 < 1 -%}
{%- if loop.index % 60 == 0 %}
 {% endif %}
{%- else -%}
{%- if loop.index % 73 == 60 %}
 {% endif %}
{%- endif %}
{%- endfor %}
{%- endif %}

{%- if page.extra.geo %}
GEO:{{ page.extra.geo }}
{%- endif %}
END:VEVENT
{%- endfor %}
END:VCALENDAR
{%- endif %}

DTSTAMP, I was quite unsure what to set this too I guess ideally it would be page.date, but I quite like having the page date the event date can be convinced thats a bad idea though.

Variables I added were:

  • page.extra.geo to set location info
  • page.extra.start_date
  • page.extra.end_date
  • page.extra.cal_published for DTSTAMP but this maybe better as page.date as mentioned above

@Keats
Copy link
Collaborator

Keats commented Jan 19, 2025

I think it would be fine to add but I don't know anything about .ics so I wouldn't really know what we need

@seam345
Copy link
Author

seam345 commented Jan 20, 2025

I think it would be fine to add but I don't know anything about .ics so I wouldn't really know what we need

At the moment the above template validates against an online validator https://icalendar.org/validator.html?url=https://rustmanchester.co.uk/events/cal.ics

The only new things that are needed are a start and end date, geo is optional and the other things are mostly the same as atom feed like description and title.

@Keats
Copy link
Collaborator

Keats commented Jan 21, 2025

Yeah the issue is how to handle the optional things that need to be put in the [extra] section. If it's well documented maybe it's fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants