@@ -36,48 +36,52 @@ export default function buildContent ({ nuxt, options }) {
3636 const { page, generate, permalink } = content [ dirName ]
3737 const contentPath = join ( sitePath , srcDir )
3838
39- if ( ! generate ) return
40-
41- const db = createDatabase ( contentPath , dirName , options )
42-
43- generate . forEach ( reqType => {
44- const req = { }
45- if ( typeof reqType === 'string' ) {
46- req [ 'method' ] = reqType
47- } else if ( Array . isArray ( reqType ) ) {
48- const [ reqMethod , reqOptions ] = reqType
49- req [ 'method' ] = reqMethod
50- req [ 'query' ] = reqOptions . query ? reqOptions . query : { }
51- req [ 'args' ] = reqOptions . args ? reqOptions . args : [ ]
52- }
39+ let name
40+ if ( page ) {
41+ name = routeName ( page )
42+ routePaths . set ( name , permalink . replace ( / ^ \/ / , '' ) )
43+ }
5344
54- switch ( req [ 'method' ] ) {
55- case 'get' :
56- if ( ! page ) throw new Error ( 'You must specify a page path' )
57- const name = routeName ( page )
58- const pathPrefix = getPrefix ( name )
59- routePaths . set ( name , permalink . replace ( / ^ \/ / , '' ) )
60- db . findAll ( req [ 'query' ] ) . forEach ( ( page ) => {
61- routePages . push ( join ( pathPrefix , page . permalink ) )
62- assetMap . set ( buildPath ( page . permalink , dirName , options ) , page )
63- } )
64- break
65- case 'getAll' :
66- assetMap . set (
67- buildPath ( '_all' , dirName , options ) ,
68- db . findAll ( req [ 'query' ] )
69- )
70- break
71- case 'getOnly' :
72- assetMap . set (
73- buildPath ( '_only' , dirName , options ) ,
74- db . findOnly ( req [ 'args' ] , req [ 'query' ] )
75- )
76- break
77- default :
78- throw new Error ( `The ${ req [ 'method' ] } is not supported for static builds.` )
79- }
80- } )
45+ if ( generate ) {
46+ const db = createDatabase ( contentPath , dirName , options )
47+
48+ generate . forEach ( reqType => {
49+ const req = { }
50+ if ( typeof reqType === 'string' ) {
51+ req [ 'method' ] = reqType
52+ } else if ( Array . isArray ( reqType ) ) {
53+ const [ reqMethod , reqOptions ] = reqType
54+ req [ 'method' ] = reqMethod
55+ req [ 'query' ] = reqOptions . query ? reqOptions . query : { }
56+ req [ 'args' ] = reqOptions . args ? reqOptions . args : [ ]
57+ }
58+
59+ switch ( req [ 'method' ] ) {
60+ case 'get' :
61+ if ( ! page ) throw new Error ( 'You must specify a page path' )
62+ const pathPrefix = getPrefix ( name )
63+ db . findAll ( req [ 'query' ] ) . forEach ( ( page ) => {
64+ routePages . push ( join ( pathPrefix , page . permalink ) )
65+ assetMap . set ( buildPath ( page . permalink , dirName , options ) , page )
66+ } )
67+ break
68+ case 'getAll' :
69+ assetMap . set (
70+ buildPath ( '_all' , dirName , options ) ,
71+ db . findAll ( req [ 'query' ] )
72+ )
73+ break
74+ case 'getOnly' :
75+ assetMap . set (
76+ buildPath ( '_only' , dirName , options ) ,
77+ db . findOnly ( req [ 'args' ] , req [ 'query' ] )
78+ )
79+ break
80+ default :
81+ throw new Error ( `The ${ req [ 'method' ] } is not supported for static builds.` )
82+ }
83+ } )
84+ }
8185 } )
8286
8387 interceptRoutes ( nuxt , routePaths )
0 commit comments