forked from gatsbyjs/gatsby
-
Notifications
You must be signed in to change notification settings - Fork 1
/
markdown.config.js
45 lines (43 loc) · 1.41 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
const fs = require(`fs-extra`)
const path = require(`path`)
const _ = require(`lodash`)
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())
// theme starters have their own README so skip those
.filter(dir => !dir.includes(`theme`))
.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.com](https://gatsby-starter-${name}-demo.netlify.com/)|${starter.description}|
`.trim()
})
.join(`\n`)}
`.replace(/^[^|]+/gm, ``)
},
STARTER(content, options, { originalPath }) {
const starter = path.basename(path.dirname(originalPath))
const template = fs.readFileSync(
path.join(process.cwd(), `starters`, `README-template.md`),
`utf8`
)
return _.template(template)({
name: starter,
})
},
},
}