Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changes/fix-airtable-filenames.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"gatsby-source-airtable": patch
---

This makes the fileNode pull `name` from the airtable metadata instead of the
remote file, because when an airtable user changes the file name, airtable does
not rename the original url. This change makes file name changes in airtable
usable in the fileNode instead of needing to download, rename, and re-upload the
file.
4 changes: 4 additions & 0 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const crypto = require("crypto");
const { createRemoteFileNode } = require("gatsby-source-filesystem");
const { map } = require("bluebird");
const mime = require("mime/lite");
const path = require("path");

exports.sourceNodes = async (
{ actions, createNodeId, store, cache },
Expand Down Expand Up @@ -305,8 +306,11 @@ const localFileCheck = async (
// the cleanKey here
data[key].forEach((attachment) => {
const ext = mime.getExtension(attachment.type); // unknown type returns null
// get the filename from the airtable metadata instead of the remote file
const airtableFileName = path.parse(attachment.filename).name;
let attachmentNode = createRemoteFileNode({
url: attachment.url,
name: airtableFileName,
store,
cache,
createNode,
Expand Down