refactor: don't hardcode language names

pull/875/head
Divyansh Singh 3 years ago
parent 29d44e7a22
commit dd1067815e

@ -27,7 +27,7 @@ You will need [pnpm](https://pnpm.io)
After cloning the repo, run:
```bash
```sh
# install the dependencies of the project
$ pnpm install
```
@ -36,7 +36,7 @@ $ pnpm install
At first, execute the `pnpm run build` command.
```bash
```sh
$ pnpm run build
```
@ -44,7 +44,7 @@ You only need to do this once for your fresh project. It copies required files a
The easiest way to start testing out VitePress is to tweak the VitePress docs. You may run `pnpm run docs` to boot up VitePress documentation site locally, with live reloading of the source code.
```bash
```sh
$ pnpm run docs
```
@ -52,6 +52,6 @@ After executing the above command, visit http://localhost:3000 and try modifying
If you don't need docs site up and running, you may start VitePress local dev environment with `pnpm run dev`.
```bash
```sh
$ pnpm run dev
```

@ -1,6 +1,5 @@
/docs
/examples
*.css
*.md
*.vue
dist

@ -19,7 +19,7 @@ The following guides are based on some shared assumptions:
You may run `yarn docs:build` command to build the docs.
```bash
```sh
$ yarn docs:build
```
@ -27,7 +27,7 @@ By default, the build output will be placed at `.vitepress/dist`. You may deploy
Once you've built the docs, you may test them locally by running `yarn docs:serve` command.
```bash
```sh
$ yarn docs:build
$ yarn docs:serve
```
@ -56,7 +56,7 @@ Now the `docs:serve` method will launch the server at `http://localhost:8080`.
2. Inside your project, create `deploy.sh` with the following content (with highlighted lines uncommented appropriately), and run it to deploy:
```bash{13,20,23}
```sh{13,20,23}
#!/usr/bin/env sh
# abort on errors
@ -206,7 +206,7 @@ You can also deploy to a [custom domain](https://surge.sh/help/adding-a-custom-d
3. Run `heroku login` and fill in your Heroku credentials:
```bash
```sh
$ heroku login
```
@ -224,7 +224,7 @@ This is the configuration of your site; read more at [heroku-buildpack-static](h
5. Set up your Heroku git remote:
```bash
```sh
# version change
$ git init
$ git add .
@ -239,7 +239,7 @@ $ heroku buildpacks:set https://github.com/heroku/heroku-buildpack-static.git
6. Deploy your site:
```bash
```sh
# publish site
$ git push heroku main

@ -10,13 +10,13 @@ VitePress is currently in `alpha` status. It is already suitable for out-of-the-
Create and change into a new directory.
```bash
```sh
$ mkdir vitepress-starter && cd vitepress-starter
```
Then, initialize with your preferred package manager.
```bash
```sh
$ yarn init
```
@ -24,13 +24,13 @@ $ yarn init
Add VitePress and Vue as dev dependencies for the project.
```bash
```sh
$ yarn add --dev vitepress vue
```
Create your first document.
```bash
```sh
$ mkdir docs && echo '# Hello VitePress' > docs/index.md
```
@ -52,7 +52,7 @@ Add some scripts to `package.json`.
Serve the documentation site in the local server.
```bash
```sh
$ yarn docs:dev
```

@ -11,7 +11,7 @@ export function useCopyCode() {
nextTick(() => {
document
.querySelectorAll<HTMLSpanElement>(
'.vp-doc div[class*="language-"]>span.copy'
'.vp-doc div[class*="language-"] > span.copy'
)
.forEach(handleElement)
})
@ -67,16 +67,16 @@ async function copyToClipboard(text: string) {
function handleElement(el: HTMLElement) {
el.onclick = () => {
const parent = el.parentElement
if (!parent) {
const sibling = el.nextElementSibling as HTMLPreElement | null
if (!parent || !sibling) {
return
}
const isShell =
parent.classList.contains('language-sh') ||
parent.classList.contains('language-bash')
const isShell = /language-(shellscript|shell|bash|sh|zsh)/.test(
parent.classList.toString()
)
let { innerText: text = '' } = parent
let { innerText: text = '' } = sibling
if (isShell) {
text = text.replace(/^ *\$ /gm, '')

@ -75,7 +75,7 @@ b {
a,
area,
button,
[role="button"],
[role='button'],
input,
label,
select,
@ -142,13 +142,13 @@ textarea {
button {
padding: 0;
font-family: inherit;;
font-family: inherit;
background-color: transparent;
background-image: none;
}
button,
[role="button"] {
[role='button'] {
cursor: pointer;
}
@ -197,7 +197,7 @@ input::-webkit-inner-spin-button {
margin: 0;
}
input[type="number"] {
input[type='number'] {
-moz-appearance: textfield;
}

@ -203,7 +203,7 @@
color: inherit;
font-weight: 600;
text-decoration: underline;
transition: opacity .25s;
transition: opacity 0.25s;
}
.vp-doc .custom-block a:hover {
@ -381,7 +381,7 @@
background-position: 50%;
background-size: 20px;
background-repeat: no-repeat;
transition: opacity 0.25s;
transition: opacity 0.4s;
}
.vp-doc [class*='language-']:hover > span.copy {
@ -414,10 +414,10 @@
color: var(--vp-code-copy-code-active-text);
background-color: var(--vp-code-copy-code-hover-bg);
white-space: nowrap;
content: "Copied";
content: 'Copied';
}
.vp-doc [class*='language-']:before {
.vp-doc [class*='language-'] > span.lang {
position: absolute;
top: 6px;
right: 12px;
@ -425,43 +425,13 @@
font-size: 12px;
font-weight: 500;
color: var(--vp-c-text-dark-3);
transition: color 0.5s, opacity 0.5s;
transition: color 0.4s, opacity 0.4s;
}
.vp-doc [class*='language-']:hover:before {
.vp-doc [class*='language-']:hover > span.lang {
opacity: 0;
}
.vp-doc [class~='language-c']:before { content: 'c'; }
.vp-doc [class~='language-css']:before { content: 'css'; }
.vp-doc [class~='language-go']:before { content: 'go'; }
.vp-doc [class~='language-html']:before { content: 'html'; }
.vp-doc [class~='language-java']:before { content: 'java'; }
.vp-doc [class~='language-javascript']:before { content: 'js'; }
.vp-doc [class~='language-js']:before { content: 'js'; }
.vp-doc [class~='language-json']:before { content: 'json'; }
.vp-doc [class~='language-jsx']:before { content: 'jsx'; }
.vp-doc [class~='language-less']:before { content: 'less'; }
.vp-doc [class~='language-markdown']:before { content: 'md'; }
.vp-doc [class~='language-md']:before { content: 'md' }
.vp-doc [class~='language-php']:before { content: 'php'; }
.vp-doc [class~='language-python']:before { content: 'py'; }
.vp-doc [class~='language-py']:before { content: 'py'; }
.vp-doc [class~='language-rb']:before { content: 'rb'; }
.vp-doc [class~='language-ruby']:before { content: 'rb'; }
.vp-doc [class~='language-rust']:before { content: 'rust'; }
.vp-doc [class~='language-sass']:before { content: 'sass'; }
.vp-doc [class~='language-scss']:before { content: 'scss'; }
.vp-doc [class~='language-sh']:before { content: 'sh'; }
.vp-doc [class~='language-bash']:before { content: 'sh'; }
.vp-doc [class~='language-stylus']:before { content: 'styl'; }
.vp-doc [class~='language-vue-html']:before { content: 'template'; }
.vp-doc [class~='language-typescript']:before { content: 'ts'; }
.vp-doc [class~='language-ts']:before { content: 'ts'; }
.vp-doc [class~='language-tsx']:before { content: 'tsx'; }
.vp-doc [class~='language-vue']:before { content: 'vue'; }
.vp-doc [class~='language-yaml']:before { content: 'yaml'; }
/**
* Component: Team
* -------------------------------------------------------------------------- */

@ -46,38 +46,63 @@
gap: 4px;
}
.vp-sponsor-grid.xmini .vp-sponsor-grid-link { height: 64px; }
.vp-sponsor-grid.xmini .vp-sponsor-grid-image { max-width: 64px; max-height: 22px }
.vp-sponsor-grid.xmini .vp-sponsor-grid-link {
height: 64px;
}
.vp-sponsor-grid.xmini .vp-sponsor-grid-image {
max-width: 64px;
max-height: 22px;
}
.vp-sponsor-grid.mini .vp-sponsor-grid-link { height: 72px; }
.vp-sponsor-grid.mini .vp-sponsor-grid-image { max-width: 96px; max-height: 24px }
.vp-sponsor-grid.mini .vp-sponsor-grid-link {
height: 72px;
}
.vp-sponsor-grid.mini .vp-sponsor-grid-image {
max-width: 96px;
max-height: 24px;
}
.vp-sponsor-grid.small .vp-sponsor-grid-link { height: 96px; }
.vp-sponsor-grid.small .vp-sponsor-grid-image { max-width: 96px; max-height: 24px }
.vp-sponsor-grid.small .vp-sponsor-grid-link {
height: 96px;
}
.vp-sponsor-grid.small .vp-sponsor-grid-image {
max-width: 96px;
max-height: 24px;
}
.vp-sponsor-grid.medium .vp-sponsor-grid-link { height: 112px; }
.vp-sponsor-grid.medium .vp-sponsor-grid-image { max-width: 120px; max-height: 36px }
.vp-sponsor-grid.medium .vp-sponsor-grid-link {
height: 112px;
}
.vp-sponsor-grid.medium .vp-sponsor-grid-image {
max-width: 120px;
max-height: 36px;
}
.vp-sponsor-grid.big .vp-sponsor-grid-link { height: 184px; }
.vp-sponsor-grid.big .vp-sponsor-grid-image { max-width: 192px; max-height: 56px }
.vp-sponsor-grid.big .vp-sponsor-grid-link {
height: 184px;
}
.vp-sponsor-grid.big .vp-sponsor-grid-image {
max-width: 192px;
max-height: 56px;
}
.vp-sponsor-grid[data-vp-grid="2"] .vp-sponsor-grid-item {
.vp-sponsor-grid[data-vp-grid='2'] .vp-sponsor-grid-item {
width: calc((100% - 4px) / 2);
}
.vp-sponsor-grid[data-vp-grid="3"] .vp-sponsor-grid-item {
.vp-sponsor-grid[data-vp-grid='3'] .vp-sponsor-grid-item {
width: calc((100% - 4px * 2) / 3);
}
.vp-sponsor-grid[data-vp-grid="4"] .vp-sponsor-grid-item {
.vp-sponsor-grid[data-vp-grid='4'] .vp-sponsor-grid-item {
width: calc((100% - 4px * 3) / 4);
}
.vp-sponsor-grid[data-vp-grid="5"] .vp-sponsor-grid-item {
.vp-sponsor-grid[data-vp-grid='5'] .vp-sponsor-grid-item {
width: calc((100% - 4px * 4) / 5);
}
.vp-sponsor-grid[data-vp-grid="6"] .vp-sponsor-grid-item {
.vp-sponsor-grid[data-vp-grid='6'] .vp-sponsor-grid-item {
width: calc((100% - 4px * 5) / 6);
}

@ -34,12 +34,12 @@
--vp-c-divider-dark-2: rgba(84, 84, 84, 0.48);
--vp-c-text-light-1: var(--vp-c-indigo);
--vp-c-text-light-2: rgba(60, 60, 60, 0.70);
--vp-c-text-light-2: rgba(60, 60, 60, 0.7);
--vp-c-text-light-3: rgba(60, 60, 60, 0.33);
--vp-c-text-light-4: rgba(60, 60, 60, 0.18);
--vp-c-text-dark-1: rgba(255, 255, 255, 0.87);
--vp-c-text-dark-2: rgba(235, 235, 235, 0.60);
--vp-c-text-dark-2: rgba(235, 235, 235, 0.6);
--vp-c-text-dark-3: rgba(235, 235, 235, 0.38);
--vp-c-text-dark-4: rgba(235, 235, 235, 0.18);
@ -180,8 +180,8 @@
* -------------------------------------------------------------------------- */
:root {
--vp-icon-copy: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' height='20' width='20' stroke='rgba(128,128,128,1)' stroke-width='2' class='h-6 w-6' viewBox='0 0 24 24'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2'/%3E%3C/svg%3E");
--vp-icon-copied: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' height='20' width='20' stroke='rgba(128,128,128,1)' stroke-width='2' class='h-6 w-6' viewBox='0 0 24 24'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2m-6 9 2 2 4-4'/%3E%3C/svg%3E");
--vp-icon-copy: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' height='20' width='20' stroke='rgba(128,128,128,1)' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2'/%3E%3C/svg%3E");
--vp-icon-copied: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' height='20' width='20' stroke='rgba(128,128,128,1)' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2m-6 9 2 2 4-4'/%3E%3C/svg%3E");
}
/**

@ -13,8 +13,10 @@ export const preWrapperPlugin = (md: MarkdownIt) => {
const fence = md.renderer.rules.fence!
md.renderer.rules.fence = (...args) => {
const [tokens, idx] = args
const token = tokens[idx]
const lang = tokens[idx].info.trim()
const rawCode = fence(...args)
return `<div class="language-${token.info.trim()}"><span class="copy"></span>${rawCode}</div>`
return `<div class="language-${lang}"><span class="lang">${
lang === 'vue-html' ? 'template' : lang
}</span><span class="copy"></span>${rawCode}</div>`
}
}

Loading…
Cancel
Save