Jekyll: Can the included snippet know where it comes from?

We have a large document posted online using the jekyll and github pages.

When we first did this, we probably overdid it a bit, breaking it down into small pieces of content. We have used it include

everywhere. The goal was that a lot of people could contribute to this, but its structure is a bit complex.

I want you to be able to put a link to the file in the github repository after each section of the included content. This will allow people to jump straight to the part they want to edit.

Is it possible to do something like:

<span class="edit-link">{{whereIwasIncludedFrom}}</span>

      

To make it explicit if the file is in

_includes
    A
      my_file.md

      

then the snippet will give

_includes/A/my_file.md

I am currently achieving this by including it in a two step process:

{% include A/template.markdown box-type="definition" value="A/B/markdown.md" %}

      

calls this:

<div markdown="1" class="box-{{ include.box-type }}">
[](https://github.com/bvn-architecture/styleguide/blob/gh-pages/_includes/{{ include.value }}){:.edit-link title="Edit this section" target="_blank"}

{% include {{ include.value }} %}

</div>

      

Which works fine, but a lot of unnecessary input and complexity if possible to get it through a variable.

+3


source to share


1 answer


You know where the fragment is, why can't you just add a reference to the fragment itself instead of the parent?

_posts> 2015-11-24-Alphabet.markdown

{% include alphabet/letter-a.markdown %}

      

_includes> alphabet> letter-a.markdown



{% assign child_file = alphabet/alphabet-markdown/a/a-1-key.markdown %}
{% include child_file %}

      

_includes> alphabet> alphabet-markdown> a> a-1-key.markdown

<span class="transform-to-uppercase">Cover sheet</span>
[Link to a file](https://github.com/bvn-architecture/styleguide/gh-pages/{{ child_file | relative_url }})

      

0


source







All Articles