Skip to content

Commit 67f4e38

Browse files
committed
wip docs, add extensions api
1 parent dec9193 commit 67f4e38

13 files changed

+460
-78
lines changed

docs/.vitepress/config.ts

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { defineConfig } from 'vitepress'
2+
import { tabsMarkdownPlugin } from 'vitepress-plugin-tabs'
23

34
// https://vitepress.dev/reference/site-config
45
export default defineConfig({
@@ -13,17 +14,31 @@ export default defineConfig({
1314
],
1415

1516
sidebar: [
17+
{ text: 'Introduction', link: '/introduction', },
1618
{
17-
text: 'Examples',
19+
text: 'Installation',
1820
items: [
19-
{ text: 'Markdown Examples', link: '/markdown-examples' },
20-
{ text: 'Runtime API Examples', link: '/api-examples' }
21+
{ text: 'Server', link: '/installation/server' },
22+
{ text: 'Client', link: '/installation/client' },
23+
]
24+
},
25+
{
26+
text: 'Usage',
27+
items: [
28+
{ text: 'Navigation', link: '/usage/navigation' },
29+
{ text: 'Extensions API', link: '/usage/extensions' },
2130
]
2231
}
2332
],
2433

2534
socialLinks: [
26-
{ icon: 'github', link: 'https://github.com/vuejs/vitepress' }
35+
{ icon: 'github', link: 'https://github.com/westacks/vortex' }
2736
]
37+
},
38+
markdown: {
39+
config(md) {
40+
// @ts-ignore
41+
md.use(tabsMarkdownPlugin)
42+
}
2843
}
2944
})

docs/.vitepress/theme/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { h } from 'vue'
33
import type { Theme } from 'vitepress'
44
import DefaultTheme from 'vitepress/theme'
5+
import { enhanceAppWithTabs } from 'vitepress-plugin-tabs/client'
56
import './style.css'
67

78
export default {
@@ -12,6 +13,6 @@ export default {
1213
})
1314
},
1415
enhanceApp({ app, router, siteData }) {
15-
// ...
16+
enhanceAppWithTabs(app)
1617
}
1718
} satisfies Theme
File renamed without changes.

docs/index.md

+14-12
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,24 @@ layout: home
44

55
hero:
66
name: "Vortex"
7-
text: "Server-based routing for SPA"
8-
tagline: My great project tagline
7+
text: "Server-side routing for SPA"
8+
tagline: Low-level API, High-level Efficiency
99
actions:
1010
- theme: brand
11-
text: Markdown Examples
12-
link: /markdown-examples
11+
text: Learn More
12+
link: /introduction
1313
- theme: alt
14-
text: API Examples
15-
link: /api-examples
14+
text: Examples
15+
link: /examples
1616

1717
features:
18-
- title: Feature A
19-
details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
20-
- title: Feature B
21-
details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
22-
- title: Feature C
23-
details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
18+
- title: Truly Framework-Agnostic
19+
details: Works seamlessly with any front-end framework.
20+
21+
- title: SSR support
22+
details: Provides simple API to pre-render pages on the server.
23+
24+
- title: Low-Level API Access
25+
details: Offers full control and customization of your application.
2426
---
2527

docs/installation/client.md

