Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: padarom/vuepress-plugin-code-switcher
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 4fe1892848ddb088959a80d88e0bf63ca0621bca
Choose a base ref
...
head repository: padarom/vuepress-plugin-code-switcher
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 4284f55ba38e3f9c8eeb2186158ce90e484926a2
Choose a head ref
  • 1 commit
  • 21 files changed
  • 1 contributor

Commits on Oct 2, 2022

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    4284f55 View commit details
8 changes: 7 additions & 1 deletion .github/workflows/demo.yaml
Original file line number Diff line number Diff line change
@@ -11,6 +11,12 @@ jobs:
steps:
- name: Checkout Git repository
uses: actions/checkout@v2

- name: Install plugin dependencies
run: npm install

- name: Build and link the plugin
run: npm run build && npm link

- name: Build and Deploy
uses: jenkey2011/vuepress-deploy@master
@@ -21,5 +27,5 @@ jobs:
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
CNAME: code-switcher.padarom.xyz
TARGET_BRANCH: gh-pages
BUILD_SCRIPT: cd demo && npm install && npm run build
BUILD_SCRIPT: npm run build --workspace @vuepress-plugin-code-switcher/demo
BUILD_DIR: src/.vuepress/dist
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -2,3 +2,6 @@ node_modules
yarn.lock
package-lock.json
demo/src/.vuepress/dist
demo/src/.vuepress/.cache
demo/src/.vuepress/.temp
lib
3 changes: 0 additions & 3 deletions .npmignore

This file was deleted.

41 changes: 27 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
# vuepress-plugin-code-switcher
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.

_Requires Vuepress 1.0+_
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.

| | Vuepress 1 | Vuepress 2 |
| -- | --- | --- |
| npm | Versions `1.x.x` | Versions `2.x.x` |
| 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) |

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

![](preview.gif)
## Installation
**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).**

```
$ npm install vuepress-plugin-code-switcher --save
$ npm install vuepress-plugin-code-switcher@~2.0 --save
```

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

```js
module.exports = {
```ts
import { codeSwitcherPlugin } from 'vuepress-plugin-code-switcher'

export default {
// Your remaining configuration ...
plugins: [ 'code-switcher' ],
plugins: [ codeSwitcherPlugins(/* your config options go here */) ],
}
```

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

```js
module.exports = {
import { codeSwitcherPlugin } from 'vuepress-plugin-code-switcher'

export default {
// Your remaining configuration ...
plugins: [
[
'code-switcher',
{
groups: {
default: { ts: 'TypeScript', js: 'JavaScript' },
jvm: { java: 'Java', kotlin: 'Kotlin', jruby: 'JRuby' },
},
codeSwitcherPlugins({
groups: {
default: { ts: 'TypeScript', js: 'JavaScript' },
jvm: { java: 'Java', kotlin: 'Kotlin', jruby: 'JRuby' },
},
],

// You can also specify a custom name for the code switcher component.
// If chaning the name like so, you then use the component as <CustomCodeSwitcher>
// in your markdown code
componentName: 'CustomCodeSwitcher',
})
],
}
```
112 changes: 0 additions & 112 deletions components/CodeSwitcher.vue

This file was deleted.

8 changes: 3 additions & 5 deletions demo/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{
"name": "vuepress-plugin-code-switcher-test",
"name": "@vuepress-plugin-code-switcher/demo",
"private": true,
"scripts": {
"dev": "vuepress dev src",
"build": "vuepress build src"
},
"dependencies": {
"vuepress-plugin-code-switcher": "file://.."
},
"devDependencies": {
"vuepress": "^1.5.3"
"vuepress": "^2.0.0-beta.51"
}
}
23 changes: 0 additions & 23 deletions demo/src/.vuepress/config.js

This file was deleted.

24 changes: 24 additions & 0 deletions demo/src/.vuepress/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { defineUserConfig } from 'vuepress'
import { codeSwitcherPlugin } from '../../../lib/node'
import { defaultTheme } from '@vuepress/theme-default'

export default defineUserConfig({
title: 'Code Switcher Vuepress Plugin',

theme: defaultTheme({
repo: 'https://github.com/padarom/vuepress-plugin-code-switcher',
editLink: true,
docsDir: 'demo/src',
lastUpdated: true,
}),

plugins: [
codeSwitcherPlugin({
groups: {
synchronized: { julia: 'Julia', kotlin: 'Kotlin', perl: 'Perl' },
'group-1': { nim: 'Nim', ocaml: 'OCaml' },
'group-2': { nim: 'Nim', ocaml: 'OCaml' },
},
}),
],
})
1 change: 0 additions & 1 deletion enhanceAppFile.js

This file was deleted.

15 changes: 0 additions & 15 deletions index.js

This file was deleted.

32 changes: 29 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "vuepress-plugin-code-switcher",
"version": "2.0.0",
"author": {
"name": "Christopher Mühl",
"email": "christopher@padarom.xyz",
@@ -9,10 +10,35 @@
"type": "git",
"url": "https://github.com/padarom/vuepress-plugin-code-switcher"
},
"version": "1.1.0",
"main": "index.js",
"scripts": {
"build": "tsc -b tsconfig.build.json && cpx \"src/**/*.{d.ts,vue,scss}\" lib",
"dev": "npm run dev --workspace @vuepress-plugin-code-switcher/demo"
},
"workspaces": ["./demo"],
"packageManager": "pnpm@7.11.0",
"type": "module",
"exports": {
".": "./lib/node/index.js",
"./client": "./lib/client/index.js",
"./package.json": "./package.json"
},
"main": "./lib/node/index.ts",
"types": "./lib/node/index.d.ts",
"files": [
"lib"
],
"license": "MIT",
"devDependencies": {
"cpx": "^1.5.0",
"sass": "^1.55.0",
"sass-loader": "^13.0.2",
"typescript": "^4.8.4"
},
"dependencies": {
"@vuepress/plugin-register-components": "^1.8.0"
"@vuepress/client": "^2.0.0-beta.51",
"@vuepress/core": "^2.0.0-beta.51",
"@vuepress/utils": "^2.0.0-beta.51",
"tiny-emitter": "^2.1.0",
"vue": "^3.2.40"
}
}
Loading