1- require ( ' es6-promise' ) . polyfill ( ) ;
2- require ( ' isomorphic-fetch' ) ;
1+ require ( " es6-promise" ) . polyfill ( )
2+ require ( " isomorphic-fetch" )
33
44exports . sourceNodes = async (
55 {
@@ -19,36 +19,40 @@ exports.sourceNodes = async (
1919) => {
2020 const {
2121 baseUrl,
22- apiBase = ' jsonapi' ,
22+ apiBase = " jsonapi" ,
2323 basicAuth,
2424 headers,
2525 menus,
2626 } = pluginOptions
27- const { createNode, createParentChildLink} = actions
27+ const { createNode, createParentChildLink } = actions
2828
2929 reporter . info ( `Starting to fetch menu link items from Drupal` )
30- reporter . info ( ' Menus to fetch are ' + menus . join ( ', ' ) )
30+ reporter . info ( " Menus to fetch are " + menus . join ( ", " ) )
3131
3232 // Data can come from anywhere, but for now create it manually
33- const menuResponses = await Promise . all ( menus . map ( async menu => {
34- return await fetch ( `${ baseUrl } /${ apiBase } /menu_items/${ menu } ` , {
35- auth : basicAuth ,
36- headers
37- } ) . then ( function ( response ) {
38- if ( response . status >= 400 ) {
39- reporter . error ( `Bad response from ${ baseUrl } /${ apiBase } /menu_items/${ menu } ` ) ;
40- }
41- return response . json ( ) ;
33+ const menuResponses = await Promise . all (
34+ menus . map ( async ( menu ) => {
35+ return await fetch ( `${ baseUrl } /${ apiBase } /menu_items/${ menu } ` , {
36+ auth : basicAuth ,
37+ headers,
38+ } ) . then ( function ( response ) {
39+ if ( response . status >= 400 ) {
40+ reporter . error (
41+ `Bad response from ${ baseUrl } /${ apiBase } /menu_items/${ menu } `
42+ )
43+ }
44+ return response . json ( )
45+ } )
4246 } )
43- } ) ) ;
44- menuResponses . forEach ( ( { data : menuItems } ) => {
45- const map = new Map ( ) ;
47+ )
48+ menuResponses . forEach ( ( { data : menuItems } ) => {
49+ const map = new Map ( )
4650 menuItems . forEach ( ( item ) => {
47- const nodeContent = JSON . stringify ( item ) ;
48- const id = `menu-items-${ item . id } ` ;
49- let parentId = null ;
51+ const nodeContent = JSON . stringify ( item )
52+ const id = `menu-items-${ item . id } `
53+ let parentId = null
5054 if ( item . attributes . parent ) {
51- parentId = `menu-items-${ item . attributes . parent } ` ;
55+ parentId = `menu-items-${ item . attributes . parent } `
5256 }
5357 const nodeMeta = {
5458 id,
@@ -58,17 +62,15 @@ exports.sourceNodes = async (
5862 type : `MenuItems` ,
5963 mediaType : `text/html` ,
6064 content : nodeContent ,
61- contentDigest : createContentDigest ( item )
62- }
63- } ;
64- const node = Object . assign ( { } , item . attributes , nodeMeta ) ;
65- createNode ( node ) ;
65+ contentDigest : createContentDigest ( item ) ,
66+ } ,
67+ }
68+ const node = Object . assign ( { } , item . attributes , nodeMeta )
69+ createNode ( node )
6670 if ( parentId && map . has ( parentId ) ) {
67- createParentChildLink ( { parent : map . get ( parentId ) , child : node } )
71+ createParentChildLink ( { parent : map . get ( parentId ) , child : node } )
6872 }
6973 map . set ( id , node )
7074 } )
71- } ) ;
72-
75+ } )
7376}
74-
0 commit comments