Skip to content

Commit 5ac2021

Browse files
committed
fixed incompatability with nodejs 'join' method on Windows with regex FIXES nuxt-community#94 nuxt-community#109 and fixed content navigation by making sure regex is parsing content body FIXES nuxt-community#111
1 parent dcc06ae commit 5ac2021

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

examples/content-navigation/nuxt.config.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const nuxtent = require('../../dist/module').default
2+
13
module.exports = {
24
head: {
35
title: 'starter',
@@ -7,5 +9,5 @@ module.exports = {
79
{ hid: 'description', name: 'description', content: 'Nuxt.js project' }
810
]
911
},
10-
modules: ['nuxtent']
12+
modules: [nuxtent]
1113
}

lib/content/api.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const curryResponseHandler = (
4141

4242
return function sendContent(req, res) {
4343
const send = response(res)
44-
const permalink = req.params['0']
44+
const permalink = req.params['0'].replace(/\\|\/\//, '/')
4545
// eslint-disable-next-line no-unused-vars
4646
const [_, queryStr] = req.url.match(/\?(.*)/) || []
4747
const { only, between, ...query } = parse(queryStr)

lib/content/page.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export default function prepPage(meta, options, isDev) {
7373
const nestedPath = /([^_][a-zA-z]*?)\/[^a-z_]*/
7474
const matchedPath = options.page.match(nestedPath)
7575
if (matchedPath && matchedPath[1] !== 'index') {
76-
cached.path = join(matchedPath[1], permalink)
76+
cached.path = matchedPath[1] + permalink
7777
} else {
7878
cached.path = permalink
7979
}
@@ -89,10 +89,8 @@ export default function prepPage(meta, options, isDev) {
8989
const { year, month, day } = splitDate(date)
9090
const params = { section, slug, date, year, month, day }
9191
const toPermalink = permalinkCompiler(options.permalink)
92-
cached.permalink = join(
93-
'/',
94-
toPermalink(params, { pretty: true }).replace(/%2F/gi, '/')
95-
) // make url encoded slash pretty
92+
cached.permalink =
93+
'/' + toPermalink(params, { pretty: true }).replace(/%2F/gi, '/') // make url encoded slash pretty
9694
}
9795
return cached.permalink
9896
},
@@ -114,7 +112,7 @@ export default function prepPage(meta, options, isDev) {
114112

115113
let result
116114
const anchors = []
117-
while ((result = anchorsExp.exec(_rawData))) {
115+
while ((result = anchorsExp.exec(_rawData.body))) {
118116
// eslint-disable-next-line no-unused-vars
119117
const [match, codeSnippet, otherHeading, headingText] = result
120118
if (!(codeSnippet || otherHeading) && headingText) {
@@ -141,7 +139,8 @@ export default function prepPage(meta, options, isDev) {
141139
const { parsers } = options
142140
const { dirName, section, fileName } = meta
143141
if (fileName.search(/\.comp\.md$/) > -1) {
144-
const relativePath = '.' + join(dirName, section, fileName)
142+
const relativePath =
143+
'.' + join(dirName, section, fileName).replace(/\\/, '/') // normalize windows path
145144
cached.body = {
146145
relativePath // component body compiled by loader and imported separately
147146
}

lib/loader.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ const getDirOpts = (contentOptions, section) => {
1313
return contentOptions['/'] ? contentOptions['/'] : contentOptions[section]
1414
}
1515

16-
const getSection = path => {
16+
const getSection = dirPath => {
1717
// capture '/content/closestSubsection' or '/content'
1818
// eslint-disable-next-line no-unused-vars
19-
const [match, section] = path.match(/\/content([/][a-zA-Z\-_]*|$)/)
19+
const [match, section] = dirPath.match(/[/\\]content([/\\][a-zA-Z\-_]*|$)/)
2020
return section === '' ? '/' : section
2121
}
2222

0 commit comments

Comments
 (0)