diff --git a/openstackdocstheme/page_context.py b/openstackdocstheme/page_context.py index 4e37ecca..7c7d8ab1 100644 --- a/openstackdocstheme/page_context.py +++ b/openstackdocstheme/page_context.py @@ -16,11 +16,11 @@ import os.path import subprocess import time +import sphinx from sphinx.util import logging from . import version - LOG = logging.getLogger(__name__) _timeint = int(os.environ.get('SOURCE_DATE_EPOCH', time.time())) @@ -80,7 +80,12 @@ def _get_last_updated(app, pagename): # Strip the prefix from the filename so the git command recognizes # the file as part of the current repository. - src_file = full_src_file[len(str(app.builder.env.srcdir)) :].lstrip('/') + if sphinx.version_info >= (7, 0): + src_file = str(full_src_file.relative_to(app.builder.env.srcdir)) + else: # Sphinx < 7.0 + src_file = full_src_file[len(str(app.builder.env.srcdir)) :].lstrip( + '/' + ) candidates.append(src_file) if not os.path.exists(src_file):