Skip to content

Commit 5b6c148

Browse files
committed
docs: Update README with SVG id naming convention
1 parent 101e2d4 commit 5b6c148

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,27 @@ Which will render the following (assuming that `globalClasses: "svgicon", defaul
138138
</svg>
139139
```
140140

141+
### SVG id naming convention
142+
```
143+
📂assets
144+
┣ 📂svg
145+
┣ 📜 item.svg
146+
┣ 📂 sub_dir_1
147+
┃ ┗ 📜 item-1.svg
148+
┗ 📂 sub_dir_2
149+
┗ 📂 sub_sub_dir_2
150+
┗ 📜 example item 2.svg
151+
```
152+
For a directory structure as above, the respective SVG ids generated are as follows:
153+
```js
154+
svg "item" // no subdirectory prefix
155+
svg "sub_dir_1--item-1" // one level subdirectory with '--' prefix
156+
svg "sub_dir_2--sub_sub_dir_2--example_item_2" // two level subdirectory with '--' prefix, also convert spaces into '_'
157+
```
158+
141159
### Using your own shortcode to render SVGs
142160

143-
You can write your own SVG shortcode if you prefer. To make sure the SVG is referenced correctly, you can use the snippet below to start. `#svg-` is the prefix created by svg-sprite and `name` would be the filename of the SVG without the `.svg` extension.
161+
You can write your own SVG shortcode if you prefer. To make sure the SVG is referenced correctly, you can use the snippet below to start. `#svg-` is the prefix created by svg-sprite and `name` would be the filename of the SVG without the `.svg` extension (also refer to [SVG id naming convention](#svg-id-naming-convention) for edge cases and other uses).
144162

145163
```js
146164
eleventyConfig.addShortcode("icon", function (name) {

0 commit comments

Comments
 (0)