Skip to content

Commit f66126d

Browse files
committed
chore: add docs
1 parent 785d4a1 commit f66126d

12 files changed

Lines changed: 3050 additions & 274 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Sample workflow for building and deploying a VitePress site to GitHub Pages
2+
#
3+
name: Deploy VitePress site to Pages
4+
5+
on:
6+
# Runs on pushes targeting the `main` branch. Change this to `master` if you're
7+
# using the `master` branch as the default branch.
8+
push:
9+
branches: [main]
10+
11+
# Allows you to run this workflow manually from the Actions tab
12+
workflow_dispatch:
13+
14+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
15+
permissions:
16+
contents: read
17+
pages: write
18+
id-token: write
19+
20+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
21+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
22+
concurrency:
23+
group: pages
24+
cancel-in-progress: false
25+
26+
jobs:
27+
# Build job
28+
build:
29+
runs-on: ubuntu-latest
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v4
33+
with:
34+
fetch-depth: 0 # Not needed if lastUpdated is not enabled
35+
# - uses: pnpm/action-setup@v3 # Uncomment this block if you're using pnpm
36+
# with:
37+
# version: 9 # Not needed if you've set "packageManager" in package.json
38+
# - uses: oven-sh/setup-bun@v1 # Uncomment this if you're using Bun
39+
- name: Setup Node
40+
uses: actions/setup-node@v4
41+
with:
42+
node-version: 22
43+
cache: npm # or pnpm / yarn
44+
- name: Setup Pages
45+
uses: actions/configure-pages@v4
46+
- name: Install dependencies
47+
run: pnpm install # or pnpm install / yarn install / bun install
48+
- name: Build with VitePress
49+
run: pnpm docs:build # or pnpm docs:build / yarn docs:build / bun run docs:build
50+
- name: Upload artifact
51+
uses: actions/upload-pages-artifact@v3
52+
with:
53+
path: docs/.vitepress/dist
54+
55+
# Deployment job
56+
deploy:
57+
environment:
58+
name: github-pages
59+
url: ${{ steps.deployment.outputs.page_url }}
60+
needs: build
61+
runs-on: ubuntu-latest
62+
name: Deploy
63+
steps:
64+
- name: Deploy to GitHub Pages
65+
id: deployment
66+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ node_modules
22
dist
33
*.log
44
.DS_Store
5+
6+
docs/.vitepress/cache

docs/.vitepress/config.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { defineConfig } from 'vitepress'
2+
3+
// https://vitepress.dev/reference/site-config
4+
export default defineConfig({
5+
title: 'Utils for Developers',
6+
description: 'Make DX pleasure',
7+
base: '/utils',
8+
themeConfig: {
9+
// https://vitepress.dev/reference/default-theme-config
10+
nav: [
11+
// { text: 'Home', link: '/' },
12+
// { text: 'Examples', link: '/markdown-examples' },
13+
],
14+
15+
sidebar: [
16+
{
17+
// text: 'Browser',
18+
items: [
19+
{ text: 'Getting Started', link: '/' },
20+
{ text: 'Configuration', link: '/configuration' },
21+
{ text: 'JS', link: '/js' },
22+
{ text: 'Browser', link: '/browser' },
23+
{ text: 'React', link: '/react' },
24+
// { text: 'Runtime API Examples', link: '/api-examples' },
25+
],
26+
},
27+
],
28+
29+
socialLinks: [
30+
{ icon: 'github', link: 'https://github.com/vuejs/vitepress' },
31+
],
32+
},
33+
})

docs/api-examples.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
outline: deep
3+
---
4+
5+
# Runtime API Examples
6+
7+
This page demonstrates usage of some of the runtime APIs provided by VitePress.
8+
9+
The main `useData()` API can be used to access site, theme, and page data for the current page. It works in both `.md` and `.vue` files:
10+
11+
```md
12+
<script setup>
13+
import { useData } from 'vitepress'
14+
15+
const { theme, page, frontmatter } = useData()
16+
</script>
17+
18+
## Results
19+
20+
### Theme Data
21+
<pre>{{ theme }}</pre>
22+
23+
### Page Data
24+
<pre>{{ page }}</pre>
25+
26+
### Page Frontmatter
27+
<pre>{{ frontmatter }}</pre>
28+
```
29+
30+
<script setup>
31+
import { useData } from 'vitepress'
32+
33+
const { site, theme, page, frontmatter } = useData()
34+
</script>
35+
36+
## Results
37+
38+
### Theme Data
39+
<pre>{{ theme }}</pre>
40+
41+
### Page Data
42+
<pre>{{ page }}</pre>
43+
44+
### Page Frontmatter
45+
<pre>{{ frontmatter }}</pre>
46+
47+
## More
48+
49+
Check out the documentation for the [full list of runtime APIs](https://vitepress.dev/reference/runtime-api#usedata).

docs/browser.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Browser
2+
3+
## isBrowser
4+
5+
用于判断当前环境是否支持浏览器运行环境
6+
7+
### 使用方式
8+
9+
```js
10+
import { isBrowser } from '@shilong/utils'
11+
12+
if (isBrowser()) {
13+
console.log('Browser environment')
14+
document.getElementById('root')
15+
}
16+
```
17+
18+
## copyToClipboard
19+
20+
用于动态使用 js 将内容拷贝到设备粘贴板中,方便用户拷贝内容(可以理解为 **选中 + Ctrl/Cmd + C**
21+
22+
### 使用方式
23+
24+
```js
25+
import { copyToClipboard } from '@shilong/utils'
26+
27+
const ele = document.getElementById('root')
28+
ele.addEventListener('click', async () => {
29+
const url = ele.getAttribute('data-url')
30+
if (!url) return
31+
const res = await copyToClipboard(url)
32+
res && console.log(`链接内容 ${url} 已复制到粘贴板`)
33+
})
34+
```
35+
36+
WIP...

docs/configuration.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Configuration
2+
3+
## HTTP STATUS
4+
5+
参考 [MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status) 进行一些常用的 **http status** 状态码以及描述信息的抽离
6+
7+
### 使用
8+
9+
```js
10+
import { httpStatus, type HttpStatusCode } from '@shilong/utils'
11+
12+
console.log(httpStatus[500].msg) // -> Internal Server Error
13+
14+
/**
15+
* {
16+
msg: 'Internal Server Error',
17+
}
18+
*/
19+
console.log(httpStatus[500])
20+
```
21+
22+
一般用在封装 **api** 的场景中,例如
23+
24+
```js
25+
export const request = (input, init) => {
26+
return fetch(input, init).then((res) => {
27+
if (res.status >= 200 && res.status < 300) {
28+
return res
29+
} else {
30+
throw new Error(
31+
// 此处使用
32+
res.statusText ? res.statusText : httpStatus[res.status].msg
33+
)
34+
}
35+
})
36+
}
37+
```
38+
39+
WIP...

docs/index.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Getting Started
2+
3+
## 安装
4+
5+
目前只支持 ES 模块
6+
7+
```sh
8+
npm install @shilong/utils --save
9+
# pnpm add @shilong/utils -S
10+
```
11+
12+
### 使用
13+
14+
```js
15+
import { isBrowser } from '@shilong/utils'
16+
17+
if (isBrowser()) {
18+
console.log('Browser environment')
19+
document.getElementById('root')
20+
}
21+
```
22+
23+
WIP...

0 commit comments

Comments
 (0)