Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
terryjbutler committed Apr 12, 2021
0 parents commit b09a97b
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 0 deletions.
69 changes: 69 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# dotenv environment variable files
.env*

# gatsby files
.cache/
public

# Mac files
.DS_Store

# Yarn
yarn-error.log
.pnp/
.pnp.js
# Yarn Integrity file
.yarn-integrity
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Terry Butler

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# gatsby-source-filesystem-markdown-name

Adds a new node field called "name" designed to filter on a directory referenced by gatsby-source-filesystem:

## Install

```
npm i gatsby-source-filesystem-markdown-name
```

or

```
yarn add gatsby-source-filesystem-markdown-name
```

## Example gatsby-config.js

```javascript
plugins: [
{
resolve: `gatsby-source-filesystem`,
options: {
path: `${__dirname}/src/content/posts/`,
name: 'posts',
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
path: `${__dirname}/src/content/pages/`,
name: 'pages',
},
},
'gatsby-source-filesystem-markdown-name',
]
```

# Example GraphQL Query

```graphql
query MyQuery {
allMarkdownRemark(filter: {fields: {sourceName: {eq: "posts"}}}) {
edges {
node {
fields {
slug
sourceName
}
}
}
}
}
```
22 changes: 22 additions & 0 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.com/docs/node-apis/
*/

exports.onCreateNode = ({ node, getNode, actions }) => {

const { createNodeField } = actions

if (node.internal.type !== 'MarkdownRemark') {
return;
}

const fileNode = getNode(node.parent);

createNodeField({
node,
name: 'sourceName',
value: fileNode.sourceInstanceName,
});
};
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// noop
23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "gatsby-source-filesystem-markdown-name",
"version": "1.0.0",
"description": "Exposes a new node field called name to allow filtering of separate folders using the gatsby-source-filesystem plugin",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "echo \"No build script setup\""
},
"keywords": [
"gatsby",
"gatsby-plugin",
"markdown",
"blog"
],
"author": "Terry Butler",
"license": "MIT",
"homepage": "https://github.com/terryjbutler/gatsby-source-filesystem-markdown-name",
"repository": {
"type": "git",
"url": "https://github.com/terryjbutler/"
}
}
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


0 comments on commit b09a97b

Please sign in to comment.