|
| 1 | +--- |
| 2 | +isNav: true |
| 3 | +--- |
| 4 | + |
| 5 | +# Plugins |
| 6 | + |
| 7 | +## `<gbp-code-group>` |
| 8 | + |
| 9 | +Used to display several pieces of code with similar functionality: |
| 10 | + |
| 11 | +<gbp-code-group> |
| 12 | + |
| 13 | +```bash npm |
| 14 | +npm i gem-book |
| 15 | +``` |
| 16 | + |
| 17 | +```bash yarn |
| 18 | +yarn add gem-book |
| 19 | +``` |
| 20 | + |
| 21 | +</gbp-code-group> |
| 22 | + |
| 23 | +````md |
| 24 | +<gbp-code-group> |
| 25 | + |
| 26 | +```bash npm |
| 27 | +npm i gem-book |
| 28 | +``` |
| 29 | + |
| 30 | +```bash yarn |
| 31 | +yarn add gem-book |
| 32 | +``` |
| 33 | + |
| 34 | +</gbp-code-group> |
| 35 | +```` |
| 36 | + |
| 37 | +## `<gbp-raw>` |
| 38 | + |
| 39 | +Used to display remote code. If the provided `src` only contains a path, it will read content from the current project's GitHub (affected by [`sourceDir`](./002-cli.md#--source-dir) and [`sourceBranch`](./002-cli.md#--source-branch)), for example: |
| 40 | + |
| 41 | +<gbp-raw src="package.json" range="2-3,-4--6,author-license" highlight="-5,author"></gbp-raw> |
| 42 | + |
| 43 | +```md |
| 44 | +<!-- `range` specifies the display range, supporting negative numbers and string matching, `highlight` format is the same --> |
| 45 | + |
| 46 | +<gbp-raw src="package.json" range="2-3,-4--6,author-license" highlight="-5,author"></gbp-raw> |
| 47 | +``` |
| 48 | + |
| 49 | +## `<gbp-var>` |
| 50 | + |
| 51 | +Reference global variable: <gbp-var>hello</gbp-var> |
| 52 | + |
| 53 | +```md |
| 54 | +<gbp-var>hello</gbp-var> |
| 55 | +``` |
| 56 | + |
| 57 | +The variable needs to be defined in the [configuration file](./002-cli.md). |
| 58 | + |
| 59 | +## `<gbp-media>` |
| 60 | + |
| 61 | +Displays remote multimedia content, such as images or videos, using the same resource retrieval method as `<gbp-raw>`: |
| 62 | + |
| 63 | +```md |
| 64 | +<gbp-media src="preview.png"></gbp-media> |
| 65 | +``` |
| 66 | + |
| 67 | +## `<gbp-include>` |
| 68 | + |
| 69 | +Dynamically loads Markdown snippets: |
| 70 | + |
| 71 | +<gbp-include src="./guide/007-extension.md" range="[!NOTE]->"></gbp-include> |
| 72 | + |
| 73 | +```md |
| 74 | +<!-- `range` syntax is the same as `<gbp-raw>`, here `range` uses string matching --> |
| 75 | + |
| 76 | +<gbp-include src="./guide/007-extension.md" range="[!NOTE]->"></gbp-include> |
| 77 | +``` |
| 78 | + |
| 79 | +## `<gbp-import>` |
| 80 | + |
| 81 | +Dynamically imports modules, which can be used to load plugins on demand. For example, the following custom element is dynamically loaded (the `.ts` file will be compiled using [esm.sh](https://esm.sh/)): |
| 82 | + |
| 83 | +<gbp-import src="docs/hello.ts"></gbp-import> |
| 84 | + |
| 85 | +<my-plugin-hello></my-plugin-hello> |
| 86 | + |
| 87 | +```md |
| 88 | +<gbp-import src="docs/hello.ts"></gbp-import> |
| 89 | + |
| 90 | +<my-plugin-hello></my-plugin-hello> |
| 91 | +``` |
| 92 | + |
| 93 | +## `<gbp-content>` |
| 94 | + |
| 95 | +Insert content into `<gem-book>`, allowing customization of `<gem-book>` content on specific pages, such as a custom sidebar: |
| 96 | + |
| 97 | +```md |
| 98 | +<gbp-content slot="sidebar-before"> |
| 99 | + <div>Test</div> |
| 100 | + <style> |
| 101 | + gem-book [part=sidebar-content] { |
| 102 | + display: none; |
| 103 | + } |
| 104 | + </style> |
| 105 | +</gbp-content> |
| 106 | +``` |
| 107 | + |
| 108 | +## `<gbp-docsearch>` |
| 109 | + |
| 110 | +Use [Algolia DocSearch](https://docsearch.algolia.com/) to provide search for the website, instantiated only once, and can be placed using [slots](./guide/007-extension.md#slots): |
| 111 | + |
| 112 | +<gbp-raw src="docs/template.html" range="13--4"></gbp-raw> |
| 113 | + |
| 114 | +> [!WARNING] |
| 115 | +> |
| 116 | +> `renderJavaScript` must be enabled in the [configuration](https://crawler.algolia.com/admin/crawlers) for Algolia DocSearch Crawler. |
| 117 | +
|
| 118 | +Using `docsearch?local` can provide local search service (thanks to [MiniSearch](https://github.com/lucaong/minisearch/)), [example](https://duoyun-ui.gemjs.org). |
| 119 | + |
| 120 | +## `<gbp-comment>` |
| 121 | + |
| 122 | +It uses [Gitalk](https://github.com/gitalk/gitalk) to bring comment functionality to the website, similar to the usage of `<gbp-docsearch>`: |
| 123 | + |
| 124 | +```html |
| 125 | +<gem-book> |
| 126 | + <gbp-comment |
| 127 | + slot="main-after" |
| 128 | + client-id="xxx" |
| 129 | + client-secret="xxx" |
| 130 | + ></gbp-comment> |
| 131 | +</gem-book> |
| 132 | +``` |
| 133 | + |
| 134 | +## `<gbp-sandpack>` |
| 135 | + |
| 136 | +Use [Sandpack](https://sandpack.codesandbox.io/) to create interactive examples: |
| 137 | + |
| 138 | +<gbp-sandpack dependencies="@mantou/gem, duoyun-ui"> |
| 139 | + |
| 140 | +```ts |
| 141 | +import { render, html } from '@mantou/gem'; |
| 142 | + |
| 143 | +import 'duoyun-ui/elements/button'; |
| 144 | + |
| 145 | +render( |
| 146 | + html`<dy-button>Time: ${new Date().toLocaleString()}</dy-button>`, |
| 147 | + document.getElementById('root'), |
| 148 | +); |
| 149 | +``` |
| 150 | + |
| 151 | +</gbp-sandpack> |
| 152 | + |
| 153 | +````md |
| 154 | +<gbp-sandpack dependencies="@mantou/gem, duoyun-ui"> |
| 155 | + |
| 156 | +```ts |
| 157 | +import { render, html } from '@mantou/gem'; |
| 158 | + |
| 159 | +import 'duoyun-ui/elements/button'; |
| 160 | + |
| 161 | +render( |
| 162 | + html`<dy-button>Time: ${new Date().toLocaleString()}</dy-button>`, |
| 163 | + document.getElementById('root'), |
| 164 | +); |
| 165 | +``` |
| 166 | + |
| 167 | +</gbp-sandpack> |
| 168 | +```` |
| 169 | + |
| 170 | +## `<gbp-example>` |
| 171 | + |
| 172 | +Generate examples for any custom element, for example: |
| 173 | + |
| 174 | +<gbp-example name="dy-avatar" src="https://esm.sh/duoyun-ui/elements/avatar"> |
| 175 | + |
| 176 | +```json |
| 177 | +{ |
| 178 | + "src": "https://api.dicebear.com/5.x/bottts-neutral/svg", |
| 179 | + "status": "positive", |
| 180 | + "size": "large", |
| 181 | + "square": true |
| 182 | +} |
| 183 | +``` |
| 184 | + |
| 185 | +</gbp-example> |
| 186 | + |
| 187 | +````md |
| 188 | +<gbp-example name="dy-avatar" src="https://esm.sh/duoyun-ui/elements/avatar"> |
| 189 | + |
| 190 | +```json |
| 191 | +{ |
| 192 | + "src": "https://api.dicebear.com/5.x/bottts-neutral/svg", |
| 193 | + "status": "positive", |
| 194 | + "size": "large", |
| 195 | + "square": true |
| 196 | +} |
| 197 | +``` |
| 198 | + |
| 199 | +</gbp-example> |
| 200 | +```` |
| 201 | + |
| 202 | +## `<gbp-api>` |
| 203 | + |
| 204 | +Use [`gem-analyzer`](https://github.com/mantou132/gem/blob/main/packages/gem-analyzer) to generate API documentation for `GemElement`, such as [GemBookElement API](./004-api.md); |
0 commit comments