Skip to content

Commit

Permalink
Add Netlify Build plugin to generate metadata normally provided by gi…
Browse files Browse the repository at this point in the history
…thub-metadata gem
  • Loading branch information
timwis committed Jan 24, 2023
1 parent 9b9bc98 commit 98a812b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,4 @@ exclude:
- webpack.config.js
- README.md
- LICENSE
- netlify
5 changes: 4 additions & 1 deletion netlify.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[build]
command = "jekyll build"
command = "jekyll build --config _config.yml,_config_override.yml"
publish = "_site"

[[plugins]]
package = "/netlify/plugins/netlify-jekyll-metadata"
12 changes: 12 additions & 0 deletions netlify/plugins/netlify-jekyll-metadata/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import fs from 'node:fs'
import url from 'node:url'

export const onPreBuild = async function () {
const siteUrl = process.env.URL
const repoUrl = new URL(process.env.REPOSITORY_URL || '')
const repoNameWithOwner = repoUrl.pathname.replace(/^\/+/, '')

const fileName = '_config_override.yml'
const fileContents = `repository: ${repoNameWithOwner}\nurl: ${siteUrl}`
return fs.promises.writeFile(fileName, fileContents)
}
1 change: 1 addition & 0 deletions netlify/plugins/netlify-jekyll-metadata/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name: netlify-jekyll-metadata
6 changes: 6 additions & 0 deletions netlify/plugins/netlify-jekyll-metadata/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "netlify-jekyll-metadata",
"description": "Netlify Build Plugin to populate a Jekyll site with the metadata normally provided by the github-metadata gem",
"type": "module",
"exports": "./index.js"
}

0 comments on commit 98a812b

Please sign in to comment.