Skip to content

Commit

Permalink
Update deploy workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Routhleck committed Aug 28, 2023
1 parent 1836fd2 commit e1992bb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 8 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/jekyll_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
46 changes: 38 additions & 8 deletions markdown_process.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
import argparse
import re
import os

def prepend_markdown_header(content):
header = """
---
title: BrainPy course notes
tags:
---
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<script>
MathJax = {
tex: {
inlineMath: [['$', '$']],
processEscapes: true
}
};
</script>
"""
return header + content


def replace_img_url_1(content):
# 对于 ![image name](Notes.assets/image-000.png) 格式的替换
Expand Down Expand Up @@ -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)

0 comments on commit e1992bb

Please sign in to comment.