Skip to content

Commit

Permalink
docs(preprocess-external-link): some basic docs
Browse files Browse the repository at this point in the history
  • Loading branch information
vnphanquang committed Jul 9, 2024
1 parent 4566ed3 commit f523c03
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 52 deletions.
5 changes: 5 additions & 0 deletions .changeset/flat-trees-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@svelte-put/preprocess-external-link': patch
---

add some basic info at README.md
85 changes: 33 additions & 52 deletions packages/preprocess-external-link/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<div align="center">

# `@svelte-put/preprocess-inline-svg`
# `@svelte-put/preprocess-external-link`

[![npm.badge]][npm] [![bundlephobia.badge]][bundlephobia] [![docs.badge]][docs]

Svelte preprocessor for inlining static svg at build time
Svelte preprocessor for adding attributes to anchor tags that point to external domains.

</div>

Expand All @@ -21,80 +21,61 @@ This package is part of the [@svelte-put][github.monorepo] family. For contribut
Given this `svelte.config.js`

```javascript
import inlineSvg from '@svelte-put/preprocess-inline-svg';
import externalLink from '@svelte-put/preprocess-external-link';

/** @type {import('@sveltejs/kit').Config} */
const config = {
preprocess: [
inlineSvg([
{
directories: 'src/assets/icons',
attributes: {
class: 'icon',
width: '20',
height: '20',
},
},
{
directories: 'src/assets/pictograms',
},
]),
externalLink(['your-domain.com', 'your-other-domain.com']),
// other preprocessors
],
};
export default config;
```

and the asset files as follow

```tree
src/assets
|
|-- icons
|-- svelte.svg
|
|-- google
|-- arrow-right.svg
|-- simpleicons
|-- github.svg
|
|-- pictograms
|-- diagram.svg
```

We can now do
and the following input markup

```html
<!-- this will have width="20" height="20" as specified in the config -->
<svg data-inline-src="svelte"></svg>
```svelte
<script>
let href = 'https://developer.mozilla.org';
</script>
<!-- nested -->
<svg data-inline-src="google/arrow-right.svg"></svg>
<!-- .svg can be omitted -->
<svg data-inline-src="simpleicons/github"></svg>
<!-- links that are treated as internal -->
<a href="/internal-path">Internal Path</a>
<a href="https//your-domain.com/some-path">Internal Path</a>
<a href="https//your-other-domain.com/some-path">Internal Path</a>
<!-- with custom attributes -->
<svg data-inline-src="diagram" width="100" height="100"></svg>
<!-- links that are treated as external -->
<a href="https://svelte.dev/">Svelte</a>
<a {href} data-external>Svelte</a>
```

<!-- alternatively, you can provide a per-case path that is relative to the current source file -->
<svg data-inline-src="./local-icon.svg"></svg>
will output

<!-- if the source svg is not found for any of the above, an error will be thrown -->
```html
<!-- links that are treated as internal -->
<a href="/internal-path">Internal Path</a>
<a href="https//your-domain.com/some-path">Internal Path</a>
<a href="https//your-other-domain.com/some-path">Internal Path</a>

<!-- links that are treated as external -->
<a href="https://svelte.dev/" target="_blank" rel="noreferrer noopener">Svelte</a>
<a {href} data-external target="_blank" rel="noreferrer noopener">Svelte</a>
```

## [Changelog][github.changelog]

<!-- github specifics -->

[github.monorepo]: https://github.com/vnphanquang/svelte-put
[github.changelog]: https://github.com/vnphanquang/svelte-put/blob/main/packages/preprocess-inline-svg/CHANGELOG.md
[github.changelog]: https://github.com/vnphanquang/svelte-put/blob/main/packages/preprocess-external-link/CHANGELOG.md
[github.issues]: https://github.com/vnphanquang/svelte-put/issues?q=

<!-- heading badge -->

[npm.badge]: https://img.shields.io/npm/v/@svelte-put/preprocess-inline-svg
[npm]: https://www.npmjs.com/package/@svelte-put/preprocess-inline-svg
[bundlephobia.badge]: https://img.shields.io/bundlephobia/minzip/@svelte-put/preprocess-inline-svg?label=minzipped
[bundlephobia]: https://bundlephobia.com/package/@svelte-put/preprocess-inline-svg
[docs]: https://svelte-put.vnphanquang.com/docs/preprocess-inline-svg
[npm.badge]: https://img.shields.io/npm/v/@svelte-put/preprocess-external-link
[npm]: https://www.npmjs.com/package/@svelte-put/preprocess-external-link
[bundlephobia.badge]: https://img.shields.io/bundlephobia/minzip/@svelte-put/preprocess-external-link?label=minzipped
[bundlephobia]: https://bundlephobia.com/package/@svelte-put/preprocess-external-link
[docs]: https://svelte-put.vnphanquang.com/docs/preprocess-external-link
[docs.badge]: https://img.shields.io/badge/-Docs%20Site-blue

0 comments on commit f523c03

Please sign in to comment.