I have a note Recently updated which is a changelog showing the 25 most recently edited notes in this digital garden. It’s automated via a Python script that is run as part of the build process.
The script is called ,garden_recent and looks like this (see Pesky little scripts for naming convention.)
#!/usr/bin/env -S uv run --quiet --script
"""Check which files in digital garden have been most recently updated and write them to a particular file"""
import os
from os.path import getmtime, join
from datetime import datetime
from typing import List, Tuple
from pathlib import Path
GARDEN_DIR = "/path/to/my/garden"
EXCLUDE = ["Folders", "To", "Skip"]
TARGET = "About/Recently updated.md"
FRONTMATTER = f"""---
tags:
- meta
date created: 2024-12-31
date modified: {datetime.today().strftime('%Y-%m-%d')}
note: "This note is automatically generated when the vault is built into a website. Manual changes don't persist."
---
"""
INTRODUCTION = """Here's a changelog for most recent changes.\n\n"""
def is_excluded(filepath: str) -> bool:
"""Assesses whether a filepath should be included
in the list of recently updated files.
It skips any folder defined in EXCLUDE and
the Recently updated note itself."""
if "/About/Recently updated.md" in filepath:
return True
for _exclude in EXCLUDE:
if f"/{_exclude}/" in filepath:
return True
def find_files(root: str) -> List[Tuple[str, datetime]]:
"""Returns a list of each file tthat should be
included, and a timestamp for when it was
last modified."""
return [
(
os.path.join(dirpath, f),
datetime.fromtimestamp(getmtime(os.path.join(dirpath, f))),
)
for (dirpath, dirnames, filenames) in os.walk(root)
for f in filenames
if not is_excluded(os.path.join(dirpath, f))
]
def craft_note(files: List[Tuple[str, datetime]]) -> str:
"""Create a note body that's a table with
the 25 most recently edited notes as wiki
links to those notes."""
note = "|Note|Modified at|\n|----|-----|\n"
for filepath, timestamp in sorted(files, key=lambda x: x[1], reverse=True)[:25]:
basename = f"[[{Path(filepath).stem}]]"
note += f"|{basename}|{timestamp.strftime('%Y-%m-%d')}|\n"
return note
if __name__ == "__main__":
files = find_files(GARDEN_DIR)
note = craft_note(files)
with open(join(GARDEN_DIR, TARGET), "w") as note_file:
note_file.write(FRONTMATTER)
note_file.write(INTRODUCTION)
note_file.write(note)The script finds all files and filters out the Recently updated note itself and any folder defined in EXCLUDE list. Then it sorts them by most recently edited, takes 25 of them and turns them into a markdown table. It then combines frontmatter, a short introductory paragraph and the table of notes into the file.