Skip to content

Commit

Permalink
Add Features: Support yaml format in header part.
Browse files Browse the repository at this point in the history
  • Loading branch information
zweix123 committed Jan 4, 2024
1 parent de52bf9 commit edae87a
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 74 deletions.
17 changes: 14 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
{
"python.formatting.provider": "black",
"python.linting.flake8Enabled": false,
"python.linting.mypyEnabled": true,
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
},
},
"mypy-type-checker.args": [
"--check-untyped-defs",
],
"isort.args": [
"--profile",
"black",
],
}
62 changes: 32 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@

[Background](#background) | [Install](#install) | [Usage](#usage) | [Grammer](#grammer) | [Example](#example) | [Develop](#develop) | [Acknowledgement](#acknowledgement) | [License](#license)

- [jyyslide-md](#jyyslide-md)
- [Background](#background)
- [Install](#install)
- [Usage](#usage)
- [Grammer](#grammer)
- [Example](#example)
- [Develop](#develop)
- [Acknowledgement](#acknowledgement)
- [License](#license)

## Background
>可以从奥卡姆剃刀(如无必要,勿增实体)的角度考虑我开发本项目的发心。
Expand All @@ -38,8 +28,7 @@
```
2. 利用Poetry下载第三方模块
```bash
python3 -m poetry install
# 或者 poetry install
poetry install
```

>如果在win机器且出现乱码, 可以尝试下面的方案
Expand All @@ -51,11 +40,10 @@
+ 使用Peotry管理的Python有两种运行方式
1. 进入虚拟环境:
```bash
python3 -m poetry shell
# 或者 poetry shell
poetry shell
```
之后就可以正常的运行Python代码了
2. 使用前缀:在运行Python代码的命令前添加`python3 -m poetry run`(或者`poetry run`
2. 使用前缀:在运行Python代码的命令前添加`poetry run`

比如[样例1](#example)中的命令应该是`poetry run python main.py example\jyy\操作系统概述.md`

Expand All @@ -65,8 +53,7 @@ python main.py [Markdown文件]
```
在Markdown文件同级目录会出现一个`dist`文件夹,其下有一个index.html文件和一个static文件夹,前者即为生成的“Web幻灯片,static即为其相关静态文件。网页的title和Markdown文件同名、icon即为`static/img/favicon.png`,可通过替换这个文件修改icon。

+ PDF Export: Reveal.js [Manual](https://revealjs.com/pdf-export/)
> 也有第三方的工具,比如[decktape](https://github.com/astefanutti/decktape)
+ PDF Export: [Manual](https://revealjs.com/pdf-export/)

### Grammer

Expand Down Expand Up @@ -99,7 +86,7 @@ python main.py [Markdown文件]

>在[例子](#example)中的jyy中的Markdown文件

```
```json
{
"author": {
"name": "蒋炎岩",
Expand All @@ -109,22 +96,43 @@ python main.py [Markdown文件]
{
"name": " 南京大学 ",
"url": "https://www.nju.edu.cn/main.htm",
"img_url": "./img/nju-logo.jpg"
"img": "./img/nju-logo.jpg"
},
{
"name": "计算机科学与技术系",
"url": "https://cs.nju.edu.cn/main.htm",
"img_url": "./img/njucs-logo.jpg"
"img": "./img/njucs-logo.jpg"
},
{
"name": "计算机软件研究所",
"url": "https://www.nju.edu.cn/main.htm",
"img_url": "./img/ics-logo.png"
"img": "./img/ics-logo.png"
}
]
}
```

现也支持YAML格式(建议)

```yaml
author:
name: 蒋炎岩
url: https://ics.nju.edu.cn/~jyy/
departments:
- name: " 南京大学 "
url: https://www.nju.edu.cn/main.htm,
img: ./img/nju-logo.jpg
- name: 计算机科学与技术系
url: https://cs.nju.edu.cn/main.htm,
img: ./img/njucs-logo.jpg
- name: 计算机软件研究所
url: https://www.nju.edu.cn/main.htm,
img: ./img/ics-logo.png
```

---

+ 对Markdown原生语法适配情况:
Expand Down Expand Up @@ -180,23 +188,17 @@ python main.py [Markdown文件]
## Example

+ `example/jyy/操作系统概述.md`即为蒋老师2022年的第一节课
```powershell
python main.py example\jyy\操作系统概述.md # win
```

```bash
python main.py example/jyy/操作系统概述.md # linux
python main.py example/jyy/操作系统概述.md
```

打开`example\jyy\dist\index.html`即可查看

+ `example/Intro/slide.md`即为本项目介绍的幻灯片
```powershell
python main.py example\Intro\slide.md # win
```


```bash
python main.py example/Intro/slide.md # linux
python main.py example/Intro/slide.md
```

打开`example\Intro\dist\index.html`即可查看
Expand Down
39 changes: 16 additions & 23 deletions example/jyy/操作系统概述.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
{
"author": {
"name": "蒋炎岩",
"url": "https://ics.nju.edu.cn/~jyy/"
},
"departments": [
{
"name": " 南京大学 ",
"url": "https://www.nju.edu.cn/main.htm",
"img_url": "./img/nju-logo.jpg"
},
{
"name": "计算机科学与技术系",
"url": "https://cs.nju.edu.cn/main.htm",
"img_url": "./img/njucs-logo.jpg"
},
{
"name": "计算机软件研究所",
"url": "https://www.nju.edu.cn/main.htm",
"img_url": "./img/ics-logo.png"
}
]
}
author:
name: 蒋炎岩
url: https://ics.nju.edu.cn/~jyy/

departments:
- name: " 南京大学 "
url: https://www.nju.edu.cn/main.htm,
img: ./img/nju-logo.jpg

- name: 计算机科学与技术系
url: https://cs.nju.edu.cn/main.htm,
img: ./img/njucs-logo.jpg

- name: 计算机软件研究所
url: https://www.nju.edu.cn/main.htm,
img: ./img/ics-logo.png
+++++

# 操作系统概述
Expand Down
72 changes: 71 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ jinja2 = "^3.1.2"
markdown = "^3.4.1"
pyquery = "^2.0.0"
pygments = "^2.14.0"
lxml = "^4.9.4"
pyyaml = "^6.0.1"
types-markdown = "^3.4.2.6"
types-requests = "^2.28.11.17"
lxml = "^4.9.4"
types-pyyaml = "^6.0.12.12"


[tool.poetry.group.dev.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion src/backup/template/authortemp.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<p class=" font-serif my-1">
{{ department.name }}
</p>
<img class="inline-img h-24" src="{{ department.img_url }}" style="display: inline-block;">
<img class="inline-img h-24" src="{{ department.img }}" style="display: inline-block;">
</a>
</div>
{% endfor %}
Expand Down
31 changes: 18 additions & 13 deletions src/converter.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import os, json, shutil
import json
import os
import shutil

from pyquery import PyQuery as pq
import yaml
from jinja2 import Template
from pyquery import PyQuery # type: ignore

from . import settings as st
from src.util import *

from . import settings as st


def process_html_elements(before_html):
temp_html = "<html><body>{}</body></html>".format(before_html)
page = pq(temp_html)
page = PyQuery(temp_html)
e = page
for item in e("h1").parent():
t = pq(item)
t = PyQuery(item)
t.wrap("<div style='width:100%'>")
t.wrap("<div class='center middle'>")
class_data = {
Expand All @@ -26,11 +30,11 @@ def process_html_elements(before_html):
}
for k, v in class_data.items():
for item in e(k):
t = pq(item)
t = PyQuery(item)
t.add_class(v)
page = e
items = page("body").children()
return "".join([str(pq(e)) for e in items])
return "".join([str(PyQuery(e)) for e in items])


def process_terminal(semi_html):
Expand Down Expand Up @@ -152,21 +156,22 @@ def process_front_matter():
front_matter = parts[0]
st.content = "".join(parts[1:])

data = json.loads(front_matter)
try:
data = json.loads(front_matter)
except Exception as e:
data = yaml.load(front_matter, Loader=yaml.SafeLoader)

for department in data["departments"]:
new_name, err = file_util.get_image_to_target(
department["img_url"], st.filepath, st.images_foldpath
department["img"], st.filepath, st.images_foldpath
)
if err is False:
department["img_url"] = os.path.join(
department["img"] = os.path.join(
".", "static", st.images_foldname, new_name
)
department["name"] = department["name"].replace(" ", "&#12288;")

st.author_template = st.author_template.render(
author=data["author"], departments=data["departments"]
)
st.author_template = st.author_template.render(author=data["author"], departments=data["departments"]) # type: ignore


def process_static():
Expand Down
Loading

0 comments on commit edae87a

Please sign in to comment.