Skip to content

Commit 493feda

Browse files
committed
docs: update
1 parent 1861ec5 commit 493feda

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+300
-88
lines changed

docs/.vitepress/config.ts

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { defineConfig } from 'vitepress'
2-
import { transformerTwoslash } from '@shikijs/vitepress-twoslash'
3-
import ts from 'typescript'
2+
import { defaultHoverInfoProcessor, transformerTwoslash } from '@shikijs/vitepress-twoslash'
3+
import { transformerRemoveNotationEscape } from '@shikijs/transformers'
44
import { getLocaleConfig } from './locale'
55

66
const docsLink = 'https://js-utils-es.vercel.app'
@@ -41,15 +41,60 @@ export default defineConfig({
4141
},
4242
markdown: {
4343
codeTransformers: [
44+
{
45+
// Render custom themes with codeblocks
46+
name: 'shiki:inline-theme',
47+
preprocess(code, options) {
48+
const reg = /\btheme:([\w,-]+)\b/
49+
const match = options.meta?.__raw?.match(reg)
50+
if (!match?.[1])
51+
return
52+
const theme = match[1]
53+
const themes = theme.split(',').map(i => i.trim())
54+
if (!themes.length)
55+
return
56+
if (themes.length === 1) {
57+
// @ts-expect-error anyway
58+
delete options.themes
59+
// @ts-expect-error anyway
60+
options.theme = themes[0]
61+
}
62+
else if (themes.length === 2) {
63+
// @ts-expect-error anyway
64+
delete options.theme
65+
// @ts-expect-error anyway
66+
options.themes = {
67+
light: themes[0],
68+
dark: themes[1],
69+
}
70+
}
71+
else {
72+
throw new Error(`Only 1 or 2 themes are supported, got ${themes.length}`)
73+
}
74+
return code
75+
},
76+
},
77+
{
78+
name: 'shiki:inline-decorations',
79+
preprocess(code, options) {
80+
const reg = /^\/\/ @decorations:(.*)\n/
81+
code = code.replace(reg, (match, decorations) => {
82+
options.decorations ||= []
83+
options.decorations.push(...JSON.parse(decorations))
84+
return ''
85+
})
86+
return code
87+
},
88+
},
4489
transformerTwoslash({
45-
twoslashOptions: {
46-
compilerOptions: {
47-
jsx: ts.JsxEmit.Preserve,
48-
jsxFactory: 'vue',
49-
types: ['unplugin-vue-macros/macros-global', 'vue/jsx'],
50-
},
90+
// errorRendering: 'hover',
91+
processHoverInfo(info) {
92+
return defaultHoverInfoProcessor(info)
93+
// Remove shiki_core namespace
94+
.replace(/_shikijs_core\w*\./g, '')
5195
},
5296
}),
97+
transformerRemoveNotationEscape(),
5398
],
5499
},
55100
})

docs/.vitepress/locale.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function getLocaleConfig(lang: string) {
2020
['meta', { property: 'og:url', content: docsLink }],
2121
['meta', { property: 'twitter:card', content: 'summary_large_image' }],
2222
['meta', { property: 'twitter:image', content: `${docsLink}/og.png` }],
23-
['link', { rel: 'icon', type: 'image/svg+xml', href: '/favicon.svg' }],
23+
['link', { rel: 'icon', href: '/logo.svg', type: 'image/svg+xml' }],
2424
['meta', { name: 'theme-color', content: '#914796' }],
2525
]
2626

@@ -174,7 +174,7 @@ export function getLocaleConfig(lang: string) {
174174
]
175175

