-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
markdown.config.js
57 lines (52 loc) · 1.61 KB
/
markdown.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const fs = require(`fs-extra`)
const path = require(`path`)
const _ = require(`lodash`)
const exclusionList = [
`gatsby-starter-minimal`,
`gatsby-starter-minimal-ts`,
`gatsby-starter-plugin`,
`gatsby-starter-theme-workspace`,
]
module.exports = {
transforms: {
LIST_STARTERS() {
const base = path.join(process.cwd(), `starters`)
const starters = fs
.readdirSync(base)
.filter(dir => fs.statSync(path.join(base, dir)).isDirectory())
// Filter out excluded starters
.filter(dir => !exclusionList.includes(dir))
.reduce((merged, dir) => {
merged[dir] = JSON.parse(
fs.readFileSync(path.join(base, dir, `package.json`), `utf8`)
)
return merged
}, {})
return `
|Name|Demo|Description|
|:--:|----|-----------|
${Object.keys(starters)
.map(name => {
const starter = starters[name]
return `
|[${name}](https://github.com/gatsbyjs/gatsby-starter-${name})|[gatsby-starter-${name}-demo.netlify.app](https://gatsby-starter-${name}-demo.netlify.app/)|${starter.description}|
`.trim()
})
.join(`\n`)}
`.replace(/^[^|]+/gm, ``)
},
STARTER(content, options, { originalPath }) {
const starter = path.basename(path.dirname(originalPath))
if (exclusionList.includes(starter)) {
return ``
}
const template = fs.readFileSync(
path.join(process.cwd(), `starters`, `README-template.md`),
`utf8`
)
return _.template(template)({
name: starter,
})
},
},
}