11const _get = require ( "lodash/get" )
2+ const _kebabCase = require ( "lodash/kebabCase" )
23const { createRemoteFileNode} = require ( "gatsby-source-filesystem" )
34
45const { getImageUrlParameters} = require ( "./get-image-url-parameters" )
56
6- const GOOGLE_IMAGE_REGEX = / h t t p s : \/ \/ [ a - z 0 - 9 ] * .g o o g l e u s e r c o n t e n t \. c o m \/ [ a - z A - Z 0 - 9 _ - ] * /
7+ const GOOGLE_IMAGE_REGEX =
8+ / ( h t t p s : \/ \/ [ a - z 0 - 9 ] * .g o o g l e u s e r c o n t e n t \. c o m \/ [ a - z A - Z 0 - 9 _ - ] * ) " ( [ ^ ) ] * ) " /
79
810exports . onCreateNodeGoogleDocs = async ( {
911 node,
@@ -47,13 +49,16 @@ exports.onCreateNodeGoogleDocs = async ({
4749 }
4850 }
4951
50- const googleUrls = node . markdown . match (
51- new RegExp ( GOOGLE_IMAGE_REGEX . source , "g" )
52- )
52+ const googleImagesRegex = new RegExp ( GOOGLE_IMAGE_REGEX . source , "g" )
53+ const googleImagesIterator = node . markdown . matchAll ( googleImagesRegex )
54+ const googleImages = [ ... googleImagesIterator ]
5355
54- if ( Array . isArray ( googleUrls ) ) {
56+ if ( Array . isArray ( googleImages ) ) {
5557 const filesNodes = await Promise . all (
56- googleUrls . map ( async ( url ) => {
58+ googleImages . map ( async ( image ) => {
59+ // console.log(image)
60+ const [ , url , title ] = image
61+ console . log ( title )
5762 let fileNode
5863 try {
5964 fileNode = await createRemoteFileNode ( {
@@ -63,7 +68,9 @@ exports.onCreateNodeGoogleDocs = async ({
6368 createNodeId,
6469 cache,
6570 store,
66- name : "google-docs-image-" + createNodeId ( url ) ,
71+ name : title
72+ ? _kebabCase ( title )
73+ : "google-docs-image-" + createNodeId ( url ) ,
6774 reporter,
6875 } )
6976 } catch ( e ) {
0 commit comments