Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5bb69bac34 | |||
| a8e009b957 | |||
| 348dc8819d | |||
| 027b9517e1 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
notes/
|
notes/
|
||||||
target/
|
target/
|
||||||
assets/
|
assets/
|
||||||
|
templates/*.min.html
|
||||||
|
|||||||
22
CHANGELOG.md
22
CHANGELOG.md
@ -6,6 +6,28 @@ Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to
|
|||||||
[Semantic Versioning](https://semver.org/lang/en/).
|
[Semantic Versioning](https://semver.org/lang/en/).
|
||||||
|
|
||||||
|
|
||||||
|
## `v0.6.3` - 20.07.2026
|
||||||
|
### Fixed
|
||||||
|
- Fixed minify script and templates.
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## `v0.6.2` - 20.07.2026
|
||||||
|
### Changed
|
||||||
|
- Links are now opens in new tab.
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## `v0.6.1` - 17.07.2026
|
||||||
|
### Added
|
||||||
|
- Add compile-time templates minificattion.
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
## `v0.6.0` - 17.07.2026
|
## `v0.6.0` - 17.07.2026
|
||||||
### Added
|
### Added
|
||||||
- Add text emoji support (`:smile:` for example).
|
- Add text emoji support (`:smile:` for example).
|
||||||
|
|||||||
1261
Cargo.lock
generated
1261
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "mdpreview"
|
name = "mdpreview"
|
||||||
version = "0.6.0"
|
version = "0.6.3"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
authors = ["Vladislav Kan <thek4n@yandex.ru>"]
|
authors = ["Vladislav Kan <thek4n@yandex.ru>"]
|
||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
@ -14,6 +14,7 @@ strip = true
|
|||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
reqwest = { version = "0.11", features = ["blocking"] }
|
reqwest = { version = "0.11", features = ["blocking"] }
|
||||||
|
minify-html = "0.18"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
pulldown-cmark = { version = "0.13.4", features = ["simd"] }
|
pulldown-cmark = { version = "0.13.4", features = ["simd"] }
|
||||||
|
|||||||
34
build.rs
34
build.rs
@ -1,5 +1,7 @@
|
|||||||
|
use minify_html::{Cfg, minify};
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::io;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
const HIGHLIGHT_STYLE_URL_TEMPLATE: &str =
|
const HIGHLIGHT_STYLE_URL_TEMPLATE: &str =
|
||||||
@ -14,6 +16,11 @@ fn main() {
|
|||||||
println!("cargo:rerun-if-changed=assets/");
|
println!("cargo:rerun-if-changed=assets/");
|
||||||
println!("cargo:rerun-if-env-changed=FORCE_DEPS_DOWNLOAD");
|
println!("cargo:rerun-if-env-changed=FORCE_DEPS_DOWNLOAD");
|
||||||
|
|
||||||
|
println!("cargo:rerun-if-changed=templates/");
|
||||||
|
minify_template_file("templates/base.html", "templates/.base.min.html").unwrap();
|
||||||
|
minify_template_file("templates/dir.html", "templates/.dir.min.html").unwrap();
|
||||||
|
minify_template_file("templates/file.html", "templates/.file.min.html").unwrap();
|
||||||
|
|
||||||
let out_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
let out_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||||
let assets_path = Path::new(&out_dir).join("assets");
|
let assets_path = Path::new(&out_dir).join("assets");
|
||||||
fs::create_dir_all(&assets_path).expect("Fail to create directory");
|
fs::create_dir_all(&assets_path).expect("Fail to create directory");
|
||||||
@ -79,3 +86,30 @@ fn should_download(path: &Path) -> bool {
|
|||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn minify_template_file<P: AsRef<str>>(input_path: P, output_path: P) -> io::Result<()> {
|
||||||
|
let html_content = fs::read_to_string(input_path.as_ref())?;
|
||||||
|
|
||||||
|
let minified = minify_template_content(&html_content)
|
||||||
|
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
|
||||||
|
|
||||||
|
fs::write(output_path.as_ref(), minified)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::missing_errors_doc)]
|
||||||
|
pub fn minify_template_content(template: &str) -> Result<String, String> {
|
||||||
|
let mut cfg = Cfg::new();
|
||||||
|
cfg.allow_removing_spaces_between_attributes = true;
|
||||||
|
cfg.keep_comments = false;
|
||||||
|
cfg.minify_css = true;
|
||||||
|
cfg.minify_js = true;
|
||||||
|
cfg.keep_html_and_head_opening_tags = true;
|
||||||
|
cfg.keep_closing_tags = true;
|
||||||
|
cfg.remove_processing_instructions = true;
|
||||||
|
|
||||||
|
let minified_bytes = minify(template.as_bytes(), &cfg);
|
||||||
|
|
||||||
|
String::from_utf8(minified_bytes).map_err(|e| format!("Invalid UTF-8 in output: {e}"))
|
||||||
|
}
|
||||||
|
|||||||
@ -52,7 +52,7 @@ pub struct FileEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[template(path = "dir.html")]
|
#[template(path = ".dir.min.html")]
|
||||||
pub struct DirectoryTemplate {
|
pub struct DirectoryTemplate {
|
||||||
pub title_path: String,
|
pub title_path: String,
|
||||||
pub files: Vec<FileEntry>,
|
pub files: Vec<FileEntry>,
|
||||||
@ -65,7 +65,7 @@ pub struct DirectoryTemplate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[template(path = "file.html")]
|
#[template(path = ".file.min.html")]
|
||||||
pub struct NoteTemplate {
|
pub struct NoteTemplate {
|
||||||
pub filename: String,
|
pub filename: String,
|
||||||
pub back_link: String,
|
pub back_link: String,
|
||||||
|
|||||||
@ -435,7 +435,9 @@ fn render_blockquote(quote_kind: Option<BlockQuoteKind>) -> String {
|
|||||||
fn render_link(link_type: LinkType, dest_url: &CowStr<'_>, title: &CowStr<'_>) -> String {
|
fn render_link(link_type: LinkType, dest_url: &CowStr<'_>, title: &CowStr<'_>) -> String {
|
||||||
match link_type {
|
match link_type {
|
||||||
LinkType::Email => format!("<a href=\"mailto:{dest_url}\" title=\"{title}\">"),
|
LinkType::Email => format!("<a href=\"mailto:{dest_url}\" title=\"{title}\">"),
|
||||||
_ => format!("<a href=\"{dest_url}\" title=\"{title}\">"),
|
_ => format!(
|
||||||
|
"<a href=\"{dest_url}\" title=\"{title}\" target=\"_blank\" rel=\"noopener noreferrer\">"
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -236,8 +236,6 @@
|
|||||||
<script src="{{ mermaid_script_url }}"></script>
|
<script src="{{ mermaid_script_url }}"></script>
|
||||||
<script src="{{ highlight_script_url }}"></script>
|
<script src="{{ highlight_script_url }}"></script>
|
||||||
<script>
|
<script>
|
||||||
{% block scripts %}{% endblock %}
|
|
||||||
|
|
||||||
function copyCode(button) {
|
function copyCode(button) {
|
||||||
const wrapper = button.closest('.code-block-wrapper');
|
const wrapper = button.closest('.code-block-wrapper');
|
||||||
if (!wrapper) return;
|
if (!wrapper) return;
|
||||||
@ -276,6 +274,6 @@
|
|||||||
|
|
||||||
hljs.highlightAll();
|
hljs.highlightAll();
|
||||||
</script>
|
</script>
|
||||||
|
<script>{% block scripts %}{% endblock %}</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
{% extends "base.html" %}
|
{% extends ".base.min.html" %}
|
||||||
|
|
||||||
{% block title %}Directory: /{{ title_path }}{% endblock %}
|
{% block title %}Directory: /{{ title_path }}{% endblock %}
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
{% extends "base.html" %}
|
{% extends ".base.min.html" %}
|
||||||
|
|
||||||
{% block title %}{{ filename }}{% endblock %}
|
{% block title %}{{ filename }}{% endblock %}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user