Skip to content

Commit

Permalink
docs(preprocess-auto-slug): complete docs page
Browse files Browse the repository at this point in the history
  • Loading branch information
Quang Phan committed Nov 21, 2022
1 parent b2eaf2a commit af949ec
Show file tree
Hide file tree
Showing 37 changed files with 600 additions and 48 deletions.
5 changes: 5 additions & 0 deletions .changeset/quick-crabs-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@svelte-put/preprocess-auto-slug': patch
---

mature enough implementation with complelte docs page
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Useful svelte stuff to put in your projects
- [Packages](#packages)
- [Svelte Actions](#svelte-actions)
- [Miscellaneous](#miscellaneous)
- [Preprocessors](#preprocessors)
- [In the Pipeline](#in-the-pipeline)
- [Contributing](#contributing)

Expand Down Expand Up @@ -53,18 +54,23 @@ Useful svelte stuff to put in your projects
| [@svelte-put/avatar][github.avatar] | component & utilities for avatar | [![npm.avatar.badge]][npm.avatar] | [Changelog][github.avatar.changelog] | [API][github.avatar.docs] | [![docs.badge]][docs.avatar] |
| [@svelte-put/modal][github.modal] | type-safe async modal builder | [![npm.modal.badge]][npm.modal] | [Changelog][github.modal.changelog] | [API][github.modal.docs] | coming soon |

### Preprocessors

| Package | Short Description | Version | Changelog | API | Docs |
| --------------------------------------------------------------- | ------------------------------------------ | ------------------------------------------------------------- | -------------------------------------------------- | --------------------------------------- | ------------------------------------------ |
| [@svelte-put/preprocess-auto-slug][github.preprocess-auto-slug] | auto add `id` and anchor to selected nodes | [![npm.preprocess-auto-slug.badge]][npm.preprocess-auto-slug] | [Changelog][github.preprocess-auto-slug.changelog] | [API][github.preprocess-auto-slug.docs] | [![docs.badge]][docs.preprocess-auto-slug] |

### In the Pipeline

These are some packages that will be added in the future (as soon as I find time, and the implementation has matured & become generic enough).

| Package | Category | Short Description | Status | Docs |
| --------------------------------------------------------------- | ------------ | ---------------------------------------------------------------------------- | ------------------ | ----------- |
| [@svelte-put/preprocess-auto-slug][github.preprocess-auto-slug] | preprocessor | auto add `id` and `anchor` to headings | beta | coming soon |
| [@svelte-put/select][github.select] | component | minimal & extensible `select` | active development | coming soon |
| @svelte-put/popover | action | trigger tooltip & detailed popover, using [popperjs](https://popper.js.org/) | prototype |
| @svelte-put/noti | utility | fire async toast-like notification | prototype |
| @svelte-put/inputcache | action | cache & restore value of input into/from local/session storage | prototype |
| @svelte-put/form | action | auto collect type-safe input value from form (???) | inception |
| Package | Category | Short Description | Status | Docs |
| ----------------------------------- | --------- | ---------------------------------------------------------------------------- | ------------------ | ----------- |
| [@svelte-put/select][github.select] | component | minimal & extensible `select` | active development | coming soon |
| @svelte-put/popover | action | trigger tooltip & detailed popover, using [popperjs](https://popper.js.org/) | prototype |
| @svelte-put/noti | utility | fire async toast-like notification | prototype |
| @svelte-put/inputcache | action | cache & restore value of input into/from local/session storage | prototype |
| @svelte-put/form | action | auto collect type-safe input value from form (???) | inception |

Names for those packages may change.

Expand Down
1 change: 0 additions & 1 deletion apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
"svelte-check": "^2.9.2",
"svelte-highlight": "^6.2.1",
"svelte-preprocess": "^4.10.7",
"svelte-preprocess-import-assets": "^0.2.2",
"tailwindcss": "^3.2.4",
"ts-node": "^10.9.1",
"tslib": "^2.4.1",
Expand Down
9 changes: 5 additions & 4 deletions apps/docs/src/data/packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,18 @@ export const packages = {
'preprocess-auto-slug': {
id: 'preprocess-auto-slug',
name: '@svelte-put/preprocess-auto-slug',
description: 'add id slug and anchor to node',
description: 'svelte preprocessor to add id attribute and anchor tag',
path: APP_ROUTE_TREE.docs.preprocessAutoSlug.$.path(),
replId: undefined,
category: 'preprocessor',
status: 'beta',
ready: false,
status: 'new',
ready: true,
githubUrl:
'https://github.com/vnphanquang/svelte-put/tree/main/packages/preprocessors/auto-slug',
changelogUrl:
'https://github.com/vnphanquang/svelte-put/blob/main/packages/preprocessors/preprocess-auto-slug/CHANGELOG.md',
apiUrl: '',
apiUrl:
'https://github.com/vnphanquang/svelte-put/blob/main/packages/preprocessors/auto-slug/api/docs/index.md',
},
select: {
id: 'select',
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1,68 @@
Documentation coming soon!
<script lang="ts">
import suspiciousLinksImg from '$lib/assets/images/suspicious-links.webp';
import Code from '$lib/ui/components/Code/Code.svelte';
import Installation from '$lib/ui/components/Installation/Installation.svelte';
import ResourceLink from '$lib/ui/components/ResourceLink/ResourceLink.svelte';
import type { PageData } from './$types';
import { codes } from './codes';
export let data: PageData;
</script>

<section>
<h2>Acknowledgement</h2>
<p>
This package is heavily inspired by
<ResourceLink href="https://github.com/rehypejs/rehype-slug">rehype-slug</ResourceLink>
and
<ResourceLink href="https://github.com/rehypejs/rehype-autolink-headings">
rehype-autolink-headings
</ResourceLink>.
</p>
</section>

<Installation pkg={data.package.name} />

<section>
<h2>Quick Start</h2>
<Code lang="svelte" code={codes.quickStart} title="svelte.config.js" />
</section>

<section>
<h2>Customization</h2>

<p>
Almost every aspect of <code>preprocess-auto-slug</code> can be customized, including which tags
to process, how <code>id</code> and <code>href</code> is generated, or the placement of the anchor
tag.
</p>
<p>
For more details, inspect in-code documentation, read the
<ResourceLink href={data.package.apiUrl}>API Reference</ResourceLink>, and check out the
<ResourceLink
href="https://github.com/vnphanquang/svelte-put/blob/vercel/packages/preprocessors/auto-slug/src/auto-slug.constants.ts"
>default options</ResourceLink
>.
</p>

<p>
This documentation site uses this very package. Most <code>id</code>
and link tag for headings are auto-generated during build. See <ResourceLink
href="https://github.com/vnphanquang/svelte-put/blob/vercel/apps/docs/svelte.config.js"
>svelte.config.js</ResourceLink
>
as an example for a more complex use case.
</p>
</section>

<img
src={suspiciousLinksImg}
alt="mouse click faster"
width="300"
height="168"
loading="lazy"
decoding="async"
/>

<p>Happy slugging! 👨‍💻</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import quickStart from './quickStart.js?raw';

export const codes = {
quickStart,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import autoSlug from '@svelte-put/preprocess-auto-slug';

/** @type {import('@sveltejs/kit').Config} */
const config = {
preprocess: [autoSlug()],
};

export default config;
15 changes: 0 additions & 15 deletions apps/docs/svelte.config.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
import autoSlug from '@svelte-put/preprocess-auto-slug';
import adapter from '@sveltejs/adapter-vercel';
import preprocess from 'svelte-preprocess';
// import importAssets from 'svelte-preprocess-import-assets';

/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
preprocess: [
// importAssets({
// sources: () => [
// {
// tag: 'Code',
// srcAttributes: ['code'],
// },
// {
// tag: 'img',
// srcAttributes: ['src'],
// },
// ],
// }),
autoSlug((defaultOptions) => ({
tags: ['h2', 'h3', 'h4', 'h5', 'h6'],
anchor: {
Expand Down
40 changes: 40 additions & 0 deletions packages/preprocessors/auto-slug/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,44 @@

# `@svelte-put/preprocess-auto-slug`

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

Svelte preprocessor for adding `id` and anchor to nodes

</div>

## Usage & Documentation

[See the dedicated documentation page here][docs].

## `svelte-put`

This package is part of the [@svelte-put][github.monorepo] family. For contributing guideline and more, refer to its [readme][github.monorepo].

## [Changelog][github.changelog]

<p align="center">
<a href="https://www.buymeacoffee.com/vnphanquang" target="_blank">
<img
src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png"
height="60"
width="217"
alt="buy vnphanquang a coffee"
/>
</a>
</p>

<!-- github specifics -->

[github.monorepo]: https://github.com/vnphanquang/svelte-put
[github.changelog]: https://github.com/vnphanquang/svelte-put/blob/main/packages/actions/preprocess-auto-slug/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-auto-slug
[npm]: https://www.npmjs.com/package/@svelte-put/preprocess-auto-slug
[bundlephobia.badge]: https://img.shields.io/bundlephobia/minzip/@svelte-put/preprocess-auto-slug?label=minzipped
[bundlephobia]: https://bundlephobia.com/package/@svelte-put/preprocess-auto-slug
[docs]: https://svelte-put.vnphanquang.com/docs/preprocess-auto-slug
[docs.badge]: https://img.shields.io/badge/-Docs%20Site-blue
6 changes: 6 additions & 0 deletions packages/preprocessors/auto-slug/api-extractor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"extends": "@svelte-put/apirc/base.json",
"projectFolder": ".",
"mainEntryPointFilePath": "<projectFolder>/lib/index.d.ts"
}
11 changes: 11 additions & 0 deletions packages/preprocessors/auto-slug/api/docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md)

## API Reference

## Packages

| Package | Description |
| ------------------------------------------------------------- | ----------- |
| [@svelte-put/preprocess-auto-slug](./preprocess-auto-slug.md) | |
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@svelte-put/preprocess-auto-slug](./preprocess-auto-slug.md) &gt; [autoSlug](./preprocess-auto-slug.autoslug.md)

## autoSlug() function

create svelte preprocessor to generate slug from text content of matching tags

By default, it will search for all headings tag and add the generated slug to the tag's id attribute.

<b>Signature:</b>

```typescript
declare function autoSlug(input?: AutoSlugInput): PreprocessorGroup;
```

## Parameters

| Parameter | Type | Description |
| --------- | -------------------------------------------------------- | ----------------- |
| input | [AutoSlugInput](./preprocess-auto-slug.autosluginput.md) | <i>(Optional)</i> |

<b>Returns:</b>

PreprocessorGroup

svelte preprocessor interface
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@svelte-put/preprocess-auto-slug](./preprocess-auto-slug.md) &gt; [AutoSlugAnchorOptions](./preprocess-auto-slug.autosluganchoroptions.md) &gt; [content](./preprocess-auto-slug.autosluganchoroptions.content.md)

## AutoSlugAnchorOptions.content property

content of the inserted anchor tag, ignored when behavior is `wrap`<!-- -->. Default to '\#'

<b>Signature:</b>

```typescript
content: string;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@svelte-put/preprocess-auto-slug](./preprocess-auto-slug.md) &gt; [AutoSlugAnchorOptions](./preprocess-auto-slug.autosluganchoroptions.md) &gt; [enabled](./preprocess-auto-slug.autosluganchoroptions.enabled.md)

## AutoSlugAnchorOptions.enabled property

whether to insert an anchor tag for each matching node

<b>Signature:</b>

```typescript
enabled: boolean;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@svelte-put/preprocess-auto-slug](./preprocess-auto-slug.md) &gt; [AutoSlugAnchorOptions](./preprocess-auto-slug.autosluganchoroptions.md) &gt; [href](./preprocess-auto-slug.autosluganchoroptions.href.md)

## AutoSlugAnchorOptions.href property

href attribute of the inserted anchor tag

<b>Signature:</b>

```typescript
href: (slug: string) => string;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@svelte-put/preprocess-auto-slug](./preprocess-auto-slug.md) &gt; [AutoSlugAnchorOptions](./preprocess-auto-slug.autosluganchoroptions.md)

## AutoSlugAnchorOptions interface

instructions for adding anchor tag

<b>Signature:</b>

```typescript
interface AutoSlugAnchorOptions
```

## Properties

| Property | Modifiers | Type | Description |
| ------------------------------------------------------------------------ | --------- | ------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [content](./preprocess-auto-slug.autosluganchoroptions.content.md) | | string | content of the inserted anchor tag, ignored when behavior is <code>wrap</code>. Default to '\#' |
| [enabled](./preprocess-auto-slug.autosluganchoroptions.enabled.md) | | boolean | whether to insert an anchor tag for each matching node |
| [href](./preprocess-auto-slug.autosluganchoroptions.href.md) | | (slug: string) =&gt; string | href attribute of the inserted anchor tag |
| [position](./preprocess-auto-slug.autosluganchoroptions.position.md) | | 'prepend' \| 'append' \| 'wrap' \| 'before' \| 'after' | <p>where to create the anchor tag</p><p>- 'prepend' — inject link before the target tag text</p><p>- 'append' — inject link after the target tag text</p><p>- 'wrap' — wrap the whole target tag text with the link</p><p>- 'before' — insert link before the target tag</p><p>- 'after' — insert link after the target tag</p><p>default to <code>prepend</code></p> |
| [properties](./preprocess-auto-slug.autosluganchoroptions.properties.md) | | Record&lt;string, string&gt; | properties set to the inserted anchor tag, defaults to <code>{ 'aria-hidden': 'true', 'tab-index': '-1' }</code> |
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@svelte-put/preprocess-auto-slug](./preprocess-auto-slug.md) &gt; [AutoSlugAnchorOptions](./preprocess-auto-slug.autosluganchoroptions.md) &gt; [position](./preprocess-auto-slug.autosluganchoroptions.position.md)

## AutoSlugAnchorOptions.position property

where to create the anchor tag

- 'prepend' — inject link before the target tag text

- 'append' — inject link after the target tag text

- 'wrap' — wrap the whole target tag text with the link

- 'before' — insert link before the target tag

- 'after' — insert link after the target tag

default to `prepend`

<b>Signature:</b>

```typescript
position: 'prepend' | 'append' | 'wrap' | 'before' | 'after';
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@svelte-put/preprocess-auto-slug](./preprocess-auto-slug.md) &gt; [AutoSlugAnchorOptions](./preprocess-auto-slug.autosluganchoroptions.md) &gt; [properties](./preprocess-auto-slug.autosluganchoroptions.properties.md)

## AutoSlugAnchorOptions.properties property

properties set to the inserted anchor tag, defaults to `{ 'aria-hidden': 'true', 'tab-index': '-1' }`

<b>Signature:</b>

```typescript
properties: Record<string, string>;
```
Loading

0 comments on commit af949ec

Please sign in to comment.