Kirby as calendar / Problem with duplicate URL

I use kirby as a calendar. There is a page called “calendar” with subpages. Each subpage is a single date. Unfortunately, some dates have similar titles. So everytime an admin creates a new subpage with a title that already exists, he gets an error, because the URL generated based on the “title” field already exists.

Is it possible to generate an URL, e.g. based on “date” and “title” and not only on “title”?

Example before:
Date: 2015-10-19
Title: Test
Generated URL: /test

Example after:
Date: 2015-10-19
Title: Test
Generated URL: /2015-10-19-test

I’d recommend creating a hierarchical structure like this:

calendar
  2015-10-19
    test
    another-test
  2015-10-20
    test
    wont-ever-collide-with-the-other-day

Thank you for this recommendation. With this solution, the admin has to create at least two pages for one date - which is not really a user-friendly workflow.

Is there another way? For example with the new hook “panel.page.create”?

Something like this:
“If new page is a date, create URL from date and title.”

On panel.page.create you don’t have a date yet, so this won’t work. You could use panel.page.update instead and change the UID of the page. However, if you change the UID of a page while in the panel, you will get an error message that the page you are currently editing does not exist. So for the user that would mean to go find the page again, not very user friendly, at least as long as a hook cannot redirect you to the new page (not sure if this is possible). You can test this:

<?php
kirby()->hook('panel.page.update', 'run');

function run( $page ) {
	$title = $page->title();
	$date = $page->date('Y-m-d');
	$newUID = $date . "-" . $title;

	$page->move($newUID);
	
}

On top of that, a UID starting with a number is treated as a visible page, so the first part of the date is ignored and you end up with an URL that only shows the month and the day.

You could build a custom UI in the frontend that becomes visible if the admin is logged in. Kirby provides an API to create and edit pages, even outside of the Panel.