-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from bericp1/chore/rename-now-to-vercel
[Chore] Rename now to vercel
- Loading branch information
Showing
23 changed files
with
151 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const frontmatter = require('front-matter'); | ||
const marked = require('marked'); | ||
|
||
async function render(name) { | ||
// Resolve the path to the possible markdown file | ||
const fullPathToPossibleMarkdownFile = path.resolve( | ||
__dirname, | ||
`./pages/${name}${name.endsWith('.md') ? '' : '.md'}`, | ||
); | ||
// Attempt to read the file, returning false ("no I did not handle this request") if any error occurs reading the file. | ||
let markdownFileContents = null; | ||
try { | ||
markdownFileContents = await fs.promises.readFile(fullPathToPossibleMarkdownFile, { encoding: 'utf8' }); | ||
} catch (ignored) { | ||
return false; | ||
} | ||
// Parse the file first using `front-matter` and `marked` | ||
const fileFrontmatter = frontmatter(markdownFileContents); | ||
const htmlFileContents = marked(fileFrontmatter.body); | ||
// Generate the HTML, using the frontmatter to generate the title. | ||
return `<html lang="en"><head><title>${fileFrontmatter.attributes.title || ''}</title>` | ||
+ `</head><body>\n${htmlFileContents}</body></html>`; | ||
} | ||
|
||
/** | ||
* @returns {Promise<[string, string][]>} | ||
*/ | ||
async function renderAllPages() { | ||
const fullPathToPages = path.resolve( | ||
__dirname, | ||
`./pages`, | ||
); | ||
const filesInPagesDir = await fs.promises.readdir(fullPathToPages, { encoding: 'utf8', withFileTypes: true }); | ||
return Promise.all( | ||
filesInPagesDir | ||
.reduce((entries, dirEnt) => { | ||
if (dirEnt.isFile() && dirEnt.name.endsWith('.md')) { | ||
entries.push( | ||
render(dirEnt.name) | ||
.then((html) => [ | ||
dirEnt.name.replace(/\.md$/i, '.html'), | ||
html, | ||
]) | ||
); | ||
} | ||
return entries; | ||
}, []), | ||
); | ||
} | ||
|
||
module.exports = { render, renderAllPages }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const { createVercelBeginHandler } = require('netlify-cms-oauth-provider-node'); | ||
|
||
module.exports = createVercelBeginHandler({}, { useEnv: true }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const { createVercelCompleteHandler } = require('netlify-cms-oauth-provider-node'); | ||
|
||
module.exports = createVercelCompleteHandler({}, { useEnv: true }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { renderAllPages } = require('../common/render'); // eslint-disable-line node/no-unpublished-require | ||
|
||
renderAllPages() | ||
.then((pages) => Promise.all(pages.map(async ([fileName, html]) => { | ||
const finalFileName = fileName === 'home.html' ? 'index.html' : fileName; | ||
const publicPathForFile = path.resolve(__dirname, './public', finalFileName); | ||
console.log(`Writing ${finalFileName} to ${publicPathForFile}`); | ||
await fs.promises.writeFile(publicPathForFile, html); | ||
}))); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "netlify-cms-oauth-provider-node-vercel-example", | ||
"private": true, | ||
"scripts": { | ||
"start": "vercel dev", | ||
"clean": "rm -rf public/", | ||
"build": "yarn run clean && mkdir public && cp admin.html config.yml public/ && node ./build.js" | ||
}, | ||
"engines": { | ||
"node": "14.x" | ||
}, | ||
"dependencies": { | ||
"front-matter": "^4.0.2", | ||
"marked": "^2.0.1", | ||
"netlify-cms-oauth-provider-node": "latest" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"cleanUrls": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
const generic = require('./generic'); | ||
const now = require('./now'); | ||
const vercel = require('./vercel'); | ||
|
||
module.exports = { | ||
generic, | ||
now, | ||
vercel, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.