how to read md file in jekyll - jekyll

i have file as : _nearby/2022-10-03-ancient-places.md
and this file contains as below:
---
layout: nearby
title: Ancient places
seo_description: As we live between Chitrakoot and Kaushambi, there are numerous
ancient locations here.
date: 2022-10-03T04:56:39.531Z
image: /assets/uploads/chitrakoot_0.jpg
categories:
- Ancient places
nearbyplaces:
- title: Rishiyan ashram
description: प्राकृतिक सौन्दर्य से ओत-प्रोत आश्रम जिसे वर्तमान में ऋषियन आश्रम
के नाम से जानते हैं,यह उत्तर प्रदेश की धर्मनगरी के नाम से विख्यात्
चित्रकूट के मऊ तहसील से 14 किमी. की दूरी पर बरहा कोटरा गांव में स्थित है।
वास्तव में इस आश्रम का नामऋषियननहीं था। एक किवदन्ति के अनुसार, ‘बरहा’ गांव
के जंगल में 84000 ऋषियों ने तपस्या की थी जिससे इस स्थान का नाम पहले
‘‘ऋषिवन’’ पड़ा तथा बाद में यह अपभ्रंस होकर ‘‘ऋषियन आश्रम’’ हो गया।
entry_fee: Free
timings: 10 AM - 6PM
best_time: Always
link: ""
map: https://goo.gl/maps/WDn1hp3BknuXiTSM8
image: /assets/uploads/2022-06-29.jpg
- title: Alha Ghat
description: Alha Ghat
image: /assets/uploads/2022-08-17.jpg
entry_fee: 20 Rupee
timings: 10AM - 5PM
best_time: Rainy and Winters
map: https://goo.gl/maps/715vnrMg9x958De47
---
As we live between Chitrakoot and Kaushambi, there are numerous ancient locations here.
i am want to read variable from this file and want to use in any page.
my try:
my_variable: nearby/2022-10-03-ancient-places.md
{% my_variable.image %}
but its showing error
please help me.

See https://jekyllrb.com/docs/variables/ for a reference to all variables available in Jekyll:
Page: Page specific information + the front matter. Custom variables set via the front matter will be available here.
Use {{ page.image }} to show the image URL but use ![alt text]({{ page.image }}) to show the image.
See https://www.markdownguide.org/cheat-sheet/ for markdown syntax examples.

Related

Using liquid to sort posts by the latest date(latest(posted_date, updated_date))

I'm writing a site in Jekyll, which uses Liquid.
I have ymal for pages , like this:
---
title: Mytitle
posted: 2020-06-29
updated: 2020-07-29
....
---
And I have some posts, as follows
{
title: title1
posted: 2020-06-29
updated: 2020-07-29
},
{
title: title2
posted: 2020-07-05
},
{
title: title 3
posted: 2020-07-01
updated: 2020-07-20
},
{
title: title 4
posted: 2020-07-22
},
I expect the order of posts which is sorted by the latest date, i.e. latest(posted, updated).
liquid seems cannot sort by custom function? Can someone tell me what to do?
Thanks
By default site.posts are sorted by the date property (newest fist), which you called posed. So you may want to rename it to date to make your life easier.
For custom sorting you can use the Liquid sort filter, which takes one argument.
So if you want to sort by updated instead, you can do that with:
{% assign my_sorted_list = site.posts | sort:"updated" %}
{% for post in my_sorted_list %}
...
{% endfor %}
You'll need to set the updated property then for every post or use a custom hook as explained here.

Jekyll Collection Filter

I'm trying to grab a specific item from a collection called 'content' based on an id using where_exp, but for the life of me I can't get it to work. Here's the code:
filter:
{% assign var = site.content | where_exp:"content", "content.id == 'testId'" | first %}
frontmatter for post in collection:
---
layout: content
title: "This is the title"
image: "assets/photos/image.jpg"
id: "testId"
---
html:
<img class="full-width-poto" src="{{ var.image }}">
I can't figure out what I'm doing wrong.
Note, I've been referring to this post: Getting a specific item from a collection in Jekyll and https://riptutorial.com/jekyll/example/28446/accessing-a-specific-collection-item
Ok, I figured out my problem, just in case someone comes across this. For some reason I can't use the key 'id' for this...it must be hardcoded for something else.
I swapped in 'myid' and it works fine now...

cant find the error in jekyll... "did not find expected key while parsing a block mapping"

