Add option to limit calendar navigation (infinite pages!)

Created on 21 November 2019, over 5 years ago
Updated 7 February 2025, 4 months ago

Context:

Calendar (e.g. month) navigation always shows relative +/- 1 unit links like
calendar/month/201910 +1 or -1

Problem:

We found that crawlers follow these links to an infinite amount of pages.
For some sites it might be okay to have no limit, but for most you may want to "end" the calendar to stop crawlers from infinite crawling empty calendars.

Proposed solution:

Add an option to select a date range (absolute or relative) to show calendar navigation for
Add an option to set "rel=nofollow" on the Prev / Next links (which will not stop all crawlers but it may help).

Is there any workaround?

πŸ› Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡©πŸ‡ͺGermany 4kant

    In Drupal 7 we could limit navigation this way:

    1. filter (limit) nodes by a relevant date field (e.g. < +14 days)
    2. in navigation: choose "Page by Date" and check "Skip empty pages"

    In Drupal 11 Filters work in lists etc., but not in calendars.
    I haven't found a working filter in any calendar module yet. (Maybe someone can help me with this...)

  • No changes are likely going to be made for Drupal 7, since that version of Drupal is no longer supported.

  • πŸ‡©πŸ‡ͺGermany 4kant

    That wasn't my intention either.
    I just wanted to show how the limitation could be implemented in Drupal 7.
    I'm looking for help with Drupal 11.

  • Pipeline finished with Canceled
    4 months ago
    Total: 99s
    #418029
  • Pipeline finished with Failed
    4 months ago
    Total: 204s
    #418031
  • @anybody How would we modify the form elements to allow relative dates?

        $form['date_range']['max_date'] = [
          '#type' => 'date',
          '#title' => 'Enter Max date',
          '#format' => 'm/d/Y',
          '#description' => t('i.e. "09/06/2016" or "+1 year"'),
          '#default_value' => $this->options['date_range']['max_date'],
          '#attributes' => [
            'min' => \Drupal::service('date.formatter')->format(\Drupal::time()->getRequestTime(), 'custom', 'Y-m-d'),
            ],
          ];
    
        $form['date_range']['min_date'] = [
          '#type' => 'date',
          '#title' => 'Enter Min date',
          '#format' => 'd/m/Y',
          '#description' => t('i.e. "09/06/2016" or "-1 year"'),
          '#default_value' => $this->options['date_range']['min_date'],
          '#attributes' => [
            'max' => \Drupal::service('date.formatter')->format(\Drupal::time()->getRequestTime(), 'custom', 'Y-m-d'),
            ],
          ];
    
  • Status changed to Needs review 17 days ago
  • First commit to issue fork.
  • Pipeline finished with Failed
    17 days ago
    Total: 149s
    #497356
  • Pipeline finished with Failed
    17 days ago
    Total: 163s
    #497363
  • Is it possible to use service injection and avoid the \Drupal calls in the class?

  • πŸ‡ΊπŸ‡¦Ukraine danmer

    @solideogloria sure, I want to fix all PHP Sniffer issues, I'll fix the \Drupal calls as well, thanks

  • Pipeline finished with Failed
    17 days ago
    Total: 156s
    #497366
  • Pipeline finished with Failed
    17 days ago
    Total: 286s
    #497401
  • Pipeline finished with Success
    17 days ago
    Total: 148s
    #497409
  • πŸ‡ΊπŸ‡¦Ukraine danmer

    Okay, the MR is finally fixed and passes all tests, please check

  • solideogloria β†’ changed the visibility of the branch 3096023-add-option-to to hidden.

  • Would it be possible to allow strings to be entered for min/max date, and then call strtotime() in the lines something like this?

    $max_date = new \DateTime(strtotime($this->options['date_range']['max_date']));
    

    That way, users could set the min/max to relative values like -2 years

Production build 0.71.5 2024