Skip to content

Commit e3b6882

Browse files
Drop UUID suffix, cache based on timestamps
1 parent f8b8647 commit e3b6882

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

jupyterlite_sphinx/jupyterlite_sphinx.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,14 @@ class _LiteDirective(SphinxDirective):
313313
"new_tab": directives.unchanged,
314314
}
315315

316+
def _should_convert_notebook(self, source_path: Path, target_path: Path) -> bool:
317+
"""Check if a Markdown notebook needs conversion to IPyNB format based on
318+
some rudimentary timestamp-based caching."""
319+
if not target_path.exists():
320+
return True
321+
322+
return source_path.stat().st_mtime > target_path.stat().st_mtime
323+
316324
def run(self):
317325
width = self.options.pop("width", "100%")
318326
height = self.options.pop("height", "1000px")
@@ -344,12 +352,13 @@ def run(self):
344352
# For MyST Markdown notebooks, we create a unique target filename to avoid
345353
# collisions with other IPyNB files that may have the same name.
346354
if notebook_path.suffix.lower() == ".md":
347-
target_name = f"{notebook_path.stem}_{uuid4().hex[:8]}.ipynb"
355+
target_name = f"{notebook_path.stem}.ipynb"
348356
target_path = notebooks_dir / target_name
349357

350-
nb = jupytext.read(str(notebook_path))
351-
with open(target_path, "w", encoding="utf-8") as f:
352-
nbformat.write(nb, f, version=4)
358+
if self._should_convert_notebook(notebook_path, target_path):
359+
nb = jupytext.read(str(notebook_path))
360+
with open(target_path, "w", encoding="utf-8") as f:
361+
nbformat.write(nb, f, version=4)
353362

354363
notebook = str(target_path)
355364
notebook_name = target_name

0 commit comments

Comments
 (0)