mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-17 15:17:52 -06:00
fix: keep .mdx pages through the sweep
A body is written as .md and the decoration pass, after the sweep, gives a page with components its .mdx name. The sweep did not count the .mdx of the run before as produced: 402 pages were deleted and written again on every run, so write_if_changed never kept their bytes.
This commit is contained in:
1 parent
8d69ad54df
commit
ecfe8157bb
2 files changed
+32
-3
No files matched your search
+17
-3
@@ -54,6 +54,21 @@ def write_decorated(path: str | Path, content: str) -> bool:
|
|||||||
_record(path)
|
_record(path)
|
||||||
return _write_artifact(str(path), content)
|
return _write_artifact(str(path), content)
|
||||||
|
|
||||||
|
# A page body is written as .md and the decoration pass, which runs after
|
||||||
|
# the sweep, gives it its final extension: .mdx when it holds components,
|
||||||
|
# the other file removed. The .mdx a previous run left is that same page.
|
||||||
|
_PAGE_SUFFIXES = (".md", ".mdx")
|
||||||
|
|
||||||
|
|
||||||
|
def _was_produced(path: Path) -> bool:
|
||||||
|
"""Whether this run produced *path*, a page under either extension."""
|
||||||
|
if os.path.realpath(str(path)) in _produced:
|
||||||
|
return True
|
||||||
|
return path.suffix in _PAGE_SUFFIXES and any(
|
||||||
|
os.path.realpath(str(path.with_suffix(suffix))) in _produced
|
||||||
|
for suffix in _PAGE_SUFFIXES if suffix != path.suffix)
|
||||||
|
|
||||||
|
|
||||||
def _sweep_generated(docs: Path, directories: list[str]) -> int:
|
def _sweep_generated(docs: Path, directories: list[str]) -> int:
|
||||||
"""Delete files in the generated tree that this run did not produce."""
|
"""Delete files in the generated tree that this run did not produce."""
|
||||||
removed = 0
|
removed = 0
|
||||||
@@ -62,7 +77,7 @@ def _sweep_generated(docs: Path, directories: list[str]) -> int:
|
|||||||
if not root.is_dir():
|
if not root.is_dir():
|
||||||
continue
|
continue
|
||||||
for path in sorted(root.rglob("*")):
|
for path in sorted(root.rglob("*")):
|
||||||
if path.is_file() and os.path.realpath(str(path)) not in _produced:
|
if path.is_file() and not _was_produced(path):
|
||||||
path.unlink()
|
path.unlink()
|
||||||
removed += 1
|
removed += 1
|
||||||
for path in sorted(root.rglob("*"), reverse=True):
|
for path in sorted(root.rglob("*"), reverse=True):
|
||||||
@@ -81,8 +96,7 @@ def _sweep_top_pages(docs: Path) -> int:
|
|||||||
"""
|
"""
|
||||||
removed = 0
|
removed = 0
|
||||||
for path in sorted(docs.glob("*.md*")):
|
for path in sorted(docs.glob("*.md*")):
|
||||||
if (path.is_file() and path.suffix in (".md", ".mdx")
|
if path.is_file() and path.suffix in _PAGE_SUFFIXES and not _was_produced(path):
|
||||||
and os.path.realpath(str(path)) not in _produced):
|
|
||||||
path.unlink()
|
path.unlink()
|
||||||
removed += 1
|
removed += 1
|
||||||
return removed
|
return removed
|
||||||
@@ -120,6 +120,21 @@ class Sweep(unittest.TestCase):
|
|||||||
self.assertTrue((self.docs / "emulators/kept.md").exists())
|
self.assertTrue((self.docs / "emulators/kept.md").exists())
|
||||||
self.assertTrue((self.docs / "emulators/nested/deep.md").exists())
|
self.assertTrue((self.docs / "emulators/nested/deep.md").exists())
|
||||||
|
|
||||||
|
def test_a_page_the_decoration_pass_made_mdx_is_kept(self):
|
||||||
|
"""A body is written as .md, and the decoration pass, after the
|
||||||
|
sweep, renames a page with components to .mdx. The .mdx of the run
|
||||||
|
before was swept and written again on every run: 402 pages."""
|
||||||
|
(self.docs / "platforms/kept.mdx").write_text("x")
|
||||||
|
(self.docs / "platforms/gone.mdx").write_text("x")
|
||||||
|
self._produce("platforms/kept.md")
|
||||||
|
sitewrite._sweep_generated(self.docs, ["platforms"])
|
||||||
|
(self.docs / "top.mdx").write_text("x")
|
||||||
|
sitewrite._record(self.docs / "top.md")
|
||||||
|
self.assertEqual(sitewrite._sweep_top_pages(self.docs), 0)
|
||||||
|
self.assertTrue((self.docs / "platforms/kept.mdx").exists())
|
||||||
|
self.assertTrue((self.docs / "top.mdx").exists())
|
||||||
|
self.assertFalse((self.docs / "platforms/gone.mdx").exists())
|
||||||
|
|
||||||
def test_a_directory_outside_the_list_is_never_touched(self):
|
def test_a_directory_outside_the_list_is_never_touched(self):
|
||||||
self._produce("emulators/kept.md", "emulators/nested/deep.md",
|
self._produce("emulators/kept.md", "emulators/nested/deep.md",
|
||||||
"emulators/stale.md")
|
"emulators/stale.md")
|
||||||
|
|||||||
Reference in new issue
Block a user