176176
const themeConfig: DefaultTheme.Config = {
177-
logo: '/favicon.svg',
177+
logo: '/logo.svg',
178178
nav,
179179
sidebar,
180180
socialLinks: [

docs/.vitepress/theme/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ export default {
2020
mapAuthors: [
2121
{
2222
name: 'hunghg255',
23+
username: 'hunghg255',
24+
mapByNameAliases: ['Hung Hoang', 'Hoang Hung'],
25+
mapByEmailAliases: ['giahunghust@gmail.com'],
2326
},
2427
],
2528
})

docs/.vitepress/theme/style.css

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,49 @@
1+
/**
2+
* Customize default theme styling by overriding CSS variables:
3+
* https://github.com/vuejs/vitepress/blob/main/src/client/theme-default/styles/vars.css
4+
*/
5+
6+
/**
7+
* Colors
8+
*
9+
* Each colors have exact same color scale system with 3 levels of solid
10+
* colors with different brightness, and 1 soft color.
11+
*
12+
* - `XXX-1`: The most solid color used mainly for colored text. It must
13+
* satisfy the contrast ratio against when used on top of `XXX-soft`.
14+
*
15+
* - `XXX-2`: The color used mainly for hover state of the button.
16+
*
17+
* - `XXX-3`: The color for solid background, such as bg color of the button.
18+
* It must satisfy the contrast ratio with pure white (#ffffff) text on
19+
* top of it.
20+
*
21+
* - `XXX-soft`: The color used for subtle background such as custom container
22+
* or badges. It must satisfy the contrast ratio when putting `XXX-1` colors
23+
* on top of it.
24+
*
25+
* The soft color must be semi transparent alpha channel. This is crucial
26+
* because it allows adding multiple "soft" colors on top of each other
27+
* to create a accent, such as when having inline code block inside
28+
* custom containers.
29+
*
30+
* - `default`: The color used purely for subtle indication without any
31+
* special meanings attched to it such as bg color for menu hover state.
32+
*
33+
* - `brand`: Used for primary brand colors, such as link text, button with
34+
* brand theme, etc.
35+
*
36+
* - `tip`: Used to indicate useful information. The default theme uses the
37+
* brand color for this by default.
38+
*
39+
* - `warning`: Used to indicate warning to the users. Used in custom
40+
* container, badges, etc.
41+
*
42+
* - `danger`: Used to show error, or dangerous message to the users. Used
43+
* in custom container, badges, etc.
44+
* -------------------------------------------------------------------------- */
45+
46+
147
/**
248
* Colors
349
* -------------------------------------------------------------------------- */
@@ -135,3 +181,7 @@
135181
.VPLocalSearchBox .excerpt-wrapper {
136182
margin-top: 4px;
137183
}
184+
185+
.VPHomeHero .VPImage {
186+
border-radius: 16px;
187+
}

docs/index.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,4 @@ features:
2121
details: js-utils-es ships up to 97% less JavaScript code compared to other alternative libraries.
2222
- title: Modern implementation
2323
details: js-utils-es fully leverages modern JavaScript APIs for straightforward and error-free implementation.
24-
- title: Robust types
25-
details: js-utils-es offers simple yet robust types for all functions.
26-
- title: Battle-tested
27-
details: js-utils-es has 100% test coverage, ensuring maximum robustness.
28-
- title: Comprehensive runtime support
29-
details: js-utils-es supports all JavaScript environments, including Node.js, Deno, Bun, and browsers.
3024
---

docs/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
"preview": "vitepress preview"
1010
},
1111
"dependencies": {
12+
"@shikijs/transformers": "^1.10.3",
1213
"prettier": "^3.3.2",
1314
"shiki": "^1.10.3"
1415
},
1516
"devDependencies": {
1617
"@nolebase/vitepress-plugin-enhanced-mark": "^2.2.1",
1718
"@nolebase/vitepress-plugin-enhanced-readabilities": "^2.2.1",
18-
"@nolebase/vitepress-plugin-git-changelog": "^2.2.1",
19+
"@nolebase/vitepress-plugin-git-changelog": "^2.2.2",
1920
"@nolebase/vitepress-plugin-highlight-targeted-heading": "^2.2.1",
2021
"@shikijs/vitepress-twoslash": "^1.10.3",
2122
"@vitejs/plugin-vue-jsx": "^4.0.0",

docs/public/favicon.ico

15 KB
Binary file not shown.

docs/public/logo.svg

Lines changed: 1 addition & 0 deletions
Loading

docs/reference/array/chunk.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Throws an error if `size` is not a positive integer.
2727

2828
## Examples
2929

30-
```typescript
30+
```typescript twoslash
3131
import { chunk } from 'js-utils-es/array';
3232

3333
// Splits an array of numbers into sub-arrays of length 2

docs/reference/array/compact.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ function compact<T>(arr: T[]): Array<Exclude<T, false | null | 0 | '' | undefine
1818

1919
## Examples
2020

21-
```typescript
21+
```typescript twoslash
22+
import { compact } from 'js-utils-es/array';
23+
2224
compact([0, 1, false, 2, '', 3, null, undefined, 4, Number.NaN, 5]);
2325
// Returns: [1, 2, 3, 4, 5]
2426
```

0 commit comments

Comments
 (0)