From 258c824d07135f81284f75f26e6ed7a89961cc3a Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Tue, 16 Jan 2024 12:28:30 +0100 Subject: [PATCH 1/6] feat(plugin-sails-content): update config to use an object to take layout as well --- .../lib/generate-content.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/plugin-sails-content/lib/generate-content.js b/packages/plugin-sails-content/lib/generate-content.js index 183bde0..c6025ba 100644 --- a/packages/plugin-sails-content/lib/generate-content.js +++ b/packages/plugin-sails-content/lib/generate-content.js @@ -3,22 +3,27 @@ const path = require('path') const render = require('./render') const writeHtmlToOutput = require('./write-html-to-output') -async function generateContent(inputDir, outputDir = '.tmp/public') { - const files = await fs.readdir(inputDir) +async function generateContent(config) { + config.outputDir = config.outputDir ? config.outputDir : '.tmp/public' + const files = await fs.readdir(config.inputDir) for (const file of files) { - const filePath = path.join(inputDir, file) + const filePath = path.join(config.inputDir, file) const fileStats = await fs.stat(filePath) if (fileStats.isDirectory()) { - await generateContent(filePath, path.join(outputDir, file)) + await generateContent({ + inputDir: filePath, + outputDir: path.join(config.outputDir, file) + }) } else if (fileStats.isFile() && file.toLowerCase().endsWith('.md')) { - const { data, renderedHtml } = await render(filePath) + const { data, renderedHtml } = await render(filePath, config.layout) const outputFilePath = await writeHtmlToOutput( renderedHtml, file, - inputDir + config.inputDir ) + // @ts-ignore sails.log.verbose( `[sails:content] Processed ${filePath} -> ${outputFilePath}` ) From c9bd6a9917cf02f68d8216fd7d66fd77d818cd2f Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Tue, 16 Jan 2024 12:29:29 +0100 Subject: [PATCH 2/6] feat(plugin-sails-content): update pluginSailsContent to take a config object --- packages/plugin-sails-content/lib/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/plugin-sails-content/lib/index.js b/packages/plugin-sails-content/lib/index.js index 7f45a4a..1c916d0 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(options) { +module.exports = function pluginSailsContent(config) { return { name: 'sails:content', setup(api) { api.onDevCompileDone(async function () { - await generateContent(options.inputDir) + await generateContent(config) }) api.onAfterBuild(async function () { - await generateContent(options.inputDir) + await generateContent(config) }) } } From 9a7e1413d6e8f4ac151a89aa0cbfec52e5cddeb1 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Tue, 16 Jan 2024 12:31:20 +0100 Subject: [PATCH 3/6] feat(plugin-sails-content): add global layout config --- packages/plugin-sails-content/lib/render.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/plugin-sails-content/lib/render.js b/packages/plugin-sails-content/lib/render.js index 5e48935..51ee085 100644 --- a/packages/plugin-sails-content/lib/render.js +++ b/packages/plugin-sails-content/lib/render.js @@ -3,14 +3,16 @@ const matter = require('gray-matter') const showdown = require('showdown') const ejs = require('ejs') -async function render(mdFile) { +async function render(mdFile, layout) { const fileContent = await fs.readFile(mdFile, { encoding: 'utf8' }) const { data, content } = matter(fileContent) + layout = layout || data.layout + const converter = new showdown.Converter({ ghCompatibleHeaderId: true }) const htmlContent = converter.makeHtml(content) - const layoutContent = await fs.readFile(data.layout, { encoding: 'utf8' }) + const layoutContent = await fs.readFile(layout, { encoding: 'utf8' }) const renderedHtml = ejs.render(layoutContent, { data, content: htmlContent }) From 4ef4acd0d89a73ed8a7e267f6056c12b86d39365 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Tue, 16 Jan 2024 12:31:46 +0100 Subject: [PATCH 4/6] feat(sails-hook-content): pass the content config to pluginSailsContent --- packages/sails-hook-content/lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sails-hook-content/lib/index.js b/packages/sails-hook-content/lib/index.js index ec0033b..aeab111 100644 --- a/packages/sails-hook-content/lib/index.js +++ b/packages/sails-hook-content/lib/index.js @@ -20,7 +20,7 @@ module.exports = function defineSailsContentHook(sails) { sails.log.info('Initializing custom hook (`sails-content`)') if (sails.config.content.output == 'static') { sails.config.shipwright.build.plugins.push( - pluginSailsContent({ inputDir: sails.config.content.inputDir }) + pluginSailsContent(sails.config.content) ) } } From f382933d2c3730c70b84d831d5675aeff11897bc Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Tue, 16 Jan 2024 12:47:51 +0100 Subject: [PATCH 5/6] chore(plugin-sails-content): release 0.0.3 --- packages/plugin-sails-content/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/plugin-sails-content/package.json b/packages/plugin-sails-content/package.json index 7a736a6..563dd58 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.2", + "version": "0.0.3", "description": "Sails Content plugin for Rsbuild", "main": "lib/index.js", "scripts": { From 895dd889fe4ff0e95d00c78738a2d5bbf757eaa3 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Tue, 16 Jan 2024 12:48:23 +0100 Subject: [PATCH 6/6] chore(sails-hook-content): release 0.0.3 --- packages/sails-hook-content/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sails-hook-content/package.json b/packages/sails-hook-content/package.json index 76d640f..3fa5f96 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.2", + "version": "0.0.3", "description": "Sails hook for Sails Content", "main": "lib/index.js", "scripts": {