From 1233d4b7bde63e061519b807a044307beef2e498 Mon Sep 17 00:00:00 2001 From: Will Dean Date: Fri, 21 Nov 2025 12:28:03 -0500 Subject: [PATCH 1/6] Add page_dates.html template for displaying creation and update dates --- doc/.templates/page_dates.html | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 doc/.templates/page_dates.html diff --git a/doc/.templates/page_dates.html b/doc/.templates/page_dates.html new file mode 100644 index 0000000000..367f45f43a --- /dev/null +++ b/doc/.templates/page_dates.html @@ -0,0 +1,9 @@ +{% if date_created or last_updated %} +
+

+ {% if date_created %}Created: {{ date_created }}{% endif %} + {% if date_created and last_updated %} | {% endif %} + {% if last_updated %}Last updated: {{ last_updated }}{% endif %} +

+
+{% endif %} From 7fcd423bb0b0ac7ec917864d07d604360f9734e8 Mon Sep 17 00:00:00 2001 From: Will Dean Date: Fri, 21 Nov 2025 12:30:38 -0500 Subject: [PATCH 2/6] Add subprocess and datetime imports for git date queries --- doc/conf.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/conf.py b/doc/conf.py index e10dcffb90..c1a58b8fcb 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -1,6 +1,8 @@ import os import inspect import sys +import subprocess +from datetime import datetime import pytensor from pathlib import Path From e1f0c5e63387da58b496bd97672b9fca2082a66c Mon Sep 17 00:00:00 2001 From: Will Dean Date: Fri, 21 Nov 2025 12:31:08 -0500 Subject: [PATCH 3/6] Add page_dates.html to article footer items --- doc/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/conf.py b/doc/conf.py index c1a58b8fcb..b0dedc0b59 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -154,7 +154,7 @@ "secondary_sidebar_items": ["page-toc", "edit-this-page", "sourcelink", "donate"], "navbar_start": ["navbar-logo"], "article_header_end": ["nb-badges"], - "article_footer_items": ["rendered_citation.html"], + "article_footer_items": ["page_dates.html", "rendered_citation.html"], } html_context = { "github_url": "https://github.com", From 08c85f34f7e1b7048dee29a09fd17af2f82146dc Mon Sep 17 00:00:00 2001 From: Will Dean Date: Fri, 21 Nov 2025 12:32:08 -0500 Subject: [PATCH 4/6] Add get_git_dates function to query creation and update dates from git --- doc/conf.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/doc/conf.py b/doc/conf.py index b0dedc0b59..74c492cda9 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -198,6 +198,49 @@ # using the given strftime format. html_last_updated_fmt = "%b %d, %Y" + +# Function to get git dates for a file +def get_git_dates(source_file): + """Get the creation and last modification dates from git history.""" + dates = {} + try: + # Get last modified date + result = subprocess.run( + ["git", "log", "-1", "--format=%ai", "--", source_file], + cwd=Path(__file__).parent, + capture_output=True, + text=True, + check=True, + ) + if result.stdout.strip(): + git_date = datetime.strptime(result.stdout.strip()[:19], "%Y-%m-%d %H:%M:%S") + dates["last_updated"] = git_date.strftime(html_last_updated_fmt) + + # Get creation date (first commit) + result = subprocess.run( + ["git", "log", "--diff-filter=A", "--format=%ai", "--", source_file], + cwd=Path(__file__).parent, + capture_output=True, + text=True, + check=True, + ) + if result.stdout.strip(): + # Get the last line (first commit) + first_commit = result.stdout.strip().split('\n')[-1] + git_date = datetime.strptime(first_commit[:19], "%Y-%m-%d %H:%M:%S") + dates["date_created"] = git_date.strftime(html_last_updated_fmt) + except (subprocess.CalledProcessError, ValueError): + pass + + # Fallback to build date if git fails + build_date = datetime.now().strftime(html_last_updated_fmt) + if "last_updated" not in dates: + dates["last_updated"] = build_date + if "date_created" not in dates: + dates["date_created"] = build_date + + return dates + # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. html_use_smartypants = True From b7a2094560596f02fd57f1f89efdadf2b123628e Mon Sep 17 00:00:00 2001 From: Will Dean Date: Fri, 21 Nov 2025 12:32:48 -0500 Subject: [PATCH 5/6] Add Sphinx hook to inject git dates into page context --- doc/conf.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/doc/conf.py b/doc/conf.py index 74c492cda9..9e33f580d0 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -241,6 +241,21 @@ def get_git_dates(source_file): return dates + +# Hook to set dates per page based on git history +def html_page_context(app, pagename, templatename, context, doctree): + """Add git-based creation and last modified dates to each page context.""" + if doctree is not None: + source_file = app.env.doc2path(pagename) + dates = get_git_dates(source_file) + context["last_updated"] = dates["last_updated"] + context["date_created"] = dates["date_created"] + + +def setup(app): + """Setup the Sphinx application.""" + app.connect("html-page-context", html_page_context) + # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. html_use_smartypants = True From e34e22c8fd2a08be2c70b93c5b7265ca18b92439 Mon Sep 17 00:00:00 2001 From: Will Dean Date: Fri, 21 Nov 2025 12:38:10 -0500 Subject: [PATCH 6/6] fix lint of conf.py --- doc/conf.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/conf.py b/doc/conf.py index 9e33f580d0..a9863b4d03 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -215,7 +215,7 @@ def get_git_dates(source_file): if result.stdout.strip(): git_date = datetime.strptime(result.stdout.strip()[:19], "%Y-%m-%d %H:%M:%S") dates["last_updated"] = git_date.strftime(html_last_updated_fmt) - + # Get creation date (first commit) result = subprocess.run( ["git", "log", "--diff-filter=A", "--format=%ai", "--", source_file], @@ -231,14 +231,14 @@ def get_git_dates(source_file): dates["date_created"] = git_date.strftime(html_last_updated_fmt) except (subprocess.CalledProcessError, ValueError): pass - + # Fallback to build date if git fails build_date = datetime.now().strftime(html_last_updated_fmt) if "last_updated" not in dates: dates["last_updated"] = build_date if "date_created" not in dates: dates["date_created"] = build_date - + return dates