I am working on a school-related project and learning Hugo. I have multiple student data files in the content folder, specifically in a “students” folder where I store data for Student 1 through Student 5.
I’ve added two new attributes to each student’s data: createdAt and updatedAt. I want to automatically delete the Markdown file of a student if their data hasn’t been updated for more than a month. Essentially, if a student’s data file doesn’t have any updates within that time, the file should be deleted automatically.
However, I’m not sure how to automate the deletion of the Markdown file based on this condition.
Depending on your operating system … on macOS and other Unix derivates, this could be a job for cron.
Hugo does not delete your MD files, nor should it, IMO.
I think using cron will help when running a GitHub workflow to delete older data, but I want something similar that runs every time I preview the project locally.
cron is not related to Github. You can just write a shell script that does a find … -exec rm {} \; || hugo server
The issue is still not related to Hugo in any way, so other places might be more appropriate to find answers.
There is an expiryDate metadata for the md file header. This doesn’t remove the file, but presumably hugo stops rendering it after that date (haven’t tested, but will soon). If you really want the file removed, your script should look for that field to identify files to be removed.
But, as others have said, you probably don’t want to actually remove the file (unless archived in git). If it’s top secret military stuff, removal isn’t good enough anyway - it takes thermite to the disk drive.