Adds PlainText nodes to gatsby. Every file with a .txt extension or without a file extension will be added as PlainText node.
npm install --save gatsby-transformer-plaintext
Note: You also need to have gatsby-source-filesystem
installed and configured so it points to your files.
In your gatsby-config.js
module.exports = {
plugins: [
`gatsby-transformer-plaintext`,
{
resolve: `gatsby-source-filesystem`,
options: {
path: `./src/data/`,
},
},
],
}
Where the source folder ./src/data/
contains plain text files such as LICENSE
.
You can query the nodes using GraphQL, like from the GraphiQL browser: http://localhost:8000/___graphql
.
{
allPlainText {
nodes {
content
}
}
}
Returns:
{
"data": {
"allPlainText": {
"nodes": [
{
"content": "content of file"
},
{
"content": "content of second file"
}
]
}
}
}
{
file(relativePath: { eq: "LICENSE" }) {
childPlainText {
content
}
}
}
Returns:
{
"data": {
"file": {
"childPlainText": {
"content": "MIT License"
}
}
}
}