Skip to content

Commit 1821696

Browse files
authored
feat: addons doc (#71)
* fix: title levels * feat: add addons doc * fix: remove compiler macro warnings
1 parent afa4515 commit 1821696

17 files changed

+149
-20
lines changed

.vitepress/config.js

+20
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ const Theme = [
7070
},
7171
]
7272

73+
const Addon = [
74+
{
75+
text: 'Use Addon',
76+
link: '/addons/use',
77+
},
78+
{
79+
text: 'Write an Addon',
80+
link: '/addons/write-an-addon',
81+
},
82+
]
83+
7384
const Translations = [
7485
{
7586
text: 'English',
@@ -191,6 +202,10 @@ const slidebars = [
191202
text: 'Themes',
192203
children: Theme,
193204
},
205+
{
206+
text: 'Addons',
207+
children: Addon,
208+
},
194209
{
195210
text: 'Customizations',
196211
children: Customizations,
@@ -254,6 +269,10 @@ module.exports = {
254269
text: 'Theme',
255270
items: Theme,
256271
},
272+
{
273+
text: 'Addon',
274+
items: Addon,
275+
},
257276
{
258277
text: 'Customize',
259278
items: Customizations,
@@ -271,6 +290,7 @@ module.exports = {
271290
sidebar: {
272291
'/guide/': slidebars,
273292
'/themes/': slidebars,
293+
'/addons/': slidebars,
274294
'/custom/': slidebars,
275295
'/builtin/': slidebars,
276296
'/resources/': slidebars,

.vitepress/theme/components/AlgoliaSearchBox.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<script setup lang="ts">
66
import '@docsearch/css'
77
import { useRoute, useRouter } from 'vitepress'
8-
import { defineProps, getCurrentInstance, onMounted, watch } from 'vue'
8+
import { getCurrentInstance, onMounted, watch } from 'vue'
99
import docsearch from '@docsearch/js'
1010
import type { DocSearchHit } from '@docsearch/react/dist/esm/types'
1111
import type { DefaultTheme } from '../config'

.vitepress/theme/components/BooleanDisplay.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { ref, defineProps } from 'vue'
2+
import { ref } from 'vue'
33
44
const props = defineProps({
55
value: {

.vitepress/theme/components/Environment.vue

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
<script setup lang="ts">
2-
import { defineProps } from 'vue'
3-
42
defineProps<{ type: 'node' | 'client' }>()
53
</script>
64

.vitepress/theme/components/NavBar.vue

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
</template>
4040

4141
<script setup lang="ts">
42-
import { defineEmit, defineProps } from 'vue'
4342
import { useRepo } from '../composables/repo'
4443
import NavBarTitle from './NavBarTitle.vue'
4544
import NavLinks from './NavLinks.vue'
@@ -48,7 +47,7 @@ import DarkModeSwitch from './DarkModeSwitch.vue'
4847
4948
const repo = useRepo()
5049
51-
defineEmit(['toggle'])
50+
defineEmits(['toggle'])
5251
5352
defineProps({
5453
showSidebar: { type: Boolean, required: true },

.vitepress/theme/components/NavDropdownLink.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</template>
1515

1616
<script setup lang="ts">
17-
import { defineProps, ref, watch } from 'vue'
17+
import { ref, watch } from 'vue'
1818
import { useRoute } from 'vitepress'
1919
import type { DefaultTheme } from '../config'
2020
import NavDropdownLinkItem from './NavDropdownLinkItem.vue'

.vitepress/theme/components/NavDropdownLinkItem.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</template>
1010

1111
<script setup lang="ts">
12-
import { defineProps, toRefs } from 'vue'
12+
import { toRefs } from 'vue'
1313
import type { DefaultTheme } from '../config'
1414
import { useNavLink } from '../composables/navLink'
1515
import OutboundLink from './icons/OutboundLink.vue'

.vitepress/theme/components/NavLink.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</template>
88

99
<script setup lang="ts">
10-
import { defineProps, toRefs } from 'vue'
10+
import { toRefs } from 'vue'
1111
import type { DefaultTheme } from '../config'
1212
import { useNavLink } from '../composables/navLink'
1313
import OutboundLink from './icons/OutboundLink.vue'

.vitepress/theme/components/ShowCaseInfo.vue

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<script setup lang="ts">
2-
import { defineProps } from 'vue'
32
import type { ShowCaseInfo } from '../../showcases'
43
54
defineProps<{

.vitepress/theme/components/SideBar.vue

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
</template>
1212

1313
<script setup lang="ts">
14-
import { defineProps } from 'vue'
1514
import NavLinks from './NavLinks.vue'
1615
import SideBarLinks from './SideBarLinks.vue'
1716

.vitepress/theme/components/ThemeGallery.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { defineProps, computed } from 'vue'
2+
import { computed } from 'vue'
33
import { official, community } from '../../themes'
44
55
const props = defineProps({

.vitepress/theme/components/ThemeInfo.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { defineProps, ref } from 'vue'
2+
import { ref } from 'vue'
33
import { isClient, useIntervalFn } from '@vueuse/core'
44
import type { ThemeInfo } from '../../themes'
55

.vitepress/theme/components/Tweet.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Usage:
88

99
<script setup lang="ts">
1010
import { useScriptTag, isClient } from '@vueuse/core'
11-
import { defineProps, getCurrentInstance, onMounted, ref } from 'vue'
11+
import { getCurrentInstance, onMounted, ref } from 'vue'
1212
import { isDark } from '../composables/dark'
1313

1414
const props = defineProps<{

TRANSLATIONS.md

+5
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ In case it's already been translated but you're wondering how to maintain it, sk
7777
- [ ] `use.md` - How to use Slidev themes
7878
- [ ] `write-a-theme.md` - Write your own theme
7979

80+
### addons/
81+
82+
- [ ] `use.md` - How to use Slidev addons
83+
- [ ] `write-an-addon.md` - Write your own addon
84+
8085
## Publishing your translations
8186

8287
- [ ] When you finish the translation (at least 90%), `@antfu` in the Discord and we will invite you to the org and make the translation official.

addons/use.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Use Addon
2+
3+
Addons are sets of additionnal components, layouts, styles, configuration...etc. that you can use in your presentation.
4+
5+
They are quite similar to [themes](/themes/use), but in general:
6+
7+
* they don't affect the global styles of your slides
8+
* you can use multiple addons in one presentation
9+
10+
To use addons, you have to install them manually via:
11+
12+
```bash
13+
$ npm install [slidev-addon-package1] [slidev-addon-package2]
14+
```
15+
16+
And then declare the addons either in your frontmatter:
17+
18+
```yaml
19+
---
20+
addons:
21+
- slidev-addon-package1
22+
- slidev-addon-package2
23+
---
24+
```
25+
26+
Or in your `package.json` file:
27+
28+
```json
29+
// package.json
30+
{
31+
"slidev": {
32+
"addons": [
33+
"slidev-addon-package1",
34+
"slidev-addon-package2",
35+
]
36+
}
37+
}
38+
```

addons/write-an-addon.md

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Write an Addon
2+
3+
> Available since v0.32.1
4+
5+
## Capability
6+
7+
An addon can contribute to the following points:
8+
9+
- Global styles (use with caution has it is more the role of [themes](/themes/use))
10+
- Provide custom layouts or override the existing one
11+
- Provide custom components or override the existing one
12+
- Extend Windi CSS configurations
13+
- Configure tools like Monaco and Prism
14+
15+
## Conventions
16+
17+
Adons are published to npm registry, and they should follow the conventions below:
18+
19+
- Package name should start with `slidev-addon-`, for example: `slidev-addon-awesome`
20+
- Add `slidev-addon` and `slidev` in the `keywords` field of your `package.json`
21+
22+
## Setup
23+
24+
### Initialization
25+
26+
To create your addon, start by creating a directory with create a `package.json` file (you can use `npm init`).
27+
28+
Then, install slidev dependencies:
29+
30+
```bash
31+
$ npm install -D @slidev/cli
32+
```
33+
34+
### Testing
35+
36+
To set up the testing playground for your addon, you can create an `example.md` file with some content.
37+
38+
And optionally, you can also add some scripts to your `packages.json`
39+
40+
```json
41+
// package.json
42+
{
43+
"scripts": {
44+
"dev": "slidev example.md",
45+
"build": "slidev build example.md",
46+
"export": "slidev export example.md",
47+
"screenshot": "slidev export example.md --format png"
48+
}
49+
}
50+
```
51+
52+
To publish your theme, simply run `npm publish` and you are good to go. There is no build process required (which means you can directly publish `.vue` and `.ts` files, Slidev is smart enough to understand them).
53+
54+
Addon contribution points follow the same conventions as local customization, please refer to [the docs for the naming conventions](/custom/).
55+
56+
## Addon metadata
57+
58+
### Slidev Version
59+
60+
If the addon is relying on a specific feature of Slidev that are newly introduced, you can set the minimal Slidev version required to have your addon working properly:
61+
62+
```json
63+
// package.json
64+
{
65+
"engines": {
66+
"slidev": ">=0.32.1"
67+
}
68+
}
69+
```
70+
71+
If users are using older versions of Slidev, an error will be thrown.

guide/install.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ You can visit your slides from http://localhost/
137137

138138
Refer to the [tangramor/slidev_docker](https://github.com/tangramor/slidev_docker) for more details.
139139

140-
### Command Line Interface (CLI)
140+
## Command Line Interface (CLI)
141141

142142
`@slidev/cli` Expose a few commands you can use with `npx slidev ...` or by adding scripts in your `package.json`:
143143
```json
@@ -160,7 +160,7 @@ If you use npm scripts, don't forget to add `--` after the npm command:
160160
npm run slidev -- --open
161161
```
162162

163-
#### `slidev [entry]`
163+
### `slidev [entry]`
164164

165165
Start a local server for Slidev.
166166

@@ -175,7 +175,7 @@ Options:
175175
* `--force`, `-f` (`boolean`, default `false`): force the optimizer to ignore the cache and re-bundle.
176176
* `--theme`, `-t` (`string`): override theme.
177177

178-
#### `slidev build [entry]`
178+
### `slidev build [entry]`
179179

180180
Build hostable SPA.
181181

@@ -189,7 +189,7 @@ Options:
189189
* `--download` (`boolean`, default: `false`): allow to download the slides as PDF inside the SPA.
190190
* `--theme`, `-t` (`string`): override theme.
191191

192-
#### `slidev export [entry]`
192+
### `slidev export [entry]`
193193

194194
Export slides to PDF (or other format).
195195

@@ -205,13 +205,13 @@ Options:
205205
* `--with-clicks`, `-c` (`boolean`, default: `false`): export pages for every clicks (see https://sli.dev/guide/animations.html#click-animations).
206206
* `--theme`, `-t` (`string`): override theme.
207207

208-
#### `slidev format [entry]`
208+
### `slidev format [entry]`
209209

210210
Format the markdown file.
211211

212212
* `[entry]` (`string`, default: `slides.md`): path to the slides markdown entry.
213213

214-
#### `slidev theme [subcommand]`
214+
### `slidev theme [subcommand]`
215215

216216
Theme related operations.
217217

0 commit comments

Comments
 (0)