bajo-template 1.1.8 → 1.1.10
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.
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
<%= block.root.join('\n') %>
|
|
3
|
+
<% if (block.alpineInitializing) { %>
|
|
4
|
+
document.addEventListener('alpine:initializing', () => {
|
|
5
|
+
<%= block.alpineInitializing.join('\n') %>
|
|
6
|
+
})
|
|
7
|
+
<% } %>
|
|
8
|
+
<% if (block.alpineInit) { %>
|
|
9
|
+
document.addEventListener('alpine:init', () => {
|
|
10
|
+
<%= block.alpineInit.join('\n') %>
|
|
11
|
+
})
|
|
12
|
+
<% } %>
|
|
13
|
+
</script>
|
package/lib/resolve-resource.js
CHANGED
|
@@ -17,6 +17,7 @@ export function filecheck ({ check, dir, base, exts }) {
|
|
|
17
17
|
|
|
18
18
|
function resolveResource (type, item = '', opts = {}, fallbackHandler) {
|
|
19
19
|
const { trim, uniq, find } = this.lib._
|
|
20
|
+
const { fs } = this.lib
|
|
20
21
|
const env = this.app.bajo.config.env
|
|
21
22
|
if (env !== 'dev' && cache[item]) return cache[item]
|
|
22
23
|
|
|
@@ -60,6 +61,10 @@ function resolveResource (type, item = '', opts = {}, fallbackHandler) {
|
|
|
60
61
|
file = filecheck.call(this, { dir, base, exts, check })
|
|
61
62
|
}
|
|
62
63
|
if (fallbackHandler) file = fallbackHandler.call(this, { file, dir, base, exts, ns, subSubNs, type, theme: opts.theme })
|
|
64
|
+
if (opts.default) {
|
|
65
|
+
const fname = this.getResource(opts.default).fullPath
|
|
66
|
+
if (fs.existsSync(fname)) file = fname
|
|
67
|
+
}
|
|
63
68
|
if (!file) throw this.error('cantFind%s%s', type, item)
|
|
64
69
|
const result = { file, ns, layout: opts.layout }
|
|
65
70
|
if (env !== 'dev') cache[item] = result
|
package/package.json
CHANGED
package/plugin/factory.js
CHANGED
|
@@ -33,9 +33,13 @@ async function factory (pkgName) {
|
|
|
33
33
|
opts.lang = opts.lang ?? lang
|
|
34
34
|
return this.app.bajo.format(val, type, opts)
|
|
35
35
|
},
|
|
36
|
-
|
|
36
|
+
_findRoute: (input) => {
|
|
37
|
+
if (!this.app.waibu) return false
|
|
38
|
+
return this.app.waibu.findRoute(input)
|
|
39
|
+
},
|
|
40
|
+
_routePath: (input, opts) => {
|
|
37
41
|
if (!this.app.waibu) return input
|
|
38
|
-
return this.app.waibu.routePath(input)
|
|
42
|
+
return this.app.waibu.routePath(input, opts)
|
|
39
43
|
},
|
|
40
44
|
_titleize: this.app.bajo.titleize,
|
|
41
45
|
_hasPlugin: name => this.app.bajo.pluginNames.includes(name),
|
|
@@ -139,7 +143,7 @@ async function factory (pkgName) {
|
|
|
139
143
|
}
|
|
140
144
|
|
|
141
145
|
_renderString = async (content, locals = {}, opts = {}) => {
|
|
142
|
-
const { merge, without, isString, omit } = this.lib._
|
|
146
|
+
const { merge, without, isString, omit, kebabCase } = this.lib._
|
|
143
147
|
if (opts.ext === '.md' && this.app.bajoMarkdown) {
|
|
144
148
|
content = await this.compile(content, locals, { lang: opts.lang, ttl: -1 }) // markdown can't process template tags, hence preprocess here
|
|
145
149
|
content = this.app.bajoMarkdown.parse(content)
|
|
@@ -148,8 +152,13 @@ async function factory (pkgName) {
|
|
|
148
152
|
if (!opts.partial) {
|
|
149
153
|
const pageFm = await this.parseFrontMatter(opts.frontMatter, opts.lang)
|
|
150
154
|
if (pageFm.layout) opts.layout = pageFm.layout
|
|
155
|
+
if (pageFm.scriptBlock) opts.scriptBlock = pageFm.scriptBlock
|
|
156
|
+
if (pageFm.styleBlock) opts.styleBlock = pageFm.styleBlock
|
|
151
157
|
locals.page = merge({}, locals.page, omit(pageFm, ['layout']))
|
|
152
158
|
layout = opts.layout ?? locals.page.layout ?? (locals.page.ns ? `${locals.page.ns}.layout:/default.html` : 'main.layout:/default.html')
|
|
159
|
+
for (const b of ['scriptBlock', 'styleBlock']) {
|
|
160
|
+
locals.page[b] = pageFm[b] ?? opts[b] ?? (locals.page.ns ? `${locals.page.ns}.partial:/${kebabCase(b)}.html` : `bajoTemplate.partial:/${kebabCase(b)}.html`)
|
|
161
|
+
}
|
|
153
162
|
const ext = path.extname(layout)
|
|
154
163
|
const { file } = this.resolveLayout(layout, opts)
|
|
155
164
|
let { content: layoutContent, frontMatter: layoutFm } = this.splitContent(file, true)
|