Skip to content

Commit b12a1e1

Browse files
committed
【新增】生成全合一 HTML 文件并优化工作流
- 新增功能:生成全合一 HTML 文件,包含所有外部资源 - 优化 Github Actions 工作流,支持生成多种 HTML 文件 - 更新 README 和文档,增加全合一 HTML 文件说明 - 重构代码,支持生成压缩和全合一 HTML 文件
1 parent 514f0ae commit b12a1e1

9 files changed

Lines changed: 198 additions & 104 deletions

File tree

.github/workflows/release.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858

5959
- name: Generate minimized HTML
6060
if: steps.version-check.outputs.version != '0'
61-
run: cargo run --release -- index.html index.min.html
61+
run: cargo run --release -- index.html
6262
shell: bash
6363
working-directory: ${{ github.action_path }}
6464

@@ -68,6 +68,8 @@ jobs:
6868
mkdir -p ../release
6969
cp -v index.html ../release/
7070
cp -v index.min.html ../release/
71+
cp -v index.allinone.html ../release/
72+
cp -v index.allinone.min.html ../release/
7173
shell: bash
7274
working-directory: ${{ github.action_path }}
7375

@@ -77,7 +79,7 @@ jobs:
7779
with:
7880
generateReleaseNotes: true
7981
tag: "v${{ steps.version-check.outputs.version }}"
80-
artifacts: "../release/index.html,../release/index.min.html"
82+
artifacts: "../release/index.html,../release/index.min.html,../release/index.allinone.html,../release/index.allinone.min.html"
8183

8284
- name: Delete tag on failure
8385
if: failure() && steps.push-tag.outputs.tag_name != ''

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
/target
22
/Cargo.lock
3-
index.min.html
3+
4+
index.min.html
5+
index.allinone.html
6+
index.allinone.min.html

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
1. Fork 源码,下载到本地并运行项目;
2323
2. 添加或修改代码;
24-
3. 运行 `cargo run --release -- index.html index.min.html` 命令以生成压缩的最小文件
24+
3. 配置 rust 环境并运行 `cargo run --release -- index.html` 命令以生成压缩的最小文件和全合一文件
2525
4. 对相关改动进行全面的自我测试;
2626
5. 确认无误后提交修改到 Github;
2727
6. 提交 Pull Request。

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ edition = "2021"
77

88
[dependencies]
99
minify-html = "0.15.0"
10+
reqwest = { version = "0.12.20", features = ["blocking"] }
11+
scraper = "0.23.1"

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
## 特性
88

9-
- **依赖少**:仅需一个 HTML 文件、少量 CDN 和服务器程序,即可完成 Markdown 网页渲染。
9+
- **依赖少**:仅需一个 HTML 文件,即可完成 Markdown 网页渲染。
1010
- **代码高亮支持**:渲染 Markdown 中的代码块。
1111
- **Markdown 支持**:将 Markdown 文件渲染为 HTML。
1212
- **Mermaid 支持**:将 Markdown 中的 Mermaid 语法渲染为图表。
@@ -16,13 +16,22 @@
1616

1717
## 使用方法
1818

19+
| 文件名 | 说明 |
20+
| :----- | :--- |
21+
| index.html | 默认 HTML 入口文件,使用 CDN 引入依赖。 |
22+
| index.min.html | 压缩后的 HTML 入口文件,使用 CDN 引入依赖。 |
23+
| index.allinone.html | 全合一 HTML 入口文件,默认包含所有可被脚本下载的依赖。 |
24+
| index.allinone.min.html | 压缩后的全合一 HTML 入口文件,默认包含所有可被脚本下载的依赖。 |
25+
1926
### 手动部署
2027

