bajo-template 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bajo/method/compile.js
CHANGED
|
@@ -31,7 +31,8 @@ async function compile (content, locals, { lang, ttl = 0 } = {}) {
|
|
|
31
31
|
const _ = this.app.bajo.lib._
|
|
32
32
|
const { template } = _
|
|
33
33
|
const cache = this.app.bajoCache
|
|
34
|
-
|
|
34
|
+
let canCache = this.config.cache !== false && cache && this.app.bajo.config.env !== 'dev'
|
|
35
|
+
if (ttl === -1) canCache = false
|
|
35
36
|
const opts = {
|
|
36
37
|
imports: buildCompileImports.call(this, lang)
|
|
37
38
|
}
|
|
@@ -38,6 +38,10 @@ async function handleInclude (content, locals = {}, opts = {}) {
|
|
|
38
38
|
|
|
39
39
|
export async function _renderString (content, locals = {}, opts = {}) {
|
|
40
40
|
const { merge, without, isString, omit } = this.app.bajo.lib._
|
|
41
|
+
if (opts.ext === '.md' && this.app.bajoMarkdown) {
|
|
42
|
+
content = await this.compile(content, locals, { lang: opts.lang, ttl: -1 }) // markdown can't process template tags, hence preprocess here
|
|
43
|
+
content = this.app.bajoMarkdown.parse(content)
|
|
44
|
+
}
|
|
41
45
|
let layout
|
|
42
46
|
if (!opts.partial) {
|
|
43
47
|
const pageFm = await this.parseFrontMatter(opts.frontMatter, opts.lang)
|
package/bajo/method/render.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import crypto from 'crypto'
|
|
2
2
|
import { _renderString } from './render-string.js'
|
|
3
|
+
import path from 'path'
|
|
3
4
|
|
|
4
5
|
let loopDetector = {}
|
|
5
6
|
|
|
@@ -46,9 +47,8 @@ async function _render (tpl, locals = {}, opts = {}) {
|
|
|
46
47
|
_detectLoop.call(this, tpl, file, opts)
|
|
47
48
|
const fileContent = trim(fs.readFileSync(file, 'utf8'))
|
|
48
49
|
let { content, frontMatter } = this.splitContent(fileContent)
|
|
49
|
-
if (isEmpty(content) && subNs === 'template')
|
|
50
|
-
|
|
51
|
-
}
|
|
50
|
+
if (isEmpty(content) && (subNs === 'template')) content = '<!-- include ' + tpl.replace('.template', '.partial') + ' -->'
|
|
51
|
+
opts.ext = path.extname(file)
|
|
52
52
|
opts.frontMatter = frontMatter
|
|
53
53
|
opts.partial = opts.partial ?? subNs === 'partial'
|
|
54
54
|
return await _renderString.call(this, content, locals, opts)
|