Compare commits

..

No commits in common. "main" and "v0.6.0" have entirely different histories.
main ... v0.6.0

10 changed files with 31 additions and 1306 deletions

1
.gitignore vendored
View File

@ -1,4 +1,3 @@
notes/ notes/
target/ target/
assets/ assets/
templates/*.min.html

View File

@ -6,28 +6,6 @@ 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

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
[package] [package]
name = "mdpreview" name = "mdpreview"
version = "0.6.3" version = "0.6.0"
edition = "2024" edition = "2024"
authors = ["Vladislav Kan <thek4n@yandex.ru>"] authors = ["Vladislav Kan <thek4n@yandex.ru>"]
build = "build.rs" build = "build.rs"
@ -14,7 +14,6 @@ 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"] }

View File

@ -1,7 +1,5 @@
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 =
@ -16,11 +14,6 @@ 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");
@ -86,30 +79,3 @@ 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}"))
}

View File

@ -52,7 +52,7 @@ pub struct FileEntry {
} }
#[derive(Template)] #[derive(Template)]
#[template(path = ".dir.min.html")] #[template(path = "dir.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.min.html")] #[template(path = "file.html")]
pub struct NoteTemplate { pub struct NoteTemplate {
pub filename: String, pub filename: String,
pub back_link: String, pub back_link: String,

View File

@ -435,9 +435,7 @@ 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!( _ => format!("<a href=\"{dest_url}\" title=\"{title}\">"),
"<a href=\"{dest_url}\" title=\"{title}\" target=\"_blank\" rel=\"noopener noreferrer\">"
),
} }
} }

View File

@ -236,6 +236,8 @@
<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;
@ -274,6 +276,6 @@
hljs.highlightAll(); hljs.highlightAll();
</script> </script>
<script>{% block scripts %}{% endblock %}</script>
</body> </body>
</html> </html>

View File

@ -1,4 +1,4 @@
{% extends ".base.min.html" %} {% extends "base.html" %}
{% block title %}Directory: /{{ title_path }}{% endblock %} {% block title %}Directory: /{{ title_path }}{% endblock %}

View File

@ -1,4 +1,4 @@
{% extends ".base.min.html" %} {% extends "base.html" %}
{% block title %}{{ filename }}{% endblock %} {% block title %}{{ filename }}{% endblock %}