+156
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
# Client-Side Installation
2+
3+
Once you have prepared [server-side](/installation/server.md) adapter, you will need to setup your client-side framework.
4+
5+
## Install Dependencies
6+
7+
First, you need to install Vortex client:
8+
9+
::: tabs
10+
11+
== npm
12+
```shell
13+
npm install @westacks/vortex
14+
```
15+
== yarn
16+
```shell
17+
yarn add @westacks/vortex
18+
```
19+
== pnpm
20+
```shell
21+
pnpm add @westacks/vortex
22+
```
23+
== bun
24+
```shell
25+
bun add @westacks/vortex
26+
```
27+
:::
28+
29+
## Initialize Application
30+
31+
Next, initialize Vortex client and create your application root:
32+
33+
::: tabs
34+
== Svelte
35+
**_app.js_**
36+
37+
Create application root and subscribe to page changes.
38+
```js
39+
import { createVortex, subscribe } from '@westacks/vortex'
40+
import { props } from './setup'
41+
import App from './App.svelte'
42+
43+
createVortex(async (target, page, hydrate) => {
44+
const app = new App({ target, props: await props(page), hydrate })
45+
46+
subscribe(async (page) => app.$set(await props(page)))
47+
})
48+
```
49+
**_setup.js_**
50+
51+
You will need to resolve page component, using your bundler's API. We will provide example for Vite as most popular, but code below may differ depending on bundler you are using.
52+
```js
53+
export const props = async (page) => {
54+
const pages = import.meta.glob('./pages/**/*.svelte')
55+
const component = (await pages[`./pages/${page.component}.svelte`])?.default
56+
57+
return { component, props: page.props ?? {} }
58+
}
59+
```
60+
**_App.svelte_**
61+
```svelte
62+
<script>
63+
export let component, props
64+
</script>
65+
66+
{#if component}
67+
<component this={component} {...props} />
68+
{/if}
69+
```
70+
== Solid
71+
TODO
72+
== Vue
73+
TODO
74+
== React
75+
TODO
76+
== Angular
77+
TODO
78+
:::
79+
80+
After that you may start creating components in `./pages` directory. Each time vortex initiates page change, it will resolve corresponding component, provide it with props and render it.
81+
82+
You are not glued to use app structure provided above, so you may modify it as you wish for your use-cases (layouts, loading states, etc).
83+
84+
## Server-Side Rendering
85+
86+
Optionally, you can setup bundle for server-side rendering (SSR), which can be utilized by your server to pre-render pages of your application:
87+
88+
::: tabs
89+
== Svelte
90+
**_ssr.js_**
91+
```js
92+
import { createVortexServer } from '@westacks/vortex/server'
93+
import { props } from './setup'
94+
import App from './App.svelte'
95+
96+
createVortexServer(async (page) => {
97+
const {html, head} = App.render(await props(page))
98+
99+
// You should return data type, that compatible with your server API
100+
return {body: html, head}
101+
})
102+
103+
```
104+
== Solid
105+
TODO
106+
== Vue
107+
TODO
108+
== React
109+
TODO
110+
== Angular
111+
TODO
112+
:::
113+
114+
### Using SSR bundle
115+
116+
SSR bundle takes page data as input and returns pre-rendered HTML strings based on your client-side logic. You will need a JavaScript runtime configured on your server to use it:
117+
118+
#### Server Mode
119+
120+
::: tabs
121+
== Node.js
122+
```shell
123+
node ./dist/ssr.js
124+
```
125+
== Deno
126+
```shell
127+
deno run --allow-net ./dist/ssr.js
128+
```
129+
== Bun
130+
```shell
131+
bun run --bun ./dist/ssr.js
132+
```
133+
:::
134+
135+
```shell
136+
curl -X POST http://localhost:13714/render \
137+
-H 'Content-Type: application/json' \
138+
-d '{"component":"Page","props":{},"url": "/","version":"..."}'
139+
```
140+
141+
#### CLI Mode
142+
143+
::: tabs
144+
== Node.js
145+
```shell
146+
node ./dist/ssr.js '{"component":"Page","props":{},"url": "/","version":"..."}'
147+
```
148+
== Deno
149+
```shell
150+
deno run ./dist/ssr.js '{"component":"Page","props":{},"url": "/","version":"..."}'
151+
```
152+
== Bun
153+
```shell
154+
bun run --bun ./dist/ssr.js '{"component":"Page","props":{},"url": "/","version":"..."}'
155+
```
156+
:::

docs/installation/server.md

Whitespace-only changes.
File renamed without changes.

docs/usage/extensions.md

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Extensions API
2+
3+
Vortex allows you easily extend your navigation logic on runtime. Extensions use [axios interceptors](https://axios-http.com/docs/interceptors) to "glue in" between your requests and responses.
4+
5+
## Installing extensions
6+
```typescript
7+
import { extend, type VortexExtension } from '@westacks/vortex'
8+
9+
const extension: VortexExtension = ({ request, response }) => ({
10+
request: request.use(
11+
function (request) {
12+
// Modify request config, e.g. add headers, any custom logic
13+
},
14+
function (error) {
15+
// Handle error
16+
}
17+
),
18+
response: response.use(
19+
function (response) {
20+
// Handle response
21+
},
22+
function (error) {
23+
// Handle error
24+
}
25+
)
26+
})
27+
28+
// Add extension
29+
const dispose = extend(extension)
30+
31+
// You may remove extensions at any time you want by calling destructor function
32+
dispose()
33+
```
34+
35+
## Examples
36+
37+
### NProgress
38+
Adds simple progress indicator on top of the page
39+
```typescript
40+
import type { VortexExtension } from '@westacks/vortex'
41+
import NProgress from 'nprogress'
42+
43+
export default ({ request, response }) => ({
44+
request:request.use(
45+
function (config) {
46+
NProgress.start();
47+
return config;
48+
},
49+
function (error) {
50+
NProgress.done();
51+
return Promise.reject(error);
52+
}
53+
),
54+
response: response.use(
55+
function (response) {
56+
NProgress.done();
57+
return response;
58+
},
59+
function (error) {
60+
NProgress.done();
61+
return Promise.reject(error);
62+
}
63+
)
64+
}) as VortexExtension
65+
```
66+
67+
## Community extensions
68+
69+
Feel free to share your extensions by creating Pull Request on [GitHub](https://github.com/westacks/vortex)
70+
71+
- _No one done anything yet, we've just released._

0 commit comments

Comments
 (0)