Skip to content

Commit 4284f55

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

21 files changed

+333
-199
lines changed
 

‎.github/workflows/demo.yaml

+7-1
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

+3
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

-3
This file was deleted.

‎README.md

+27-14
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

-112
This file was deleted.

‎demo/package.json

+3-5
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

-23
This file was deleted.

‎demo/src/.vuepress/config.ts

+24
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

-1
This file was deleted.

‎index.js

-15
This file was deleted.

‎package.json

+29-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "vuepress-plugin-code-switcher",
3+
"version": "2.0.0",
34
"author": {
45
"name": "Christopher Mühl",
56
"email": "christopher@padarom.xyz",
@@ -9,10 +10,35 @@
910
"type": "git",
1011
"url": "https://github.com/padarom/vuepress-plugin-code-switcher"
1112
},
12-
"version": "1.1.0",
13-
"main": "index.js",
13+
"scripts": {
14+
"build": "tsc -b tsconfig.build.json && cpx \"src/**/*.{d.ts,vue,scss}\" lib",
15+
"dev": "npm run dev --workspace @vuepress-plugin-code-switcher/demo"
16+
},
17+
"workspaces": ["./demo"],
18+
"packageManager": "pnpm@7.11.0",
19+
"type": "module",
20+
"exports": {
21+
".": "./lib/node/index.js",
22+
"./client": "./lib/client/index.js",
23+
"./package.json": "./package.json"
24+
},
25+
"main": "./lib/node/index.ts",
26+
"types": "./lib/node/index.d.ts",
27+
"files": [
28+
"lib"
29+
],
1430
"license": "MIT",
31+
"devDependencies": {
32+
"cpx": "^1.5.0",
33+
"sass": "^1.55.0",
34+
"sass-loader": "^13.0.2",
35+
"typescript": "^4.8.4"
36+
},
1537
"dependencies": {
16-
"@vuepress/plugin-register-components": "^1.8.0"
38+
"@vuepress/client": "^2.0.0-beta.51",
39+
"@vuepress/core": "^2.0.0-beta.51",
40+
"@vuepress/utils": "^2.0.0-beta.51",
41+
"tiny-emitter": "^2.1.0",
42+
"vue": "^3.2.40"
1743
}
1844
}

0 commit comments

Comments
 (0)
Please sign in to comment.