From 7f741d9b3ae38ff3dc3730c7d161668cc2ee869a Mon Sep 17 00:00:00 2001 From: Benjamin Canac Date: Wed, 5 Aug 2020 11:07:48 +0200 Subject: [PATCH] fix(content): options were not forwarded in plugin static lazy --- packages/content/templates/plugin.static.js | 4 ++-- packages/content/templates/plugin.static.lazy.js | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/content/templates/plugin.static.js b/packages/content/templates/plugin.static.js index 5fd8a4c3d..4e0d12270 100644 --- a/packages/content/templates/plugin.static.js +++ b/packages/content/templates/plugin.static.js @@ -8,7 +8,7 @@ Vue.component(NuxtContent.name, NuxtContent) export default (ctx, inject) => { let $$content = null - let $content = (...contentArgs) => { + const $content = (...contentArgs) => { if ($$content) { return $$content(...contentArgs) } @@ -23,7 +23,7 @@ export default (ctx, inject) => { 'surround' ] const mock = {} - let toCall = [] + const toCall = [] for (const key of keys) { mock[key] = (...args) => { toCall.push({ key, args }) diff --git a/packages/content/templates/plugin.static.lazy.js b/packages/content/templates/plugin.static.lazy.js index 923411614..42671c944 100644 --- a/packages/content/templates/plugin.static.lazy.js +++ b/packages/content/templates/plugin.static.lazy.js @@ -18,16 +18,20 @@ const $content = function () { } }) + const { text = false, deep = false } = options + const path = `/${paths.join('/').replace(/\/+/g, '/')}` const isDir = !path || !!dirs.find(dir => dir === path) // Look for dir or path - const query = isDir ? { dir: options.deep ? { $regex: path } : path } : { path } + const query = isDir ? { dir: deep ? { $regex: new RegExp(`^${path}`) } : path } : { path } // Postprocess to get only first result (findOne) const postprocess = isDir ? [] : [data => data[0]] return new QueryBuilder({ query: items.chain().find(query, !isDir), - postprocess + path, + postprocess, + text }, { fullTextSearchFields: <%= JSON.stringify(options.fullTextSearchFields) %> })