Documents are normalized content objects that Netlify Create reads and writes from content sources. The properties here allow for extending behavior built into content source modules in Netlify Create.
Document Properties
These properties enable you to customize the behavior and visibility of editable documents in Netlify Create.
filterDocument
Filter documents available to be edited in Netlify Create based on the current user context.
1
2
3
4
5
6
- The
filterDocument
function is called for every document that is loaded from all content sources. The return value (boolean orundefined
) determines if the document is available to be edited in Netlify Create, overriding thehidden
property on that document.- If
hidden
istrue
on a document, returningtrue
fromfilterDocument
will override that and make the document visible and editable. - If
hidden
isfalse
(orundefined
) on a document, returningfalse
fromfilterDocument
will override that and hide the document, making it uneditable. Returningundefined
fromfilterDocument
will leave the document visible and editable.
- If
filterModel
is run beforefilterDocument
, and if a model is hidden, all documents of that model will be hidden as well, andfilterDocument
will not be called for those documents.
mapDocuments
(experimental)
A function that can be used to extend or manipulate documents that Netlify Create retrieves from the content source.
1
2
3
4
5
6
7
8
9
10
- This can only be used when the source was defined using
contentSources
. - The function should return an array of documents. Documents not returned from this function will be ignored by Netlify Create.
Document Hook Methods
Document hooks provide the ability to perform transformations and other operations on documents, in response to content changes within Netlify Create.
onContentCreate
Modify values of documents and their nested objects before these values are transformed into operations to create new documents.
After this method is returned, Netlify Create will take the result and call onDocumentCreate
for every eligible document contained within the return object.
Options
The options
object contains shared document hook method properties, along with these unique properties:
Usage Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
See the document hooks feature guide for more information and examples.
Reserved Keys
There are reserved keys that can be used to help with nested and reference information.
See the feature guide and Presets API reference for more information.
onDocumentCreate
Perform actions after a user creates a new document, but before that document is stored in the content source.
Options
The options
object contains shared document hook method properties, along with these unique properties:
Usage Example
1
2
3
4
5
6
7
8
9
10
See the document hooks feature guide for more information and examples.
onDocumentDelete
Perform actions after a user chooses to deletes a document, but before that document is removed from the content source.
Options
The options
object contains shared document hook method properties, along with these unique properties:
Usage Example
1
2
3
4
5
6
7
8
9
10
See the document hooks feature guide for more information and examples.
onDocumentsPublish
Perform actions after a user publishes changes, but before the changes are marked as published in the content source.
Options
The options
object contains shared document hook method properties, along with these unique properties:
Usage Example
1
2
3
4
5
6
7
8
9
10
See the document hooks feature guide for more information and examples.
onDocumentUpdate
Perform actions after a user updates an existing document, but before the changes are sent to the content source.
Options
The options
object contains shared document hook method properties, along with these unique properties:
Usage Example
1
2
3
4
5
6
7
8
9
10
See the document hooks feature guide for more information and examples.
Document Hook Options
In addition to the unique properties available in the options
object sent to document hook functions, there are a number of properties within options
available to all hooks. These are referenced below.
contentSourceActions
An object containing functions to create, update, delete and publish documents in the content source of the current document.
All functions receive an optional userContext
. If the userContext
is not specified, a default userContext
for the current user and the content source will be used.
Action Functions
The following functions are available on this object.
Usage Example
1
getContentSourceActionsForSource
Function that returns an object containing functions to create, update, delete and publish documents in the content source matching the received srcType
and srcProjectId
. This is typically used to call these actions on a source other than the one used by the current document.
All functions receive an optional userContext
. If the userContext
is not specified, a default userContext
for the current user and the content source will be used.
Function Parameters
Options passed to this function are shown below.
Return Value
Unless undefined
, the return value will be an object with the following methods.
Usage Example
1
2
3
4
getDefaultLocaleBySource
Returns the default locale of a content source.
Function Parameters
The following should be sent as properties to an options argument passed to the function.
Usage Example
1
getDocumentById
Returns a Document
object using the unique id
value of the document in the content source.
Function Parameters
The following should be sent as properties to an options argument passed to the function.
Usage Example
1
getDocumentFieldForFieldPath
Returns a (non-localized) document field for the provided fieldPath
.
Function Parameters
The following should be sent as properties to an options argument passed to the function.
Usage Example
1
2
3
4
getDocuments
Returns an array of DocumentWithSource
objects value of the document in the content source. DocumentWithSource
adds srcType
and srcProjectId
properties to the standard Document
object.
Function Parameters
This method uses no parameters.
Usage Example
1
getLogger
Returns a Logger
object that can be used to emit messages to the appropriate console, based on the developer's or user's environment and context.
Function Parameters
There are no parameters for this method.
Usage Example
1
Return Value
The Logger
return value contains functions that can be used to set the context of a message. Each accepts a message string as the sole parameter.
1
2
3
4
5
getModelByName
Returns a Model
object by matching the name
property.
Function Parameters
The following should be sent as properties to an options argument passed to the function.
Usage Example
1
getSchemas
Returns an array of SchemaWithSource
objects, optionally filtered by a specific source.
Function Parameters
The function accepts a single options object, which supports the following properties:
If omitted, the function returns all schemas. Otherwise it will filter by all of the specified properties.
Usage Example
1
2
Return Value
A SchemaWithSource
object has the following properties:
context
: The schema contextlocales
: A list of locales used within the schema, if applicable.models
: An array ofModel
objects within that schemasrcProjectId
: Uniquely-identifying string for the content source instancesrcType
: Property from the content source module
getUserContextForContentSourceType
Returns the userContext
of the current user for the content source specified by srcType
. This can be used to create, update, delete and publish documents on behalf of the current user.
Generally, userContext
is not used, as it will be applied automatically as the current user.
Function Parameters
Options passed to this function are shown below.
Return Value
A user context object is returned, which can be passed as the userContext
property when using a document action. Typically, this is not needed.
Usage Example
1
srcProjectId
The content source project ID of the current document (string
), set by the content source module. This is usually passed as an option when instantiating the content source module.
srcType
The content source type of the current document (string
), set by the content source module.