solspace / craft-calendar

Calendar for Craft: The most reliable and powerful event management plugin for Craft.
http://docs.solspace.com/craft/calendar/v5
Other
15 stars 16 forks source link

No bounds on calendar means web spiders crawl the links relentlessly #171

Closed elibird closed 2 years ago

elibird commented 2 years ago

I am maintaining a Craft 3 site w/ the calendar plugin, and noticed that Craft's /storage/runtime/cache folder was filling up with tens of thousands of files and using tens of gigabytes of space.

I tracked the issue down by examining the webserver's access logs and found various spiders crawling the "next" and "last" links, resulting in dates both very far in the future and past.

I modified the twig templates (month.html, day.html, week.html) to include something like the following:

{% set month = craft.calendar.month({
    date: targetDate,
    calendar: calendarHandle,
}) %}

{% set the_diff = now.diff(month.nextDate)|date('%r%a') %}

<!-- CALENDAR NAVIGATION - MONTHS -->
<div class="calendar-nav mb-3">

    {% if the_diff > -365 %}
        <div class="btn-prev">
            <a class="btn btn-outline-secondary"
href="{{ siteUrl }}{{ calendarBasePath }}{{ month.previousDate.format('Y/m') }}{{ urlParamsString }}">
                <span class="fas fa-arrow-left"></span><span class="d-none d-sm-inline"> {{ month.previousDate.format('F') }}</span>
            </a>
        </div>
    {% else %}
        <div><!-- no link for spiders, but add an empty div to not break the layout --></div>
    {% endif %}

So, this is more of a feature request, but it would be nice if I could go into the general settings of the plugin and set bounds on the links like I've done in the template, so that at a certain length of time either forwards or backwards, the "next" and "last" links no longer appear.

Craft & Plugin Info (please complete the following information):

kjmartens commented 2 years ago

Sorry for the delay @elibird.

Thanks for this suggestion. I'll make a note of the bounds setting idea for future consideration, and we'll also consider adding the workaround to the demo templates and documentation. 🙂