-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
173 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Getting Started | ||
|
||
## Quickstart | ||
|
||
``` bash | ||
# install globally | ||
npm install -g vuepress | ||
|
||
# create a markdown file | ||
echo "# Hello VuePress!" > index.md | ||
|
||
# start writing | ||
vuepress dev . | ||
|
||
# build | ||
vuepress build . | ||
``` | ||
|
||
## Inside an Existing Project | ||
|
||
``` bash | ||
# install as a dependency | ||
npm install -D vuepress | ||
|
||
# create a docs directory | ||
mkdir docs | ||
# create a markdown file | ||
echo "# Hello VuePress!" > docs/index.md | ||
|
||
# start writing | ||
npx vuepress dev docs | ||
``` | ||
|
||
Or, add some scripts to `package.json`: | ||
|
||
``` json | ||
{ | ||
"scripts": { | ||
"docs:dev": "vuepress dev docs", | ||
"docs:build": "vuepress build docs" | ||
} | ||
} | ||
``` | ||
|
||
Then you can start writing with: | ||
|
||
``` bash | ||
npm run docs:dev | ||
``` | ||
|
||
To generate static assets, run: | ||
|
||
``` bash | ||
npm run docs:build | ||
``` | ||
|
||
By default the built files will be in `.vuepress/dist`. The files can be deployed to any static file server. See [Deployment Guide](./deploy.md) for guides on deploying to popular services. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
export default function resolveSidebar (route, site) { | ||
const { pages, themeConfig } = site | ||
const sidebarConfig = themeConfig.sidebar | ||
if (!sidebarConfig) { | ||
return pages | ||
} else { | ||
const matchingConfig = Array.isArray(sidebarConfig) | ||
? sidebarConfig | ||
: resolveMatchingSidebar(route, sidebarConfig) | ||
return matchingConfig.map(item => resolveItem(item, site.pages)) | ||
} | ||
} | ||
|
||
function resolveMatchingSidebar (route, sidebarConfig) { | ||
for (const base in sidebarConfig) { | ||
if (ensureEndingSlash(route.path).indexOf(base) === 0) { | ||
return sidebarConfig[base] | ||
} | ||
} | ||
} | ||
|
||
function ensureEndingSlash (path) { | ||
return /(\.html|\/)$/.test(path) | ||
? path | ||
: path + '/' | ||
} | ||
|
||
function resolveItem (item, pages) { | ||
if (typeof item === 'string') { | ||
return Object.assign({ type: 'page' }, findPage(pages, item)) | ||
} else if (Array.isArray(item)) { | ||
return { | ||
type: 'heading', | ||
title: item[0], | ||
children: (item[1] || []).map(child => resolveItem(child, pages)) | ||
} | ||
} else { | ||
throw new Error(`Invalid sidebar item config: ${item}`) | ||
} | ||
} | ||
|
||
function findPage (pages, path) { | ||
path = normalize(path) | ||
for (let i = 0; i < pages.length; i++) { | ||
if (normalize(pages[i].path) === path) { | ||
return pages[i] | ||
} | ||
} | ||
} | ||
|
||
function normalize (path) { | ||
return path.replace(/\.(md|html)$/, '') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters