From e1992bb3106c80c418e96bf9dc88ea5ce4740452 Mon Sep 17 00:00:00 2001
From: Routhleck <1310722434@qq.com>
Date: Mon, 28 Aug 2023 20:25:12 +0800
Subject: [PATCH] Update deploy workflow
---
.github/workflows/jekyll_deploy.yml | 13 ++++++++
markdown_process.py | 46 ++++++++++++++++++++++++-----
2 files changed, 51 insertions(+), 8 deletions(-)
diff --git a/.github/workflows/jekyll_deploy.yml b/.github/workflows/jekyll_deploy.yml
index 1bfbd5e..379bd19 100644
--- a/.github/workflows/jekyll_deploy.yml
+++ b/.github/workflows/jekyll_deploy.yml
@@ -28,6 +28,19 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v2
+ - name: Checkout Notes.md and Notes.assets from master
+ uses: actions/checkout@v2
+ with:
+ repository: routhleck/BrainPy-course-notes
+ ref: master
+ path: master_content
+
+ - name: Process Notes.md using markdown_process.py
+ run: python3 markdown_process.py -i master_content/Notes.md -o _posts/2023-08-27-BrainPy-course-notes.md
+
+ - name: Move Notes.assets to assets/images/
+ run: mv -f master_content/Notes.assets assets/images/
+
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
diff --git a/markdown_process.py b/markdown_process.py
index 50b9206..ecb0c3b 100644
--- a/markdown_process.py
+++ b/markdown_process.py
@@ -1,6 +1,27 @@
+import argparse
import re
import os
+def prepend_markdown_header(content):
+ header = """
+---
+title: BrainPy course notes
+tags:
+---
+
+
+
+
+"""
+ return header + content
+
def replace_img_url_1(content):
# 对于 ![image name](Notes.assets/image-000.png) 格式的替换
@@ -43,20 +64,29 @@ def add_newlines_around_formula(content):
return content
-if __name__ == "__main__":
+def main(input_path, out_path):
# 打印当前工作目录
- # print(os.getcwd())
+ print(os.getcwd())
input_path = "_posts/2023-08-27-BrainPy-course-notes.md"
out_path = "_posts/2023-08-27-BrainPy-course-notes_replace.md"
with open(input_path, "r", encoding="utf-8") as file:
md_content = file.read()
- md_content = replace_img_url_1(content)
- md_content = replace_img_url_2(content)
- md_content = add_newlines_around_formula(content)
+ md_content = prepend_markdown_header(md_content)
+ md_content = replace_img_url_1(md_content)
+ md_content = replace_img_url_2(md_content)
+ md_content = add_newlines_around_formula(md_content)
# 将修改后的内容写入新文件
- with open(out_path, "w", encoding="utf-8") as file:
- file.write(md_content)
-
+ with open(out_path, "w", encoding="utf-8") as file:
+ file.write(md_content)
+
+
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser(description='Process markdown file.')
+ parser.add_argument('-i', '--input', type=str, required=True, help='Path to the input markdown file.')
+ parser.add_argument('-o', '--output', type=str, required=True, help='Path to the output markdown file.')
+
+ args = parser.parse_args()
+ main(args.input, args.output)