Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow to reference (Jekyll) variables in YAML files #8783

Closed
keunes opened this issue Aug 23, 2021 · 3 comments
Closed

feat: Allow to reference (Jekyll) variables in YAML files #8783

keunes opened this issue Aug 23, 2021 · 3 comments
Labels
feature frozen-due-to-age stale Nobody stepped up to work on this issue.

Comments

@keunes
Copy link

keunes commented Aug 23, 2021

Summary

Make it possible to reference (Jekyll) variables (from the same or other files) in a given variable in YAML (configuration) files.

Motivation

My use-case is that I would like to easily and quickly record my username and server of a federated service in my site's _config file, which the theme then can use to create different variables (e.g. my username and my profile URL) based on these, in the background.

My variables in _config.yml:

author:
  mastodon_user     : keunes
  mastodon_server   : mastodon.social # instance domain without protocol (e.g. mastodon.social)

The variables created by the theme, and usable in page elements:

social-media:
  mastodon:
    handle: @{{site.author.mastodon_user}}@{{site.author.mastodon_server}}
    profile: https://{{site.author.mastodon_server}}/@{{site.author.mastodon_user}}

But I think that the ability to reference variables will enable many more options in completely different contexts.

As this is a 'basic' (not 'simple', but as in 'high-level') functionality and not enabling a specific feature (e.g. an RSS feed), I believe this should be in core (not a plugin).

Guide-level explanation

You can reference Jekyll variables in any YAML configuration file. By including a reference, its value will be 'printed' as a string or integer (depending on the source and target variables) in the new variable.

It is possible to have 'nested' references, as follows:

food-colours:
  fruit:
    kiwi: green
favourite:
  food: kiwi (which is {{food-colours.fruit.kiwi}})
section-titles:
  favourites: My current favourite food: {{favourite.food}}

If variable C references variable B, and variable B references variable A, the value of variable A will show in the value of variable C (even though variable C doesn't directly reference variable A).

Note, however, that this should not lead to vicious circles, where variables reference each-other, as here:

a: {{sum-b}} - {{sum-c}}
b: {{sum-a}} - {{sum-c}}
c: {{sum-a}} - {{sum-b}}

If such circular references occur this will lead to an error, and your site will fail to build.

Reference-level explanation

Sorry, just got started with Jekyll, so I don't know what to write here.

Drawbacks

There's extra functionality to maintain and create tests for. And this might be complex if people start making deeply nested variables with vicious circles. Creating helpful error messages that clearly indicate where a circular reference appears might be complicated (?)

Unresolved Questions

@keunes keunes added the feature label Aug 23, 2021
@jekyllbot
Copy link
Contributor

This issue has been automatically marked as stale because it has not been commented on for at least two months.

The resources of the Jekyll team are limited, and so we are asking for your help.

If this is a bug and you can still reproduce this error on the latest 3.x-stable or master branch, please reply with all of the information you have about it in order to keep the issue open.

If this is a feature request, please consider building it first as a plugin. Jekyll 3 introduced hooks which provide convenient access points throughout the Jekyll build pipeline whereby most needs can be fulfilled. If this is something that cannot be built as a plugin, then please provide more information about why in order to keep this issue open.

This issue will automatically be closed in two months if no further activity occurs. Thank you for all your contributions.

@jekyllbot jekyllbot added the stale Nobody stepped up to work on this issue. label Oct 23, 2021
@keunes
Copy link
Author

keunes commented Oct 30, 2021

I'm just starting with Jekyll so I can't tell if this could be done with hooks. And I believe ai explained the 'why' quite well. Of course, if a human has a specific question, I'd be more than happy to try and give an answer.

@jekyllbot jekyllbot removed the stale Nobody stepped up to work on this issue. label Oct 30, 2021
@jekyllbot jekyllbot added the stale Nobody stepped up to work on this issue. label Dec 30, 2021
@jekyllbot
Copy link
Contributor

This issue has been automatically marked as stale because it has not been commented on for at least two months.

The resources of the Jekyll team are limited, and so we are asking for your help.

If this is a bug and you can still reproduce this error on the latest 3.x-stable or master branch, please reply with all of the information you have about it in order to keep the issue open.

If this is a feature request, please consider building it first as a plugin. Jekyll 3 introduced hooks which provide convenient access points throughout the Jekyll build pipeline whereby most needs can be fulfilled. If this is something that cannot be built as a plugin, then please provide more information about why in order to keep this issue open.

This issue will automatically be closed in two months if no further activity occurs. Thank you for all your contributions.

@jekyll jekyll locked and limited conversation to collaborators Mar 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature frozen-due-to-age stale Nobody stepped up to work on this issue.
Projects
None yet
Development

No branches or pull requests

2 participants