commit 0407d02129ceb7701ec547e1360a18790eea645f Author: fengbohan <1953356163@qq.com> Date: Fri Jan 12 13:46:57 2024 +0800 init diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..0417935 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,19 @@ +{ + // 使用 IntelliSense 了解相关属性。 + // 悬停以查看现有属性的描述。 + // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python: 当前文件", + "type": "python", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal", + "justMyCode": true, + "args": [ + "${workspaceFolder}/test.md" + ] + } + ] +} \ No newline at end of file diff --git a/remove.py b/remove.py new file mode 100644 index 0000000..4c76125 --- /dev/null +++ b/remove.py @@ -0,0 +1,45 @@ +# auto remove unuse img +from pathlib import Path +import argparse +import chardet + + +if __name__ == "__main__": + # get opt + parser = argparse.ArgumentParser() + parser.add_argument("file", help="specifi the markdown file", type=str) + parser.add_argument("-a", "--assets", help="specifi the img dir", type=str) + args = parser.parse_args() + + if args.assets: + img_dir = Path(args.assets) + else: + img_dir = Path(args.file).with_suffix('.assets') + + with open(args.file, 'rb') as file: + result = chardet.detect(file.read()) + print("{} encoding is {}, confidence: {}".format(args.file, result['encoding'], result['confidence'])) + with open(args.file, 'r', encoding=result['encoding']) as file: + content = file.read() + + img_list = list(img_dir.glob('**/*')) + unuse_img_list = [] + for file_name in img_list: + img_name = Path(file_name).name + if img_name not in content: + print("img:{}".format(img_name)) + unuse_img_list.append(file_name) + + if len(unuse_img_list) == 0: + print("not find unuse img file") + else: + print("find {} unuse img files:".format(len(unuse_img_list))) + for file_name in unuse_img_list: + print("{}".format(file_name)) + usr_input = input("would you want to delete them?(y or n):") + if usr_input == "y": + for file_name in unuse_img_list: + print("delete {}".format(file_name)) + Path(file_name).unlink() + else: + print("unused img will not remove!") diff --git a/test.assets/img.png b/test.assets/img.png new file mode 100644 index 0000000..0ca9181 Binary files /dev/null and b/test.assets/img.png differ diff --git a/test.assets/写周报了.png b/test.assets/写周报了.png new file mode 100644 index 0000000..808ff31 Binary files /dev/null and b/test.assets/写周报了.png differ diff --git a/test.assets/萌萌的伊雷娜.jpg b/test.assets/萌萌的伊雷娜.jpg new file mode 100644 index 0000000..9e2bd87 Binary files /dev/null and b/test.assets/萌萌的伊雷娜.jpg differ diff --git a/test.md b/test.md new file mode 100644 index 0000000..944c90e --- /dev/null +++ b/test.md @@ -0,0 +1,3 @@ +![萌萌的伊雷娜](./test.assets/萌萌的伊雷娜.jpg) + +![写周报了](./test.assets/写周报了.png)