Skip to content

Commit 4284f55

Browse files
authored
Add support for Vuepress 2 (#9)
1 parent 4fe1892 commit 4284f55

File tree

21 files changed

+333
-199
lines changed

21 files changed

+333
-199
lines changed

.github/workflows/demo.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ jobs:
1111
steps:
1212
- name: Checkout Git repository
1313
uses: actions/checkout@v2
14+
15+
- name: Install plugin dependencies
16+
run: npm install
17+
18+
- name: Build and link the plugin
19+
run: npm run build && npm link
1420

1521
- name: Build and Deploy
1622
uses: jenkey2011/vuepress-deploy@master
@@ -21,5 +27,5 @@ jobs:
2127
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
2228
CNAME: code-switcher.padarom.xyz
2329
TARGET_BRANCH: gh-pages
24-
BUILD_SCRIPT: cd demo && npm install && npm run build
30+
BUILD_SCRIPT: npm run build --workspace @vuepress-plugin-code-switcher/demo
2531
BUILD_DIR: src/.vuepress/dist

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ node_modules
22
yarn.lock
33
package-lock.json
44
demo/src/.vuepress/dist
5+
demo/src/.vuepress/.cache
6+
demo/src/.vuepress/.temp
7+
lib

.npmignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

README.md

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
11
# vuepress-plugin-code-switcher
22
Component that allows having synchronized language switchable code blocks (e.g. to switch between Java and Kotlin examples). Selected languages are persisted to local storage to have language selection be permanent across page requests.
33

4-
_Requires Vuepress 1.0+_
4+
This plugin supports both Vuepress 1 and 2. Since Vuepress 1 plugins are incompatible with Vuepress 2 I try to maintain the plugin for both Vuepress versions. Those plugin versions can be seen in different GitHub branches as shown below.
5+
6+
| | Vuepress 1 | Vuepress 2 |
7+
| -- | --- | --- |
8+
| npm | Versions `1.x.x` | Versions `2.x.x` |
9+
| GitHub | [`vuepress-1` Branch](https://github.com/padarom/vuepress-plugin-code-switcher/tree/vuepress-1) | [`main` Branch](https://github.com/padarom/vuepress-plugin-code-switcher/tree/main) |
510

611
## Demo
712
A live demo is available at https://code-switcher.padarom.xyz.
813

914
![](preview.gif)
1015
## Installation
16+
**These instructions are only valid for Vuepress 2. If you use Vuepress 1, see [here](https://github.com/padarom/vuepress-plugin-code-switcher/blob/vuepress-1/README.md#installation).**
17+
1118
```
12-
$ npm install vuepress-plugin-code-switcher --save
19+
$ npm install vuepress-plugin-code-switcher@~2.0 --save
1320
```
1421

1522
After installing, add it to your Vuepress configuration's plugin list:
1623

17-
```js
18-
module.exports = {
24+
```ts
25+
import { codeSwitcherPlugin } from 'vuepress-plugin-code-switcher'
26+
27+
export default {
1928
// Your remaining configuration ...
20-
plugins: [ 'code-switcher' ],
29+
plugins: [ codeSwitcherPlugins(/* your config options go here */) ],
2130
}
2231
```
2332

@@ -53,18 +62,22 @@ specify your languages every single time. Therefore you can instantiate the
5362
plugin with options and name the default languages for a given group:
5463

5564
```js
56-
module.exports = {
65+
import { codeSwitcherPlugin } from 'vuepress-plugin-code-switcher'
66+
67+
export default {
5768
// Your remaining configuration ...
5869
plugins: [
59-
[
60-
'code-switcher',
61-
{
62-
groups: {
63-
default: { ts: 'TypeScript', js: 'JavaScript' },
64-
jvm: { java: 'Java', kotlin: 'Kotlin', jruby: 'JRuby' },
65-
},
70+
codeSwitcherPlugins({
71+
groups: {
72+
default: { ts: 'TypeScript', js: 'JavaScript' },
73+
jvm: { java: 'Java', kotlin: 'Kotlin', jruby: 'JRuby' },
6674
},
67-
],
75+
76+
// You can also specify a custom name for the code switcher component.
77+
// If chaning the name like so, you then use the component as <CustomCodeSwitcher>
78+
// in your markdown code
79+
componentName: 'CustomCodeSwitcher',
80+
})
6881
],
6982
}
7083
```

components/CodeSwitcher.vue

Lines changed: 0 additions & 112 deletions
This file was deleted.

demo/package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
{
2-
"name": "vuepress-plugin-code-switcher-test",
2+
"name": "@vuepress-plugin-code-switcher/demo",
3+
"private": true,
34
"scripts": {
45
"dev": "vuepress dev src",
56
"build": "vuepress build src"
67
},
7-
"dependencies": {
8-
"vuepress-plugin-code-switcher": "file://.."
9-
},
108
"devDependencies": {
11-
"vuepress": "^1.5.3"
9+
"vuepress": "^2.0.0-beta.51"
1210
}
1311
}

demo/src/.vuepress/config.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

demo/src/.vuepress/config.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { defineUserConfig } from 'vuepress'
2+
import { codeSwitcherPlugin } from '../../../lib/node'
3+
import { defaultTheme } from '@vuepress/theme-default'
4+
5+
export default defineUserConfig({
6+
title: 'Code Switcher Vuepress Plugin',
7+
8+
theme: defaultTheme({
9+
repo: 'https://github.com/padarom/vuepress-plugin-code-switcher',
10+
editLink: true,
11+
docsDir: 'demo/src',
12+
lastUpdated: true,
13+
}),
14+
15+
plugins: [
16+
codeSwitcherPlugin({
17+
groups: {
18+
synchronized: { julia: 'Julia', kotlin: 'Kotlin', perl: 'Perl' },
19+
'group-1': { nim: 'Nim', ocaml: 'OCaml' },
20+
'group-2': { nim: 'Nim', ocaml: 'OCaml' },
21+
},
22+
}),
23+
],
24+
})

enhanceAppFile.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

index.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)