Add support for scope to be of type Context
to fix rendering in Liquid
#35
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR attempts to add support for the
scope
variable when it is of type Context. Without these changes, I was unable to use this plugin to generate SEO tags for my Eleventy site which uses Liquid templates.Motivation and Context
Attempting to use this plugin on an Eleventy site with Liquid templates resulted in runtime errors (snapshot below). It seems like other people have also run into this issue when attempting to use this plugin.
After some digging, I realized that the error was coming from the references to
scope.contexts[0]
in the liquidRender functions. Printingscope
to the console revealed that the object didn't have a field calledcontexts
, hence the "Cannot read property '0' of undefined" error.Click to see a snapshot of what the `scope` object looked like on my local
``` Context { scopes: [ {} ], registers: {}, sync: false, opts: { root: [ 'src/_includes', 'src' ], layouts: [ 'src/_includes', 'src' ], partials: [ 'src/_includes', 'src' ], relativeReference: true, jekyllInclude: false, cache: undefined, extname: '.liquid', fs: [Object: null prototype] { exists: [AsyncFunction: exists], readFile: [Function: readFile], existsSync: [Function: existsSync], readFileSync: [Function: readFileSync], resolve: [Function: resolve], fallback: [Function: fallback], dirname: [Function: dirname], contains: [Function: contains], sep: '/' }, dynamicPartials: true, jsTruthy: false, dateFormat: '%A, %B %-e, %Y at %-l:%M %P %z', trimTagRight: false, trimTagLeft: false, trimOutputRight: false, trimOutputLeft: false, greedy: true, tagDelimiterLeft: '{%', tagDelimiterRight: '%}', outputDelimiterLeft: '{{', outputDelimiterRight: '}}', preserveTimezones: false, strictFilters: true, strictVariables: false, ownPropertyOnly: true, lenientIf: false, globals: {}, keepOutputType: false, operators: { '==': [Function: equal], '!=': [Function: !=], '>': [Function: >], '<': [Function: <], '>=': [Function: >=], '<=': [Function: <=], contains: [Function: contains], not: [Function: not], and: [Function: and], or: [Function: or] }, outputEscape: undefined }, globals: {}, environments: { eleventy: { version: '2.0.1', generator: 'Eleventy v2.0.1', env: [Object] }, pkg: { name: 'digital-services-coalition', version: '1.0.0', description: '', main: 'index.js', scripts: [Object], repository: [Object], keywords: [], author: '', license: 'ISC', bugs: [Object], homepage: 'https://github.com/DSCoalition/dsc-11ty-cms', devDependencies: [Object], dependencies: [Object] }, title: 'Story', layout: 'layouts/story.liquid', permalink: '/story/', heroTitle: 'Answering the call by building a community.', eleventyNavigation: { key: 'Story', order: 3 }, page: { date: 2023-08-28T16:46:58.708Z, inputPath: './src/pages/story.md', fileSlug: 'story', filePathStem: '/pages/story', outputFileExtension: 'html', templateSyntax: 'liquid,md', url: '/story/', outputPath: '_site/story/index.html' }, collections: { all: [Array], boardMemberItem: [Array], orgItem: [Array] }, content: '\n' + 'I checked the LiquidJS changelog and it does look like a recent change was made in 2022 to support scopes of type
Context
.To maintain backwards compatibility while fixing the issue I just added a check to set the context to
scope.environments
(the user passed in scope for the Context type) whenscope.contexts
is undefined.How Has This Been Tested?
I added some tests for the new use case and made sure all tests passed. I confirmed that after making these changes I was able to generate SEO tags and use this plugin on my Eleventy site.
![Screen Shot 2023-10-19 at 5 51 45 PM](https://private-user-images.githubusercontent.com/5403975/276762166-e0870084-c890-4068-927e-0aac9f12c69d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk2MjY3NzMsIm5iZiI6MTcxOTYyNjQ3MywicGF0aCI6Ii81NDAzOTc1LzI3Njc2MjE2Ni1lMDg3MDA4NC1jODkwLTQwNjgtOTI3ZS0wYWFjOWYxMmM2OWQucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDYyOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA2MjlUMDIwMTEzWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NzRlYzUzNzFhNTg4MGY3NTE3MzkwZTc3ZTAxZTg4Nzc3OGI1YzczMjc4YzdiYWQwYWY3OTIzYjdjODI0MzQ0MyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.OY168wFPJN1lIzvO_D0p7ZZ44ouHVNRmi6J7Ux_XXTk)
Types of Changes
- [ ] New feature (non-breaking change that adds functionality)- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)Checklist:
- [ ] My change requires a change to the documentation.- [ ] I have updated the documentation accordingly.Thanks for your work creating and maintaining this plugin! 馃槃