@bookshop/eleventy-engine
Advanced tools
Comparing version
@@ -1,1 +0,1 @@ | ||
{"processes":{"113f09a7-2c59-4c40-ba6a-1265c6e3ea60":{"parent":"43d014e8-6270-4de0-b8c6-5e9d8067af6a","children":[]},"43d014e8-6270-4de0-b8c6-5e9d8067af6a":{"parent":null,"children":["113f09a7-2c59-4c40-ba6a-1265c6e3ea60","8c8d456d-99ad-45d8-943d-32875237bc34","f74df58f-e234-432f-9921-4ea3c30c4964"]},"8c8d456d-99ad-45d8-943d-32875237bc34":{"parent":"43d014e8-6270-4de0-b8c6-5e9d8067af6a","children":[]},"f74df58f-e234-432f-9921-4ea3c30c4964":{"parent":"43d014e8-6270-4de0-b8c6-5e9d8067af6a","children":[]}},"files":{},"externalIds":{}} | ||
{"processes":{"3f2df976-e41d-49a7-bd42-4bb160b631cf":{"parent":"61829513-e4d8-485e-aa88-7eae901bd75d","children":[]},"46b18750-0520-4f86-8165-448999f7c0bb":{"parent":"61829513-e4d8-485e-aa88-7eae901bd75d","children":[]},"61829513-e4d8-485e-aa88-7eae901bd75d":{"parent":null,"children":["3f2df976-e41d-49a7-bd42-4bb160b631cf","46b18750-0520-4f86-8165-448999f7c0bb","d3f13bcf-d819-48f9-8b2d-3d0aa09df90f"]},"d3f13bcf-d819-48f9-8b2d-3d0aa09df90f":{"parent":"61829513-e4d8-485e-aa88-7eae901bd75d","children":[]}},"files":{},"externalIds":{}} |
@@ -105,5 +105,6 @@ import { Liquid, Context } from 'liquidjs'; | ||
// TODO: memoize parts of this that are expensive | ||
injectInfo(props) { | ||
return { | ||
...(this.info.collections || {}), | ||
collections: this.precomputed_collections, | ||
...(this.info.data || {}), | ||
@@ -120,2 +121,22 @@ ...props, | ||
this.info = info; | ||
const collections = this.info.collections || {}; | ||
collections["all"] = []; | ||
for (const [key, val] of Object.entries(collections)) { | ||
collections[key] = val.map(item => { | ||
return { | ||
inputPath: item.path, // Maybe not relative to the right location | ||
outputPath: item.path, // Not correct | ||
fileSlug: item.url.replace(/(\/|\.[^\/]+)$/, '').replace(/^.+([^\/]+)$/, '').toLowerCase(), // Not correct | ||
url: item.url, | ||
date: item.date ? new Date(item.date) : new Date(), | ||
templateContent: "Content is not available when live editing", | ||
data: item | ||
} | ||
}); | ||
collections["all"] = [...collections["all"], ...collections[key]]; | ||
} | ||
this.precomputed_collections = collections; | ||
} | ||
@@ -142,2 +163,8 @@ | ||
try { | ||
// Template values might have been parenthesised for parsing, | ||
// so we remove outer parentheses. | ||
if (/^\([\s\S]+\)$/.test(str)) { | ||
str = str.replace(/^\(|\)$/g, ''); | ||
} | ||
str = str.replace(/\n/g, ''); // TODO: Are there any cases where this breaks the eval? | ||
const ctx = new Context(); | ||
@@ -144,0 +171,0 @@ if (Array.isArray(props)) { |
@@ -29,3 +29,3 @@ import { Tokenizer } from 'liquidjs'; | ||
let [, identifier, value] = token.args.match(/^[\r\n\s]*([^=]+?)[\r\n\s]*=[\r\n\s]*([\s\S]+?)[\r\n\s]*$/); | ||
raw = `${raw}<!--bookshop-live context(${identifier}: ${value})-->` | ||
raw = `${raw}<!--bookshop-live context(${identifier}: (${value}))-->` | ||
} | ||
@@ -32,0 +32,0 @@ |
@@ -66,9 +66,15 @@ import test from 'ava'; | ||
const input = `{% assign a=b %}`; | ||
const expected = `{% assign a=b %}<!--bookshop-live context(a: b)-->`; | ||
const expected = `{% assign a=b %}<!--bookshop-live context(a: (b))-->`; | ||
t.is(translateLiquid(input, { expandBindSyntax: false }), expected); | ||
}); | ||
test("add live markup to complex assigns", t => { | ||
const input = `{% assign a = b | where: "a", "b" %}`; | ||
const expected = `{% assign a = b | where: "a", "b" %}<!--bookshop-live context(a: (b | where: "a", "b"))-->`; | ||
t.is(translateLiquid(input, { expandBindSyntax: false }), expected); | ||
}); | ||
test("add live markup to local assigns", t => { | ||
const input = `{% local a=b %}`; | ||
const expected = `{% local a=b %}<!--bookshop-live context(a: b)-->`; | ||
const expected = `{% local a=b %}<!--bookshop-live context(a: (b))-->`; | ||
t.is(translateLiquid(input, { expandBindSyntax: false }), expected); | ||
@@ -75,0 +81,0 @@ }); |
{ | ||
"name": "@bookshop/eleventy-engine", | ||
"packageManager": "yarn@3.0.0", | ||
"version": "3.0.0-beta.3", | ||
"version": "3.0.0-beta.4", | ||
"description": "Bookshop frontend Eleventy renderer", | ||
@@ -30,3 +30,3 @@ "type": "module", | ||
"dependencies": { | ||
"@bookshop/helpers": "3.0.0-beta.3", | ||
"@bookshop/helpers": "3.0.0-beta.4", | ||
"esbuild": "^0.13.10", | ||
@@ -33,0 +33,0 @@ "liquidjs": "9.28.0", |
27209
6.24%487
6.33%+ Added
- Removed