Skip to content
This repository has been archived by the owner on Oct 20, 2024. It is now read-only.

Commit

Permalink
use filter to drop items then mutuate with map
Browse files Browse the repository at this point in the history
  • Loading branch information
nanorepublica committed Jul 30, 2019
1 parent 8f3dbc9 commit 35e7a80
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ AWS.config.update({
const getValidFiles = function(metadata) {
file_keys = ["File_1", "File_2", "File_3", "File_4", "File_5"]
return file_keys.map(key => {
if (metadata[key] != "" && metadata[key].endsWith(".mp3")) {
if (metadata[key] != "" && (metadata[key].endsWith(".mp3") || metadata[key].endsWith(".mpg"))) {
return metadata[key]
}
})
Expand Down Expand Up @@ -133,7 +133,7 @@ module.exports = {
serialize: ({
query: { site, imageSharp, allS3Object, allJson },
}) => {
return allJson.edges.map(({ node }) => {
return allJson.edges.filter(({ node }) => {
S3Obj = allS3Object.edges.filter(s3node => {
var s3node = s3node.node
// get a list of files from the JSON blob
Expand All @@ -144,7 +144,19 @@ module.exports = {
)
return thing[0]
})[0]
if (S3Obj !== undefined) {
return S3Obj !== undefined
}).map(({ node }) => {
S3Obj = allS3Object.edges.filter(s3node => {
var s3node = s3node.node
// get a list of files from the JSON blob
validMediaFiles = getValidFiles(node)
//
var thing = validMediaFiles.filter(file =>
s3node.Key.endsWith(file)
)
return thing[0]
})[0]

var S3ObjNode = S3Obj.node
var s3URL = `https://${S3ObjNode.Name}.s3.amazonaws.com/${S3ObjNode.Key}`
var description = node.Description
Expand Down Expand Up @@ -191,12 +203,12 @@ module.exports = {
}
],
}
}

})
},
query: `
{
allS3Object(filter: {Key: {regex: "/[mp3]$/"}}) {
allS3Object(filter: {Key: {regex: "/[mp3|mpg]$/"}}) {
edges {
node {
Key
Expand Down

0 comments on commit 35e7a80

Please sign in to comment.