Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated docs. #13

Merged
merged 4 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,19 @@ npm install -g svgo-ll

## Command-line usage

Process single files:
To process a single file with the default settings for **svgo-ll** version 5:

```sh
svgo-ll one.svg two.svg -o one.min.svg two.min.svg
svgo-ll -i one.svg -o one.min.svg
```

Process a directory of files recursively with `-f`/`--folder`:
To process a single file with the latest settings (which will become the defaults for **svgo-ll** version 6):

```sh
svgo-ll -f path/to/directory_with_svgs -o path/to/output_directory
svgo-ll --preset next -i one.svg -o one.min.svg
```

Help for advanced usage:

```sh
svgo-ll --help
```
For more detailed options, see the [command line option documentation](https://github.com/svg-utils/svgo-ll/blob/main/docs/command-line-options.md) or [FAQ](https://github.com/svg-utils/svgo-ll/blob/main/docs/faq.md).

## Configuration

Expand Down
8 changes: 0 additions & 8 deletions docs/04-plugins/mergeStyles.mdx

This file was deleted.

74 changes: 74 additions & 0 deletions docs/command-line-options.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Command Line Options

For examples of how these options can be used, see the [FAQ](./faq.md).

`-v, --version`
Output the version number.

`-i, --input <INPUT...>`
One or more input files to process. Use "-" to take input from STDIN.

`-s, --string <STRING>`
Process an input file specified as a string.

`-f, --folder <FOLDER>`
Process all \*.svg files in the specified folder.

`-o, --output <OUTPUT...>`
File or folder to which output should be written. If no output option is specified, the input file will be overwritten by the processed result. Use "-" to write output to STDOUT.

`--preset <default | next | none>`
Specify which set of predefined plugins to use. If this option is not used, and no plugins are define by the `--config` option,
[preset-default](./preset-default.md) is used.

`--config <CONFIG>`
Custom configuration file.

`--enable <plugin...>`
Specify one or more builtin plugins to run in addition to those specified by `--preset` or `--config`.

`--disable <plugin...>`
Specify one or more plugins specified by `--preset` or `--config` which should not be run.

`--datauri <base64 | enc | unenc>`
Output as Data URI string (base64), URI encoded (enc) or unencoded (unenc) rather than .svg.

`--max-passes <INTEGER>`
Maximum number of iterations over the plugins. Must be an integer between 1 and 10. Default is 10.

`--pretty`
Add line breaks and indentation to output.

`--indent <INTEGER>`
Number of spaces to indent if `--pretty` is specified. Default is 4.

`--eol <lf | crlf>`
Line break to use when outputting SVG. If unspecified, the platform default is used.

`--final-newline`
Ensure output ends with a line break.

`-r, --recursive`
If `--folder` is specified, process files in all sub-folders recursively.

`--exclude <PATTERN...>`
If `--folder` is specified, exclude files matching any of the specified regular expression patterns.

`-q, --quiet`
Only output error messages, not regular status messages.

`--show-plugins`
Show available plugins and exit.

`--no-color`
Output messages in plain text without color.

`-h, --help`
Display help for command line options.

## Syntax

If an option has exactly one value, it can be expressed either with or without an `=`, for example as `-i test.svg` or `-i=test.svg`.

If an option has more than one value it can be expressed by followin the argument with the values separated by spaces,
for example as `-i test1.svg test2.svg`.
28 changes: 28 additions & 0 deletions docs/faq.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# FAQ

Compression

- [Just remove whitespace from a file](#comp-ws)
- [Run a single plugin](#comp-1plugin)

## Compression

<a id="comp-1plugin"></a>

### Run a single plugin

Use `preset-none` and `--enable`. For example:

```
npx svgo-ll --preset none --enable minifyPathData -i test.svg
```

<a id="comp-ws"></a>

### Just remove whitespace from a file

Use `preset-none`. For example:

```
npx svgo-ll --preset none -i test.svg
```
9 changes: 9 additions & 0 deletions docs/plugins/cleanupXlink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# cleanupXlink

Changes `xlink:href` attributes to `href` attributes. If an `href` attribute is already present, the `xlink:href` attribute is removed.

The plugin has no effect if:

- The document has scripts.
- The document has `<style>` elements with CSS which **svgo-ll** is not able to process.
- The document has `<style>` elements with attribute selectors.
73 changes: 73 additions & 0 deletions docs/preset-next.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
`preset-next` is the set of plugins that will become the [defaults](./preset-default.md) in version 6. To enable these plugins, use the
`--preset=next` option on the command line.

## Plugins List

The following plugins are included in `preset-next`, in the order that they're executed:

- removeDoctype
- removeXMLProcInst
- removeComments
- removeMetadata
- removeEditorsNSData
- removeDesc
- cleanupAttrs
- [cleanupXlink](./plugins/cleanupXlink.md)
- cleanupStyleAttributes
- combineStyleElements
- inlineStyles
- minifyStyles
- cleanupIds
- removeUselessDefs
- convertColors
- [removeUnknownsAndDefaults](./plugins/removeUnknownsAndDefaults.md)
- removeNonInheritableGroupAttrs
- removeUselessStrokeAndFill
- removeHiddenElems
- removeEmptyText
- minifyTransforms
- convertEllipseToCircle
- moveElemsAttrsToGroup
- moveElemsStylesToGroup
- collapseGroups
- convertShapeToPath
- combinePaths
- minifyPathData
- removeEmptyAttrs
- removeEmptyContainers
- removeUnusedNS

## Disable a Plugin

Sometimes a specific plugin might not be appropriate for your workflow. You can continue using `preset-default` while disabling any plugin by using the `overrides` parameter.

In `overrides`, reference the plugin ID and set it to `false` to disable it:

```js
module.exports = {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
cleanupIds: false,
},
},
},
],
};
```

Alternatively, you can drop `preset-default` entirely, and configure your own plugin pipeline from scratch, with only the desirable plugins:

```js
module.exports = {
plugins: [
'removeDoctype',
'removeXMLProcInst',
'minifyStyles',
'sortAttrs',
'sortDefsChildren',
],
};
```
16 changes: 10 additions & 6 deletions lib/svgo/coa.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default function makeProgram(program) {
'Specify one or more plugins from the preset or config which should not be run ',
)
.option(
'--datauri <FORMAT>',
'--datauri <base64 | enc | unenc>',
'Output as Data URI string (base64), URI encoded (enc) or unencoded (unenc)',
)
.option(
Expand All @@ -81,13 +81,17 @@ export default function makeProgram(program) {
'10',
)
.option('--multipass', 'DEPRECATED - use --max-passes')
.option('--pretty', 'Make SVG pretty printed')
.option('--indent <INTEGER>', 'Indent number when pretty printing SVGs')
.option('--pretty', 'Add line breaks and indentation to output')
.option(
'--eol <EOL>',
'Line break to use when outputting SVG: lf, crlf. If unspecified, uses platform default.',
'--indent <INTEGER>',
'Number of spaces to indent if --pretty is specified',
'4',
)
.option('--final-newline', 'Ensure SVG ends with a line break')
.option(
'--eol <lf | crlf>',
'Line break to use when outputting SVG. If unspecified, the platform default is used',
)
.option('--final-newline', 'Ensure output ends with a line break')
.option(
'-r, --recursive',
"Use with '--folder'. Optimizes *.svg files in folders recursively.",
Expand Down