bajo-template 1.1.3 → 1.1.5
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/package.json +1 -1
- package/plugin/factory.js +14 -2
package/package.json
CHANGED
package/plugin/factory.js
CHANGED
|
@@ -43,6 +43,9 @@ async function factory (pkgName) {
|
|
|
43
43
|
_parseMarkdown: content => {
|
|
44
44
|
if (!this.app.bajoMarkdown) return content
|
|
45
45
|
return this.app.bajoMarkdown.parseContent(content)
|
|
46
|
+
},
|
|
47
|
+
_excerpt: (content, words) => {
|
|
48
|
+
return this.getExcerpt(content, words)
|
|
46
49
|
}
|
|
47
50
|
}
|
|
48
51
|
}
|
|
@@ -143,8 +146,8 @@ async function factory (pkgName) {
|
|
|
143
146
|
if (!opts.partial) {
|
|
144
147
|
const pageFm = await this.parseFrontMatter(opts.frontMatter, opts.lang)
|
|
145
148
|
if (pageFm.layout) opts.layout = pageFm.layout
|
|
146
|
-
locals.page = merge(locals.page, omit(pageFm, ['layout']))
|
|
147
|
-
layout = opts.layout ?? (locals.page.ns ? `${locals.page.ns}.layout:/default.html` : 'main.layout:/default.html')
|
|
149
|
+
locals.page = merge({}, locals.page, omit(pageFm, ['layout']))
|
|
150
|
+
layout = opts.layout ?? locals.page.layout ?? (locals.page.ns ? `${locals.page.ns}.layout:/default.html` : 'main.layout:/default.html')
|
|
148
151
|
const ext = path.extname(layout)
|
|
149
152
|
const { file } = this.resolveLayout(layout, opts)
|
|
150
153
|
let { content: layoutContent, frontMatter: layoutFm } = this.splitContent(file, true)
|
|
@@ -306,6 +309,15 @@ async function factory (pkgName) {
|
|
|
306
309
|
content = content ?? ''
|
|
307
310
|
return { frontMatter, content }
|
|
308
311
|
}
|
|
312
|
+
|
|
313
|
+
// based on: https://medium.com/@paulohfev/problem-solving-how-to-create-an-excerpt-fdb048687928
|
|
314
|
+
getExcerpt = (content, maxWords = 50, trailChars = '...') => {
|
|
315
|
+
const listOfWords = content.trim().split(' ')
|
|
316
|
+
const truncatedContent = listOfWords.slice(0, maxWords).join(' ')
|
|
317
|
+
const excerpt = truncatedContent + trailChars
|
|
318
|
+
const output = listOfWords.length > maxWords ? excerpt : content
|
|
319
|
+
return output
|
|
320
|
+
}
|
|
309
321
|
}
|
|
310
322
|
}
|
|
311
323
|
|