Skip to content

Commit 6f539b6

Browse files
committed
add oxvg
1 parent 3ff7e9c commit 6f539b6

File tree

4 files changed

+39
-27
lines changed

4 files changed

+39
-27
lines changed

Cargo.toml

Lines changed: 8 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ansi2/Cargo.toml

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ansi2/src/main.rs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -116,25 +116,10 @@ fn main() {
116116
sourcemap,
117117
);
118118
if compress {
119-
svg = osvg::osvg(
120-
&svg,
121-
Some(
122-
r#"
123-
{
124-
plugins: [
125-
{
126-
name: "preset-default",
127-
params: {
128-
overrides: {
129-
inlineStyles: false,
130-
},
131-
},
132-
},
133-
],
134-
}"#,
135-
),
136-
)
137-
.expect("compress error");
119+
#[cfg(feature = "minify")]
120+
{
121+
svg = minify_svg(&svg).expect("compress error");
122+
}
138123
}
139124
svg
140125
}
@@ -146,3 +131,24 @@ fn main() {
146131
};
147132
print!("{}", output);
148133
}
134+
135+
fn minify_svg(svg: &str) -> Result<String, String> {
136+
use oxvg_ast::{
137+
implementations::{roxmltree::parse, shared::Element},
138+
serialize::{self, Node as _, Options},
139+
visitor::Info,
140+
};
141+
use oxvg_optimiser::Jobs;
142+
let arena = typed_arena::Arena::new();
143+
let dom = parse(svg, &arena).map_err(|e| e.to_string())?;
144+
145+
Jobs::default()
146+
.run(&dom, &Info::<Element>::new(&arena))
147+
.map_err(|err| err.to_string())?;
148+
149+
dom.serialize_with_options(Options {
150+
indent: serialize::Indent::None,
151+
..Default::default()
152+
})
153+
.map_err(|err| err.to_string())
154+
}

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ neofetch | ansi2 --format=svg --light-bg=#FFFFFF --dark-bg=#181818 > neofetch.sv
9797

9898
### compress
9999

100-
Compressing using [osvg](https://github.com/ahaoboy/osvg) and [svgo](https://github.com/svg/svgo), this will increase the running time by several seconds, but can save half of the storage space.
100+
Compressing using [oxvg](https://github.com/noahbald/oxvg.git), this maybe will increase the running time by several seconds, but can save half of the storage space.
101101

102102
```bash
103103
neofetch | ansi2 --format=svg --compress > neofetch.svg

0 commit comments

Comments
 (0)