Skip to content

Commit 5fd9a7f

Browse files
authored
Revert "Support filename that contains non-ASCII and unicode chars (#473)"
This reverts commit 95a3548.
1 parent 95a3548 commit 5fd9a7f

File tree

10 files changed

+17
-36
lines changed

10 files changed

+17
-36
lines changed

docs/README.md

-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ footer: MIT Licensed | Copyright © 2018-present Evan You
1515

1616
### As Easy as 1, 2, 3
1717

18-
- [](./尤.md)
19-
2018
``` bash
2119
# install
2220
yarn global add vuepress # OR npm install -g vuepress

docs/尤.md

-3
This file was deleted.

docs/溪.md

-3
This file was deleted.

docs/雨.md

-3
This file was deleted.

lib/app/Content.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { pathToComponentName } from './util'
2+
13
export default {
24
functional: true,
35

@@ -9,7 +11,7 @@ export default {
911
},
1012

1113
render (h, { parent, props, data }) {
12-
return h(parent.$page.key, {
14+
return h(pathToComponentName(parent.$page.path), {
1315
class: [props.custom ? 'custom' : '', data.class, data.staticClass],
1416
style: data.style
1517
})

lib/app/util.js

+8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ export function injectMixins (options, mixins) {
55
options.mixins.push(...mixins)
66
}
77

8+
export function pathToComponentName (path) {
9+
if (path.charAt(path.length - 1) === '/') {
10+
return `page${path.replace(/\//g, '-') + 'index'}`
11+
} else {
12+
return `page${path.replace(/\//g, '-').replace(/\.html$/, '')}`
13+
}
14+
}
15+
816
export function findPageForPath (pages, path) {
917
for (let i = 0; i < pages.length; i++) {
1018
const page = pages[i]

lib/build.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
153153
console.error(chalk.red(`Error rendering ${pagePath}:`))
154154
throw e
155155
}
156-
const filename = decodeURIComponent(pagePath.replace(/\/$/, '/index.html').replace(/^\//, ''))
156+
const filename = pagePath.replace(/\/$/, '/index.html').replace(/^\//, '')
157157
const filePath = path.resolve(outDir, filename)
158158
await fs.ensureDir(path.dirname(filePath))
159159
await fs.writeFile(filePath, html)

lib/default-theme/Layout.vue

+2-3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import Home from './Home.vue'
2727
import Navbar from './Navbar.vue'
2828
import Page from './Page.vue'
2929
import Sidebar from './Sidebar.vue'
30+
import { pathToComponentName } from '@app/util'
3031
import { resolveSidebarItems } from './util'
3132
3233
export default {
@@ -85,13 +86,11 @@ export default {
8586
},
8687
8788
mounted () {
88-
window.addEventListener('scroll', this.onScroll)
89-
9089
// configure progress bar
9190
nprogress.configure({ showSpinner: false })
9291
9392
this.$router.beforeEach((to, from, next) => {
94-
if (to.path !== from.path && !Vue.component(to.name)) {
93+
if (to.path !== from.path && !Vue.component(pathToComponentName(to.path))) {
9594
nprogress.start()
9695
}
9796
next()

lib/prepare.js

+3-16
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const createMarkdown = require('./markdown')
55
const loadConfig = require('./util/loadConfig')
66
const tempPath = path.resolve(__dirname, 'app/.temp')
77
const {
8-
encodePath,
98
inferTitle,
109
extractHeaders,
1110
parseFrontmatter,
@@ -182,10 +181,8 @@ async function resolveOptions (sourceDir) {
182181
// resolve pagesData
183182
const pagesData = await Promise.all(pageFiles.map(async (file) => {
184183
const filepath = path.resolve(sourceDir, file)
185-
const key = 'v-' + Math.random().toString(16).slice(2)
186184
const data = {
187-
key,
188-
path: encodePath(fileToPath(file))
185+
path: fileToPath(file)
189186
}
190187

191188
if (shouldResolveLastUpdated) {
@@ -299,31 +296,21 @@ async function resolveComponents (sourceDir) {
299296
}
300297

301298
async function genRoutesFile ({ siteData: { pages }, sourceDir, pageFiles }) {
302-
function genRoute ({ path: pagePath, key: componentName }, index) {
299+
function genRoute ({ path: pagePath }, index) {
303300
const file = pageFiles[index]
304301
const filePath = path.resolve(sourceDir, file)
305302
let code = `
306303
{
307-
name: ${JSON.stringify(componentName)},
308304
path: ${JSON.stringify(pagePath)},
309305
component: ThemeLayout,
310306
beforeEnter: (to, from, next) => {
311307
import(${JSON.stringify(filePath)}).then(comp => {
312-
Vue.component(${JSON.stringify(componentName)}, comp.default)
308+
Vue.component(${JSON.stringify(fileToComponentName(file))}, comp.default)
313309
next()
314310
})
315311
}
316312
}`
317313

318-
const dncodedPath = decodeURIComponent(pagePath)
319-
if (dncodedPath !== pagePath) {
320-
code += `,
321-
{
322-
path: ${JSON.stringify(dncodedPath)},
323-
redirect: ${JSON.stringify(pagePath)}
324-
}`
325-
}
326-
327314
if (/\/$/.test(pagePath)) {
328315
code += `,
329316
{

lib/util/index.js

-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
const spawn = require('cross-spawn')
22
const parseHeaders = require('./parseHeaders')
33

4-
exports.encodePath = function (path) {
5-
return path.split('/').map(item => encodeURIComponent(item)).join('/')
6-
}
7-
84
exports.parseHeaders = parseHeaders
95

106
exports.normalizeHeadTag = tag => {

0 commit comments

Comments
 (0)