Kirby Content Last Modified

I am creating posts for my plugins to make it easier to find them using the forum search and not just the docs search.

This plugin will track the most recent timestamp whenever you use the Panel or Kirby PHP API to update content. Like changing a page title, renaming a file, creating a new page, removing a file,…

That single timestamp might be useful if you need to know when the last modification on your content happened. For example when clearing caches or similar actions.

Output the last modified timestamp

<?= site()->contentLastModified()->toDate('c') ?>

Flush a cache if the content was modified after a given timestamp

// http://example.com/some-page?last-modified=1726822135 
if (site()->contentLastModified()->toInt() > intval(get('last-modified'))) { 
    kirby()->cache('my-cache')->flush(); 
}

NOTE: yes… site()->modified() will give you the same value but it will crawl ALL content files, which might not be the most performant thing to do depending on how much content you have.

1 Like

I’ve been trying to use this plugin on one of my K4 sites (Kirby 4.5.0) and it’s throwing this error:

Bnomei\ContentLastModified::timestamp():
   Return value must be of type int, null returned

I’m trying to output the date using your example:

<?= site()->contentLastModified()->toDate('c') ?>

Am I missing anything obvious here?

Thanks!

can you check if the cache file exists and if what is it’s content? its content/.content-last-modified.

The cache file does not exist at content/.content-last-modified

However, there is a cache file being created here:

/site/cache/newtonglossary-dev_8890/updates/plugins/bnomei/content-last-modified.cache

Where newtonglossary-dev_8890 is my local MAMP environment.

The contents of the cache file are:

{"created":1736203476,"minutes":4320,"value":"Could not load update data for plugin bnomei\/content-last-modified: HTTP error 500"}

thats related to the panel system view for my plugin.

if there is no cache file from my plugin maybe you did not edit a single page/file via the panel?

Ah, that’s it … I don’t use the panel for content creation or editing.

It’s all hand-build text files.

then using site()->modified() is the only way to do this right now.

but i will release a plugin called „turbo“ that can do that more performantly around the same time that k5 will launch.

1 Like

My site has just over 1,800 pages, and I was wary of using site()->modified() because of the potential performance hit.

However, I may as well give it a try … as a test on my development server, anyway.

Ooh … this sounds promising!

Thanks for the information, Bruno.