Skip to content

Commit

Permalink
Revert "Support filename that contains non-ASCII and unicode chars (#473
Browse files Browse the repository at this point in the history
)"

This reverts commit 95a3548.
  • Loading branch information
ulivz authored May 24, 2018
1 parent 95a3548 commit 5fd9a7f
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 36 deletions.
2 changes: 0 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ footer: MIT Licensed | Copyright © 2018-present Evan You

### As Easy as 1, 2, 3

- [](./尤.md)

``` bash
# install
yarn global add vuepress # OR npm install -g vuepress
Expand Down
3 changes: 0 additions & 3 deletions docs/尤.md

This file was deleted.

3 changes: 0 additions & 3 deletions docs/溪.md

This file was deleted.

3 changes: 0 additions & 3 deletions docs/雨.md

This file was deleted.

4 changes: 3 additions & 1 deletion lib/app/Content.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { pathToComponentName } from './util'

export default {
functional: true,

Expand All @@ -9,7 +11,7 @@ export default {
},

render (h, { parent, props, data }) {
return h(parent.$page.key, {
return h(pathToComponentName(parent.$page.path), {
class: [props.custom ? 'custom' : '', data.class, data.staticClass],
style: data.style
})
Expand Down
8 changes: 8 additions & 0 deletions lib/app/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ export function injectMixins (options, mixins) {
options.mixins.push(...mixins)
}

export function pathToComponentName (path) {
if (path.charAt(path.length - 1) === '/') {
return `page${path.replace(/\//g, '-') + 'index'}`
} else {
return `page${path.replace(/\//g, '-').replace(/\.html$/, '')}`
}
}

export function findPageForPath (pages, path) {
for (let i = 0; i < pages.length; i++) {
const page = pages[i]
Expand Down
2 changes: 1 addition & 1 deletion lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
console.error(chalk.red(`Error rendering ${pagePath}:`))
throw e
}
const filename = decodeURIComponent(pagePath.replace(/\/$/, '/index.html').replace(/^\//, ''))
const filename = pagePath.replace(/\/$/, '/index.html').replace(/^\//, '')
const filePath = path.resolve(outDir, filename)
await fs.ensureDir(path.dirname(filePath))
await fs.writeFile(filePath, html)
Expand Down
5 changes: 2 additions & 3 deletions lib/default-theme/Layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import Home from './Home.vue'
import Navbar from './Navbar.vue'
import Page from './Page.vue'
import Sidebar from './Sidebar.vue'
import { pathToComponentName } from '@app/util'
import { resolveSidebarItems } from './util'
export default {
Expand Down Expand Up @@ -85,13 +86,11 @@ export default {
},
mounted () {
window.addEventListener('scroll', this.onScroll)
// configure progress bar
nprogress.configure({ showSpinner: false })
this.$router.beforeEach((to, from, next) => {
if (to.path !== from.path && !Vue.component(to.name)) {
if (to.path !== from.path && !Vue.component(pathToComponentName(to.path))) {
nprogress.start()
}
next()
Expand Down
19 changes: 3 additions & 16 deletions lib/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const createMarkdown = require('./markdown')
const loadConfig = require('./util/loadConfig')
const tempPath = path.resolve(__dirname, 'app/.temp')
const {
encodePath,
inferTitle,
extractHeaders,
parseFrontmatter,
Expand Down Expand Up @@ -182,10 +181,8 @@ async function resolveOptions (sourceDir) {
// resolve pagesData
const pagesData = await Promise.all(pageFiles.map(async (file) => {
const filepath = path.resolve(sourceDir, file)
const key = 'v-' + Math.random().toString(16).slice(2)
const data = {
key,
path: encodePath(fileToPath(file))
path: fileToPath(file)
}

if (shouldResolveLastUpdated) {
Expand Down Expand Up @@ -299,31 +296,21 @@ async function resolveComponents (sourceDir) {
}

async function genRoutesFile ({ siteData: { pages }, sourceDir, pageFiles }) {
function genRoute ({ path: pagePath, key: componentName }, index) {
function genRoute ({ path: pagePath }, index) {
const file = pageFiles[index]
const filePath = path.resolve(sourceDir, file)
let code = `
{
name: ${JSON.stringify(componentName)},
path: ${JSON.stringify(pagePath)},
component: ThemeLayout,
beforeEnter: (to, from, next) => {
import(${JSON.stringify(filePath)}).then(comp => {
Vue.component(${JSON.stringify(componentName)}, comp.default)
Vue.component(${JSON.stringify(fileToComponentName(file))}, comp.default)
next()
})
}
}`

const dncodedPath = decodeURIComponent(pagePath)
if (dncodedPath !== pagePath) {
code += `,
{
path: ${JSON.stringify(dncodedPath)},
redirect: ${JSON.stringify(pagePath)}
}`
}

if (/\/$/.test(pagePath)) {
code += `,
{
Expand Down
4 changes: 0 additions & 4 deletions lib/util/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const spawn = require('cross-spawn')
const parseHeaders = require('./parseHeaders')

exports.encodePath = function (path) {
return path.split('/').map(item => encodeURIComponent(item)).join('/')
}

exports.parseHeaders = parseHeaders

exports.normalizeHeadTag = tag => {
Expand Down

0 comments on commit 5fd9a7f

Please sign in to comment.