From dffe16452dd5563459dfcd72162cd80da28827be Mon Sep 17 00:00:00 2001 From: Huntedpix Date: Wed, 25 Jan 2017 15:40:04 +0100 Subject: [PATCH 1/4] Merge data from data file and src file Merge data from data file and src file via yaml front matter --- tasks/assemble.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tasks/assemble.js b/tasks/assemble.js index 44f6798..33a3d91 100644 --- a/tasks/assemble.js +++ b/tasks/assemble.js @@ -492,7 +492,8 @@ module.exports = function(grunt) { data = options.data, pages = options.pages, collections = options.collections, - context = {}; + context = {}, + datas = {}; grunt.verbose.writeln('Variables loaded'); @@ -507,7 +508,9 @@ module.exports = function(grunt) { options.pages = undefined; options.layout = undefined; options.collections = undefined; - context = _.extend({}, context, assemble.util.filterProperties(options), data, pageContext); + + datas = _.merge(data, pageContext); + context = _.extend({}, context, assemble.util.filterProperties(options), datas); options.data = data; options.pages = pages; options.collections = collections; @@ -544,7 +547,9 @@ module.exports = function(grunt) { options.pages = undefined; options.layout = undefined; options.collections = undefined; - context = _.extend({}, context, assemble.util.filterProperties(options), layout.data, data, pageContext); + datas = _.merge(data, pageContext); + context = _.extend({}, context, assemble.util.filterProperties(options), layout.data, datas); + options.data = data; options.pages = pages; options.collections = collections; From f9f8d1c17745fe62b5d38a696944a6419d817922 Mon Sep 17 00:00:00 2001 From: Huntedpix Date: Thu, 31 Aug 2017 15:59:09 +0200 Subject: [PATCH 2/4] Fix leaked informations between pages As the documentation of lodash explain it, the first argument for the merge function is the destination object. (https://lodash.com/docs/2.4.2#merge) So the first argument was changing and it was not the behavior we excepted. --- tasks/assemble.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/assemble.js b/tasks/assemble.js index f37cdf1..2940c2a 100644 --- a/tasks/assemble.js +++ b/tasks/assemble.js @@ -488,7 +488,7 @@ module.exports = function(grunt) { options.layout = undefined; options.collections = undefined; - datas = _.merge(data, pageContext); + datas = _.merge({}, data, pageContext); context = _.extend({}, context, assemble.util.filterProperties(options), datas); options.data = data; options.pages = pages; @@ -526,7 +526,7 @@ module.exports = function(grunt) { options.pages = undefined; options.layout = undefined; options.collections = undefined; - datas = _.merge(data, pageContext); + datas = _.merge({}, data, pageContext); context = _.extend({}, context, assemble.util.filterProperties(options), layout.data, datas); options.data = data; From 941ed9165c4bca22a8ed5fbb5fe745ed7b6fba8c Mon Sep 17 00:00:00 2001 From: Huntedpix Date: Fri, 1 Sep 2017 10:37:56 +0200 Subject: [PATCH 3/4] Revert "Fix leaked information between pages" This reverts commit 3714f037a791f651d043edb81a3881c3428b5c03. --- tasks/assemble.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/assemble.js b/tasks/assemble.js index 2940c2a..f37cdf1 100644 --- a/tasks/assemble.js +++ b/tasks/assemble.js @@ -488,7 +488,7 @@ module.exports = function(grunt) { options.layout = undefined; options.collections = undefined; - datas = _.merge({}, data, pageContext); + datas = _.merge(data, pageContext); context = _.extend({}, context, assemble.util.filterProperties(options), datas); options.data = data; options.pages = pages; @@ -526,7 +526,7 @@ module.exports = function(grunt) { options.pages = undefined; options.layout = undefined; options.collections = undefined; - datas = _.merge({}, data, pageContext); + datas = _.merge(data, pageContext); context = _.extend({}, context, assemble.util.filterProperties(options), layout.data, datas); options.data = data; From a519b3d02126182d0a8b6d269e161d382003173d Mon Sep 17 00:00:00 2001 From: Huntedpix Date: Mon, 5 Nov 2018 17:12:28 +0100 Subject: [PATCH 4/4] Allow documentation for pattern --- tasks/assemble.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tasks/assemble.js b/tasks/assemble.js index f37cdf1..b335ae2 100644 --- a/tasks/assemble.js +++ b/tasks/assemble.js @@ -488,7 +488,7 @@ module.exports = function(grunt) { options.layout = undefined; options.collections = undefined; - datas = _.merge(data, pageContext); + datas = _.merge({}, data, pageContext); context = _.extend({}, context, assemble.util.filterProperties(options), datas); options.data = data; options.pages = pages; @@ -526,7 +526,7 @@ module.exports = function(grunt) { options.pages = undefined; options.layout = undefined; options.collections = undefined; - datas = _.merge(data, pageContext); + datas = _.merge({}, data, pageContext); context = _.extend({}, context, assemble.util.filterProperties(options), layout.data, datas); options.data = data; @@ -656,6 +656,19 @@ module.exports = function(grunt) { layout = grunt.file.read(layout); layout = layout.replace(/\{{>\s*body\s*}}/, function() { return defaultLayout; }); + + // As we have documentation include into the pattern we need to extract the pattern content. + // Sometimes we have documenation for AMO doc and for HTML doc. + var part = /([^]*)---(?:[^]*)---(?:[^]*)---(?:[^]*)/g.exec(layout) + if (part !== null) { + layout = part[1] + } else { + // But sometimes there is only documenation for the AMO. + part = /([^]*)---(?:[^]*)---(?:[^]*)/g.exec(layout) + if (part !== null) { + layout = part[1] + } + } } var parsedLayout = matter(layout, assemble.options.matter);