diff --git a/package-lock.json b/package-lock.json index a7cb806..7d7b25b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,10 +1,11 @@ { "name": "sails-content", - "version": "1.0.0", + "version": "0.0.7", "lockfileVersion": 3, "requires": true, "packages": { "": { + "version": "0.0.7", "workspaces": [ "packages/*", "examples/*" @@ -1310,9 +1311,9 @@ } }, "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==", + "version": "3.1.10", + "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.10.tgz", + "integrity": "sha512-UeJmFfOrAQS8OJWPZ4qtgHyWExa088/MtK5UEyoJGFH67cDEXkZSviOiKRCZ4Xij0zxI3JECgYs3oKx+AizQBA==", "dependencies": { "jake": "^10.8.5" }, @@ -1859,9 +1860,9 @@ "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==", + "version": "10.9.2", + "resolved": "https://registry.npmjs.org/jake/-/jake-10.9.2.tgz", + "integrity": "sha512-2P4SQ0HrLQ+fw6llpLnOaGAvN2Zu6778SJMrCUwns4fOoG9ayrTiZk3VV8sCPkVZF8ab0zksVpS8FDY5pRCNBA==", "dependencies": { "async": "^3.2.3", "chalk": "^4.0.2", @@ -3352,10 +3353,9 @@ } }, "packages/plugin-sails-content": { - "version": "0.0.5", + "version": "0.0.6", "license": "MIT", "dependencies": { - "ejs": "^3.1.9", "gray-matter": "^4.0.3", "showdown": "^2.1.0" } @@ -3365,15 +3365,24 @@ "license": "MIT", "dependencies": { "gray-matter": "^4.0.3" - }, - "devDependencies": {} + } }, "packages/sails-hook-content": { - "version": "0.0.6", + "version": "0.0.7", "license": "MIT", "dependencies": { "plugin-sails-content": "^0.0.5" } + }, + "packages/sails-hook-content/node_modules/plugin-sails-content": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/plugin-sails-content/-/plugin-sails-content-0.0.5.tgz", + "integrity": "sha512-u5/43RCzaXNQa495QpHTSksYQ5dANb/bdS2fV31SW4bn66nUH3fPlCpn8RQFed1kfKjMVHBO74tOMVawpZs5BQ==", + "dependencies": { + "ejs": "^3.1.9", + "gray-matter": "^4.0.3", + "showdown": "^2.1.0" + } } } } diff --git a/package.json b/package.json index f5babc4..ad299bc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "private": true, - "version": "0.0.6", + "version": "0.0.7", "workspaces": [ "packages/*", "examples/*" 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..d60fa99 100644 --- a/packages/plugin-sails-content/package.json +++ b/packages/plugin-sails-content/package.json @@ -1,6 +1,6 @@ { "name": "plugin-sails-content", - "version": "0.0.5", + "version": "0.0.6", "description": "Sails Content plugin for Rsbuild", "main": "lib/index.js", "scripts": { @@ -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)) } } } diff --git a/packages/sails-hook-content/package.json b/packages/sails-hook-content/package.json index bc9458e..6a4b15e 100644 --- a/packages/sails-hook-content/package.json +++ b/packages/sails-hook-content/package.json @@ -1,6 +1,6 @@ { "name": "sails-hook-content", - "version": "0.0.6", + "version": "0.0.7", "description": "Sails hook for Sails Content", "main": "lib/index.js", "scripts": { @@ -13,6 +13,6 @@ "hookName": "content" }, "dependencies": { - "plugin-sails-content": "^0.0.5" + "plugin-sails-content": "^0.0.6" } }