diff --git a/package-lock.json b/package-lock.json index a7cb806..82cc705 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,10 +1,11 @@ { "name": "sails-content", - "version": "1.0.0", + "version": "0.0.6", "lockfileVersion": 3, "requires": true, "packages": { "": { + "version": "0.0.6", "workspaces": [ "packages/*", "examples/*" @@ -870,25 +871,6 @@ "node": ">=0.10.0" } }, - "node_modules/async": { - "version": "3.2.5", - "resolved": "https://registry.npmjs.org/async/-/async-3.2.5.tgz", - "integrity": "sha512-baNZyqaaLhyLVKm/DlvdW051MSgO6b8eVfIezl9E5PqWxFgzLm/wQntEW4zOytVburDEr0JlALEpdOFwvErLsg==" - }, - "node_modules/balanced-match": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" - }, - "node_modules/brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dependencies": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, "node_modules/braces": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", @@ -1133,11 +1115,6 @@ "dot-prop": "^5.1.0" } }, - "node_modules/concat-map": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" - }, "node_modules/conventional-changelog-angular": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/conventional-changelog-angular/-/conventional-changelog-angular-7.0.0.tgz", @@ -1309,20 +1286,6 @@ "node": ">=8" } }, - "node_modules/ejs": { - "version": "3.1.9", - "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.9.tgz", - "integrity": "sha512-rC+QVNMJWv+MtPgkt0y+0rVEIdbtxVADApW9JXrUVlzHetgcyczP/E7DJmWJ4fJCZF2cPcBk0laWO9ZHMG3DmQ==", - "dependencies": { - "jake": "^10.8.5" - }, - "bin": { - "ejs": "bin/cli.js" - }, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/emoji-regex": { "version": "10.3.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-10.3.0.tgz", @@ -1414,33 +1377,6 @@ "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", "dev": true }, - "node_modules/filelist": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/filelist/-/filelist-1.0.4.tgz", - "integrity": "sha512-w1cEuf3S+DrLCQL7ET6kz+gmlJdbq9J7yXCSjK/OZCPA+qEN1WyF4ZAf0YYJa4/shHJra2t/d/r8SV4Ji+x+8Q==", - "dependencies": { - "minimatch": "^5.0.1" - } - }, - "node_modules/filelist/node_modules/brace-expansion": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", - "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", - "dependencies": { - "balanced-match": "^1.0.0" - } - }, - "node_modules/filelist/node_modules/minimatch": { - "version": "5.1.6", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", - "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/fill-range": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", @@ -1858,87 +1794,6 @@ "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", "dev": true }, - "node_modules/jake": { - "version": "10.8.7", - "resolved": "https://registry.npmjs.org/jake/-/jake-10.8.7.tgz", - "integrity": "sha512-ZDi3aP+fG/LchyBzUM804VjddnwfSfsdeYkwt8NcbKRvo4rFkjhs456iLFn3k2ZUWvNe4i48WACDbza8fhq2+w==", - "dependencies": { - "async": "^3.2.3", - "chalk": "^4.0.2", - "filelist": "^1.0.4", - "minimatch": "^3.1.2" - }, - "bin": { - "jake": "bin/cli.js" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/jake/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dependencies": { - "color-convert": "^2.0.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, - "node_modules/jake/node_modules/chalk": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "dependencies": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" - } - }, - "node_modules/jake/node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" - } - }, - "node_modules/jake/node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" - }, - "node_modules/jake/node_modules/has-flag": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "engines": { - "node": ">=8" - } - }, - "node_modules/jake/node_modules/supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dependencies": { - "has-flag": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/jiti": { "version": "1.21.0", "resolved": "https://registry.npmjs.org/jiti/-/jiti-1.21.0.tgz", @@ -2289,17 +2144,6 @@ "node": ">=4" } }, - "node_modules/minimatch": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", - "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", - "dependencies": { - "brace-expansion": "^1.1.7" - }, - "engines": { - "node": "*" - } - }, "node_modules/minimist": { "version": "1.2.8", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", @@ -3355,7 +3199,6 @@ "version": "0.0.5", "license": "MIT", "dependencies": { - "ejs": "^3.1.9", "gray-matter": "^4.0.3", "showdown": "^2.1.0" } @@ -3365,8 +3208,7 @@ "license": "MIT", "dependencies": { "gray-matter": "^4.0.3" - }, - "devDependencies": {} + } }, "packages/sails-hook-content": { "version": "0.0.6", diff --git a/packages/plugin-sails-content/lib/generate-content.js b/packages/plugin-sails-content/lib/generate-content.js index 9531c4d..414f1f6 100644 --- a/packages/plugin-sails-content/lib/generate-content.js +++ b/packages/plugin-sails-content/lib/generate-content.js @@ -3,7 +3,8 @@ const path = require('path') const render = require('./render') const writeHtmlToOutput = require('./write-html-to-output') -async function generateContent(config) { +async function generateContent(sails) { + const config = sails.config.content config.outputDir = config.outputDir ? config.outputDir : '.tmp/public' const files = await fs.readdir(config.inputDir) @@ -18,13 +19,14 @@ async function generateContent(config) { outputDir: path.join(config.outputDir, file) }) } else if (fileStats.isFile() && file.toLowerCase().endsWith('.md')) { - const { data, renderedHtml } = await render(filePath, config.layout) + const { renderedHtml } = await render(sails, filePath, config.layout) + const outputFilePath = await writeHtmlToOutput( renderedHtml, file, config.inputDir ) - // @ts-ignore + sails.log.verbose( `[sails:content] Processed ${filePath} -> ${outputFilePath}` ) diff --git a/packages/plugin-sails-content/lib/index.js b/packages/plugin-sails-content/lib/index.js index 1c916d0..cc8185f 100644 --- a/packages/plugin-sails-content/lib/index.js +++ b/packages/plugin-sails-content/lib/index.js @@ -1,13 +1,13 @@ const generateContent = require('./generate-content') -module.exports = function pluginSailsContent(config) { +module.exports = function pluginSailsContent(sails) { return { name: 'sails:content', setup(api) { api.onDevCompileDone(async function () { - await generateContent(config) + await generateContent(sails) }) api.onAfterBuild(async function () { - await generateContent(config) + await generateContent(sails) }) } } diff --git a/packages/plugin-sails-content/lib/render.js b/packages/plugin-sails-content/lib/render.js index 51ee085..15b30e7 100644 --- a/packages/plugin-sails-content/lib/render.js +++ b/packages/plugin-sails-content/lib/render.js @@ -1,9 +1,8 @@ const fs = require('fs/promises') const matter = require('gray-matter') const showdown = require('showdown') -const ejs = require('ejs') -async function render(mdFile, layout) { +async function render(sails, mdFile, layout) { const fileContent = await fs.readFile(mdFile, { encoding: 'utf8' }) const { data, content } = matter(fileContent) @@ -14,7 +13,11 @@ async function render(mdFile, layout) { const layoutContent = await fs.readFile(layout, { encoding: 'utf8' }) - const renderedHtml = ejs.render(layoutContent, { data, content: htmlContent }) + const renderedHtml = await sails.renderView(layoutContent, { + layout: false, + data, + content: htmlContent + }) return { data, renderedHtml } } diff --git a/packages/plugin-sails-content/package.json b/packages/plugin-sails-content/package.json index e0af847..4d0dc92 100644 --- a/packages/plugin-sails-content/package.json +++ b/packages/plugin-sails-content/package.json @@ -21,7 +21,6 @@ "author": "Kelvin Omereshone ", "license": "MIT", "dependencies": { - "ejs": "^3.1.9", "gray-matter": "^4.0.3", "showdown": "^2.1.0" } diff --git a/packages/sails-hook-content/lib/index.js b/packages/sails-hook-content/lib/index.js index aeab111..53e61f2 100644 --- a/packages/sails-hook-content/lib/index.js +++ b/packages/sails-hook-content/lib/index.js @@ -19,9 +19,7 @@ module.exports = function defineSailsContentHook(sails) { initialize: async function () { sails.log.info('Initializing custom hook (`sails-content`)') if (sails.config.content.output == 'static') { - sails.config.shipwright.build.plugins.push( - pluginSailsContent(sails.config.content) - ) + sails.config.shipwright.build.plugins.push(pluginSailsContent(sails)) } } }