I'm a relative newbee to jekyll and liquid. I had this running a while ago but messed it up somehow, without a backup. When finding something the error just shifts to somewhere else... Please take a look.
Here is my code:
---
title: Gallery
layout: gallery
heroimage: /img/hero-image-gallery.jpg
imgsize: small
masonry:
itemsize: 33.333%
categories:
- Objects
- People
- Places
images:
- title: one
thumb: img/gallery-image-one.jpg
big: img/gallery-image-one.jpg
categories:
- People
- Places
- title: two
thumb: img/gallery-image-two.jpg
big: img/gallery-image-two.jpg
categories:
- Objects
- Places
- title: three
thumb: img/gallery-image-three.jpg
big: img/gallery-image-three.jpg
categories:
- People
- title: four
thumb: img/gallery-image-four.jpg
big: img/gallery-image-four.jpg
categories:
- Objects
- Places
- title: five
thumb: img/gallery-image-five.jpg
big: img/gallery-image-five.jpg
categories:
- Objects
- title: eight
thumb: img/gallery-image-eight.jpg
big: img/gallery-image-eight.jpg
categories:
- Places
- title: seven
thumb: img/gallery-image-seven.jpg
big: img/gallery-image-seven.jpg
categories:
- Places
- title: six
thumb: img/gallery-image-six.jpg
big: img/gallery-image-six.jpg
categories:
- Objects
- People
- title: bla
thumb: img/gallery-image-six.jpg
big: img/gallery-image-six.jpg
categories:
- Objects
- People
---
<div class="portfolioFilter">
Alle
{% for cat in page.categories %}
{{cat}}
{% endfor %}
</div><br>
<div class="grid">
<div class="grid-sizer"></div>
{% for item in page.images %}
<div class="grid-item{% for cat in item.categories %} {{cat | slugify}}{% endfor %}">
<a class="example-image-link" href="{{item.big}}" data-lightbox="example-set" ><img src="{{item.thumb}}"/></a>
</div>
{% endfor %}
</div>
And here is the error I'm getting:
Error reading file /Users/maxborm/Desktop/lukawebsite/gallery.html: (<unknown>): did not find expected key while parsing a block mapping at line 2 column 1
Thanks in advance.
Indentation is very important in Liquid, and you have to make sure you have the right amount of spaces when declaring collections.
In your case, you have an extra space before - title: bla which is causing the error.
i.e. you have:
- title: bla
when you should have:
- title: bla

Mediawiki: Displaying a List does not work with infobox template

I created a new template and want to display a list inside my newly coded infobox. To get this working I was told to change the code like in this German tutorial.
This is how my template Infobox Music currently looks like:
|-
{{#if: {{{Sänger<includeonly>|</includeonly>}}} |
{{#ifeq: {{Str left|{{{Sänger}}} }} | *
|{{!}} style="vertical-align:top;" {{!}}
'''Sänger/in'''
{{!}}
{{{Sänger}}}
|{{!}} '''Sänger/in'''
{{!}} {{{Sänger}}}
}}
}}
In order to build a new list I edited the source code in a seperate Wiki entry like this:
{{Infobox_Music
|Sänger =
* Lady Gaga
* Michael Jackson
}}
Unfortunately, when using both of these settings my list gets displayed with the first item having an * at the beginning just as usual. Here is how it looks in HTML:
<tr>
<td> <b>Sänger/in</b>
</td>
<td> * Lady Gaga
<ul><li>Michael Jackson</li></ul>
</td></tr>
Did I miss something? What does the line {{#ifeq: {{Str left|{{{Sänger}}} }} mean?
UPDATE: Here is a snippet of my previous Infobox Music template:
{{Infobox Music
|-
{{#if: {{{Sänger|}}} | {{!}} '''Sänger/in''' {{!!}} {{{Sänger}}} }}
}}
{{Str left|{{{Sänger}}} }} is the first character of the Sänger parameter (see {{Str left}}). {{#ifeq: {{Str left|{{{Sänger}}} }} | * | ... is some kind of horrible hack to use a different layout when the parameter is a list; not trying to replicate that will help you preserve your sanity.
* will only be interpreted as a list when preceded by a newline. You can prevent stripping of the leading whitespace from the template parameter by doing something like
|Sänger = <!---->
* Lady Gaga
or you can make sure that in the template {{{Sänger}}} is preceded by a newline.

Sorted Map Iteration in Go Templates?

I'm building a website in Go, using the Hugo static site generator. What I'm trying to do is build a dynamic navigation bar for my web pages.
Here's what I'm doing:
In my config.yml file, I've defined a Map of links that I'd like to appear in my navbar -- here's what this file looks like:
baseurl: "https://www.rdegges.com/"
languageCode: "en-us"
title: "Randall Degges"
params:
navLinks: {"Twitter": "https://twitter.com/rdegges", "Facebook": "https://www.facebook.com/rdegges", "Google+": "https://plus.google.com/109157194342162880262", "Github": "https://github.com/rdegges"}
So, I've also got an index.html template in Hugo that contains a navbar which looks like this:
<nav>
<ul>
{{ range sort $title, $link := .Site.Params.navLinks }}
<li>{{ $title }}</li>
{{ end }}
</ul>
</nav>
This above code works correctly, with one exception: I'd like to order the results of my links instead of having them randomly ordered each time.
I know that Maps are not inherently structured in Go -- but is there a way to retain the original ordering of my navigation elements in some way?
Thanks for the help!
Go templates sort maps by key. If you want to force a specific order, then use a slice:
Here's the YAML:
baseurl: "https://www.rdegges.com/"
languageCode: "en-us"
title: "Randall Degges"
params:
navLinks:
- title: Twitter
url: https://twitter.com/rdegges
- title: Facebook
url: https://www.facebook.com/rdegges
... and the template:
<nav>
<ul>
{{ range $link := .Site.Params.navLinks }}
<li>{{ $link.title }}</li>
{{ end }}
</ul>
</nav>