Skip to content

Commit 4716939

Browse files
committed
🎉 Initial commit
0 parents  commit 4716939

8 files changed

+3843
-0
lines changed

.babelrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"presets": [
3+
["babel-preset-gatsby-package"]
4+
]
5+
}

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
/gatsby-node.js

.npmignore

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Logs
2+
logs
3+
*.log
4+
5+
# Runtime data
6+
pids
7+
*.pid
8+
*.seed
9+
10+
# Directory for instrumented libs generated by jscoverage/JSCover
11+
lib-cov
12+
13+
# Coverage directory used by tools like istanbul
14+
coverage
15+
16+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17+
.grunt
18+
19+
# node-waf configuration
20+
.lock-wscript
21+
22+
# Compiled binary addons (http://nodejs.org/api/addons.html)
23+
build/Release
24+
25+
# Dependency directory
26+
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
27+
node_modules
28+
*.un~
29+
yarn.lock
30+
src
31+
flow-typed
32+
coverage
33+
decls
34+
examples
35+

README.md

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# gatsby-transformer-gitinfo
2+
3+
Add some git information on `File` fields: latest commit date, author and email.
4+
5+
## Install
6+
7+
`npm install --save gatsby-transformer-gitinfo`
8+
9+
**Note:** You also need to have `gatsby-source-filesystem` installed and configured so it
10+
points to your files.
11+
12+
## How to use
13+
14+
In your `gatsby-config.js`
15+
16+
```javascript
17+
module.exports = {
18+
plugins: [
19+
`gatsby-transformer-gitinfo`,
20+
{
21+
resolve: `gatsby-source-filesystem`,
22+
options: {
23+
path: `./src/data/`,
24+
},
25+
},
26+
],
27+
}
28+
```
29+
30+
Where the _source folder_ `./src/data/` is a git versionned directory.
31+
32+
The plugin will add three fields to `File` nodes: `gitDate`, `gitAuthorName` and `gitAuthorEmail`. These fields are relative to the latest commit touching that file.
33+
34+
If the file is not versionned, these feilds will be `null`.
35+
36+
They are exposed in your graphql schema which you can query:
37+
38+
```graphql
39+
query {
40+
allFile {
41+
edges {
42+
node {
43+
fields {
44+
gitDate
45+
gitAuthorName
46+
gitAuthorEmail
47+
}
48+
internal {
49+
type
50+
mediaType
51+
description
52+
owner
53+
}
54+
}
55+
}
56+
}
57+
}
58+
```
59+
60+
Now you have a File node to work with:
61+
62+
```json
63+
{
64+
"data": {
65+
"allFile": {
66+
"edges": [
67+
{
68+
"node": {
69+
"fields": {
70+
"gitDate": "2019-10-14T12:58:39.000Z",
71+
"gitAuthorName": "John Doe",
72+
"gitAuthorEmail": "[email protected]"
73+
},
74+
"internal": {
75+
"contentDigest": "c1644b03f380bc5508456ce91faf0c08",
76+
"type": "File",
77+
"mediaType": "text/yaml",
78+
"description": "File \"src/data/example.yml\"",
79+
"owner": "gatsby-source-filesystem"
80+
}
81+
}
82+
}
83+
]
84+
}
85+
}
86+
}
87+
```
88+
89+
## Configuration options
90+
91+
**`whitelist`** [regex][optional]
92+
93+
This plugin will try to match the absolute path of the file with the `whitelist` regex.
94+
If it *does not* match, the file will be skipped.
95+
96+
```javascript
97+
module.exports = {
98+
plugins: [
99+
{
100+
resolve: `gatsby-transformer-gitinfo`,
101+
options: {
102+
whitelist: /\.md$/i, // Only .md files
103+
},
104+
},
105+
],
106+
}
107+
```
108+
109+
110+
**`blacklist`** [regex][optional]
111+
112+
This plugin will try to match the absolute path of the file with the `blacklist` regex.
113+
If it *does* match, the file will be skipped.
114+
115+
```javascript
116+
module.exports = {
117+
plugins: [
118+
{
119+
resolve: `gatsby-transformer-gitinfo`,
120+
options: {
121+
blacklist: /\.jpeg$/i, // All files except .jpeg
122+
},
123+
},
124+
],
125+
}
126+
```
127+
128+
129+
Note: the execution order is first whitelist, then blacklist.
130+
131+
```javascript
132+
module.exports = {
133+
plugins: [
134+
{
135+
resolve: `gatsby-transformer-gitinfo`,
136+
options: {
137+
whitelist: /\.md$/i,
138+
blacklist: /README/i, // Will match all .md files, except README.md
139+
},
140+
},
141+
],
142+
}
143+
```

index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//no-op

0 commit comments

Comments
 (0)