Skip to content

Commit

Permalink
Merge branch 'release/0.0.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
DominusKelvin committed Jul 24, 2024
2 parents ee2f871 + d1a6e8a commit 051d703
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 29 deletions.
33 changes: 21 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"private": true,
"version": "0.0.6",
"version": "0.0.7",
"workspaces": [
"packages/*",
"examples/*"
Expand Down
8 changes: 5 additions & 3 deletions packages/plugin-sails-content/lib/generate-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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}`
)
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-sails-content/lib/index.js
Original file line number Diff line number Diff line change
@@ -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)
})
}
}
Expand Down
9 changes: 6 additions & 3 deletions packages/plugin-sails-content/lib/render.js
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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 }
}
Expand Down
3 changes: 1 addition & 2 deletions packages/plugin-sails-content/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -21,7 +21,6 @@
"author": "Kelvin Omereshone <[email protected]>",
"license": "MIT",
"dependencies": {
"ejs": "^3.1.9",
"gray-matter": "^4.0.3",
"showdown": "^2.1.0"
}
Expand Down
4 changes: 1 addition & 3 deletions packages/sails-hook-content/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/sails-hook-content/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -13,6 +13,6 @@
"hookName": "content"
},
"dependencies": {
"plugin-sails-content": "^0.0.5"
"plugin-sails-content": "^0.0.6"
}
}

0 comments on commit 051d703

Please sign in to comment.