21-
1. 下载并重命名本仓库的 `index.html` 文件到你的网站根目录或任何其他目录中;
22-
2. 当下载并重命名后的 `index.html` 被访问时,将自动渲染同目录下的 `index.md`,如果 `index.md` 不存在,则渲染 `README.md`
28+
1. [发行页面](https://github.com/PJ-568/MARKDOWN.HTML/releases)下载并重命名您需要的 HTML 文件到你的网站根目录或任何其他目录中;
29+
2. 当下载并重命名后的 HTML 被访问时,将自动渲染同目录下的 `index.md`,如果 `index.md` 不存在,则渲染 `README.md`
2330

2431
### Github Actions
2532

33+
编译并把 HTML 放入指定目录。使用时须将 `<version>` 替换为版本号。
34+
2635
```yaml
2736
- name: Deploy markdown.html
2837
uses: PJ-568/MARKDOWN.HTML@v<version>

README_EN.md

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -4,72 +4,4 @@
44
55
This project aims to provide a low-dependency, simple deployment solution for rendering Markdown web pages.
66

7-
## Features
8-
9-
- **Low dependencies**: Only an HTML file, a small number of CDNs, and server programs are required to complete Markdown pages rendering.
10-
- **Syntax highlighting support**: Renders code blocks in Markdown.
11-
- **Markdown support**: Renders Markdown files into HTML.
12-
- **Mermaid support**: Renders Mermaid syntax in Markdown into diagrams.
13-
- **Multilingual support**: Supports machine translation between multiple languages.
14-
- **Dark mode support**: Supports light, dark, and system-following modes.
15-
- **Pjax support**: Supports page navigation without refreshing the whole page.
16-
17-
## Usage
18-
19-
### Manual Deployment
20-
21-
1. Download and rename the `index.html` file from this repository and place to your website's root directory or any other directory;
22-
2. When the html file is accessed, it will automatically render the `index.md` in the same directory. If `index.md` does not exist, it will render `README.md`.
23-
24-
### Github Actions
25-
26-
```yaml
27-
- name: Deploy markdown.html
28-
uses: PJ-568/MARKDOWN.HTML@v<version>
29-
with:
30-
target-dir: '.'
31-
file-name: 'index.html'
32-
```
33-
34-
## Additional Notes
35-
36-
`The open-source projects used in this project allow modifications, but please retain the original author information. If removal is necessary, please contact the author to avoid losing technical support.` For more details, refer to the [license](#license).
37-
38-
## Code or Content Contributions
39-
40-
We welcome contributions of code and content from anyone interested in this project.
41-
Please checkout [程序逻辑](doc/logic.md).
42-
43-
For a simpler way to contribute, please refer to the [Contribution Guide](CONTRIBUTING.md) for relevant information.
44-
45-
## License
46-
47-
This project is licensed under the [CC BY-SA 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/) license. For full license information, please refer to the [`LICENSE`](LICENSE) file.
48-
49-
### Credits
50-
51-
#### Projects
52-
53-
|Name|License|URL|
54-
|:-:|:--|:--|
55-
|tabler-icons|[MIT License](//mit-license.org)|[Github](https://github.com/tabler/tabler-icons)、[Website](https://tabler.io/icons)|
56-
|highlightjs/highlight.js|[BSD-3-Clause license](https://github.com/highlightjs/highlight.js/raw/refs/heads/main/LICENSE)|[Github](https://github.com/highlightjs/highlight.js)、[Website](https://highlightjs.org)|
57-
|markedjs/marked|[marked License](https://github.com/markedjs/marked/blob/master/LICENSE.md)|[Github](https://github.com/markedjs/marked)、[Website](https://marked.js.org)|
58-
|mermaidjs/mermaid|[MIT License](https://github.com/mermaid-js/mermaid/blob/develop/LICENSE)|[Github](https://github.com/mermaid-js/mermaid)、[Website](https://mermaid.js.org)|
59-
|translate.js|[Apache License Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)|[Github](https://github.com/xnx3/translate)、[Gitee](https://gitee.com/mail_osc/translate)、[Website](https://translate.zvo.cn)|
60-
|darkmode.js|[MIT license](//mit-license.org)|[Github](https://github.com/sandoche/Darkmode.js)、[Website](https://darkmodejs.learn.uno)|
61-
|MoOx/pjax|[MIT license](//mit-license.org)|[Github](https://github.com/MoOx/pjax)|
62-
|instant.page|[MIT license](//mit-license.org)|[Github](https://github.com/instantpage/instant.page)、[Website](https://instant.page)|
63-
|Maple Mono|[OFL-1.1 license](https://openfontlicense.org/open-font-license-official-text/)|[Github](https://github.com/subframe7536/maple-font)、[Website](https://font.subf.dev)|
64-
65-
#### Services
66-
67-
|Icon|Name|
68-
|:-:|:--|
69-
|None|[360 Frontend Static Resource Library](https://cdn.baomitu.com/)|
70-
|![ByteDance Static Resource CDN icon](https://cdn.bytedance.com/src/res/logo.svg)|[ByteDance Static Resource CDN](https://cdn.bytedance.com/)|
71-
|![Chinese Font Network Project](https://chinese-font.netlify.app/favicon.ico)|[Chinese Font Network Project](https://chinese-font.netlify.app)|
72-
73-
## Stargazers over time
74-
75-
[![Stargazers over time](https://starchart.cc/PJ-568/MARKDOWN.HTML.svg?variant=adaptive)](https://starchart.cc/PJ-568/MARKDOWN.HTML)
7+
<!-- TODO -->

action.yml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,46 @@ inputs:
99
file-name:
1010
description: Name of the minimized HTML file
1111
default: "index.html"
12+
use-minified:
13+
description: Whether to use minified HTML file
14+
default: "true"
15+
use-all-in-one:
16+
description: Whether to use all-in-one HTML file
17+
default: "false"
1218

1319
runs:
1420
using: "composite"
1521
steps:
1622
- name: Setup Rust
1723
uses: MatteoH2O1999/setup-rust@v1
24+
if: ${{ inputs.use-minified == 'true' || inputs.use-all-in-one == 'true' }}
1825

1926
- name: Build project
20-
run: cargo build --release
27+
if: ${{ inputs.use-minified == 'true' || inputs.use-all-in-one == 'true' }}
28+
run: cargo install && cargo build --release
2129
shell: bash
2230
working-directory: ${{ github.action_path }}
2331

2432
- name: Generate minimized HTML
25-
run: cargo run --release -- ${{ github.action_path }}/index.html ${{ github.action_path }}/index.min.html
33+
if: ${{ inputs.use-minified == 'true' || inputs.use-all-in-one == 'true' }}
34+
run: cargo run --release -- index.html
2635
shell: bash
2736
working-directory: ${{ github.action_path }}
2837

29-
- name: Deploy minimized file
38+
- name: Deploy file
3039
run: |
3140
mkdir -p "${{ inputs.target-dir }}"
32-
cp -uv ${{ github.action_path }}/index.min.html "${{ inputs.target-dir }}/${{ inputs.file-name }}"
41+
USE_MINIFIED=""
42+
USE_ALL_IN_ONE=""
43+
if [ "${{ inputs.use-minified }}" = "true" ]; then
44+
USE_MINIFIED=".min"
45+
fi
46+
if [ "${{ inputs.use-all-in-one }}" = "true" ]; then
47+
USE_ALL_IN_ONE=".allinone"
48+
fi
49+
cp -uv index${USE_ALL_IN_ONE}${USE_MINIFIED}.html "${{ inputs.target-dir }}/${{ inputs.file-name }}"
3350
shell: bash
51+
working-directory: ${{ github.action_path }}
3452

3553
branding:
3654
icon: 'book-open'

index.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!doctype html>
22

33
<html>
4-
<markdown-html version="1.14.5" author="PJ568" repo="https://github.com/PJ-568/markdown.html"
4+
<markdown-html version="1.15.0" author="PJ568" repo="https://github.com/PJ-568/markdown.html"
55
license="CC BY-SA 4.0 International"></markdown-html>
66

77
<head>
@@ -45,7 +45,7 @@
4545
4646
### 特性
4747
48-
- **依赖少**:仅需一个 HTML 文件、少量 CDN 和服务器程序,即可完成 Markdown 网页渲染。
48+
- **依赖少**:仅需一个 HTML 文件,即可完成 Markdown 网页渲染。
4949
- **Markdown 支持**:将 Markdown 文件渲染为 HTML。
5050
- **Mermaid 支持**:将 Markdown 中的 Mermaid 语法渲染为图表。
5151
- **多语言支持**:支持多种语言间的机器互译。
@@ -592,14 +592,13 @@
592592
if (url) {
593593
window.open(url, '_blank');
594594
event.preventDefault();
595-
return;
596595
} else {
597596
const newWindow = window.open('', '_blank');
598597
newWindow.document.write(imgOrSvg.outerHTML);
599598
newWindow.document.close();
600599
event.preventDefault();
601-
return;
602600
}
601+
return;
603602
}
604603
if (event.target.closest('nav .back-btn')) {
605604
window.history.back();

0 commit comments

Comments
 (0)