From 2af1ecab50a791dd39cfe2aba809c687dca9f46a Mon Sep 17 00:00:00 2001 From: lucemia Date: Wed, 10 Apr 2024 10:48:29 +0800 Subject: [PATCH] fix #345 compile readme with script --- README.md | 4 +- .../media/README_files}/README_1_0.png | Bin .../media/README_files}/README_1_0.svg | 0 .../media/README_files}/README_3_0.png | Bin .../media/README_files}/README_3_0.svg | 0 scripts/compile-readme.py | 41 ++++++++++++++++++ scripts/compile-readme.sh | 1 - 7 files changed, 43 insertions(+), 3 deletions(-) rename {README_files => docs/media/README_files}/README_1_0.png (100%) rename {README_files => docs/media/README_files}/README_1_0.svg (100%) rename {README_files => docs/media/README_files}/README_3_0.png (100%) rename {README_files => docs/media/README_files}/README_3_0.svg (100%) create mode 100644 scripts/compile-readme.py delete mode 100755 scripts/compile-readme.sh diff --git a/README.md b/README.md index 8720f276..e74dc7e4 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ f -![svg](README_files/README_1_0.svg) +![svg](docs/media/README_files/README_1_0.svg) @@ -125,7 +125,7 @@ f -![svg](README_files/README_3_0.svg) +![svg](docs/media/README_files/README_3_0.svg) diff --git a/README_files/README_1_0.png b/docs/media/README_files/README_1_0.png similarity index 100% rename from README_files/README_1_0.png rename to docs/media/README_files/README_1_0.png diff --git a/README_files/README_1_0.svg b/docs/media/README_files/README_1_0.svg similarity index 100% rename from README_files/README_1_0.svg rename to docs/media/README_files/README_1_0.svg diff --git a/README_files/README_3_0.png b/docs/media/README_files/README_3_0.png similarity index 100% rename from README_files/README_3_0.png rename to docs/media/README_files/README_3_0.png diff --git a/README_files/README_3_0.svg b/docs/media/README_files/README_3_0.svg similarity index 100% rename from README_files/README_3_0.svg rename to docs/media/README_files/README_3_0.svg diff --git a/scripts/compile-readme.py b/scripts/compile-readme.py new file mode 100644 index 00000000..7bc244f0 --- /dev/null +++ b/scripts/compile-readme.py @@ -0,0 +1,41 @@ +import os +import shutil + +import typer + + +def post_process(markdown_file: str, original_folder: str, new_folder: str) -> None: + # Move the folder + if os.path.exists(original_folder): + for filepath in os.listdir(original_folder): + # Move the file, replace if it already exists + old_path = os.path.join(original_folder, filepath) + new_path = os.path.join(new_folder, filepath) + if os.path.exists(new_path): + os.remove(new_path) + + shutil.move(old_path, new_path) + print(f"Moved {filepath} to {new_folder}") + + # Update paths in the Markdown file + with open(markdown_file, "r") as file: + content = file.read() + + content = content.replace(original_folder, new_folder) + + with open(markdown_file, "w") as file: + file.write(content) + + print("Image paths updated and folder moved.") + + +def main() -> None: + os.remove("README.md") + os.system("jupyter nbconvert --to markdown README.ipynb") + assert os.path.exists("README.md") + + post_process("README.md", "README_files", "docs/media/README_files") + + +if __name__ == "__main__": + typer.run(main) diff --git a/scripts/compile-readme.sh b/scripts/compile-readme.sh deleted file mode 100755 index fa833962..00000000 --- a/scripts/compile-readme.sh +++ /dev/null @@ -1 +0,0 @@ -jupyter nbconvert --to markdown README.ipynb