From c9ad9bf8da8fb899db9d042ee8d3c609cffe0464 Mon Sep 17 00:00:00 2001 From: tomjohnson1492 Date: Mon, 31 Oct 2016 23:23:24 -0700 Subject: [PATCH] fixed examples in yaml tutorial --- .DS_Store | Bin 14340 -> 16388 bytes _config.yml | 2 +- pages/mydoc/mydoc_yaml_tutorial.md | 105 +++++++++++++++++++---------- 3 files changed, 71 insertions(+), 36 deletions(-) diff --git a/.DS_Store b/.DS_Store index 80ac8bdd2cd148849f75fa82088048a157576aa6..e5c036b2b63092648f60bbda705e7cba21afbcdb 100644 GIT binary patch delta 618 zcmZoEXlYAvkp;C~ixw|gx@`H1gGVOkE6KAS1scJ+d8cqT(_}?yvB^rT z(Ll=?7=aiFIJkj!iLq=}<9W)=$hTQV>^HkC8$?P1=vD?-bTZMhlXH^t^K&+zSK7r!w&!F(o?~W6W++CO2(k_=H2H$I!sHmiT}+HlnRVVM)I5oK3=>-5* ChMqnE delta 413 zcmZo^U~DN+VPIfjbSh0TWMD7=GC6=4L<{gRFtBhjFem_N28M|$+M>!pni(j;z>vt0 z&XCGboKsv@uvw5}G4o^t85UMXpft9ZeHoReE6xht8u#kxno0+@VCR@siOkSoq-9Vzc+SFV}!O+N{R!5=Q(7?b{ zN5Rb0ytY=5v5JF3TGQ0gH?p9%YtiB*OP4KQaroF|13`JM<3LN98Il=_8H(XfM+hOg zpK-DPi}d6$f%QUWIts?-rXV{kEe(KHm>5hJ7qr>TZ_v%Ov1B`=BrC*+20+g;xFUxw b(8uqYC-ckraxg)H-ePis%+$?ds@%)~;{RRv diff --git a/_config.yml b/_config.yml index c68a5b3..ce90d2a 100644 --- a/_config.yml +++ b/_config.yml @@ -101,4 +101,4 @@ description: "Intended as a documentation theme based on Jekyll for technical wr # the description is used in the feed.xml file # needed for sitemap.xml file only -url: http://idratherbewriting.com \ No newline at end of file +url: http://idratherbewriting.com diff --git a/pages/mydoc/mydoc_yaml_tutorial.md b/pages/mydoc/mydoc_yaml_tutorial.md index 8ca83e3..c70106f 100644 --- a/pages/mydoc/mydoc_yaml_tutorial.md +++ b/pages/mydoc/mydoc_yaml_tutorial.md @@ -7,6 +7,17 @@ sidebar: mydoc_sidebar permalink: mydoc_yaml_tutorial.html folder: mydoc --- + + + ## Overview One of the most interesting features of Jekyll is the ability to separate out data elements from formatting elements using a combination of YAML and Liquid. This setup is most common when you're trying to create a table of contents. @@ -51,21 +62,19 @@ name: **Markdown + Liquid:** -{% raw %} ```liquid -Husband's name: {{site.data.samplelist.name.husband}} - -Wife's name: {{site.data.samplelist.name.wife}} +{% raw %}

Husband's name: {{site.data.samplelist.name.husband}}

+

Wife's name: {{site.data.samplelist.name.wife}}

{% endraw %} ``` -{% endraw %} Notice that in order to access the data file, you use `site.data.samplelist`. `mydoc` is the folder, and `samplelist` is the name of the YAML file. **Result:** -Husband's name: {{site.data.samplelist.name.husband}} - -Wife's name: {{site.data.samplelist.name.wife}} +
+

Husband's name: {{site.data.samplelist.name.husband}}

+

Wife's name: {{site.data.samplelist.name.wife}}

+
## Example 2: Line breaks @@ -88,20 +97,22 @@ block: | **Markdown:** ```liquid -**Feedback** -{{site.data.samplelist.feedback}} +{% raw %}

Feedback

+

{{site.data.samplelist.feedback}}

-**Block** -{{site.data.samplelist.block}} +

Block

+

{{site.data.samplelist.block}}

{% endraw %} ``` **Result:** -**Feedback** -{{site.data.samplelist.feedback}} +
+

Feedback

+

{{site.data.samplelist.feedback}}

-**Block** -{{site.data.samplelist.block}} +

Block

+

{{site.data.samplelist.block}}

+
The right angle bracket `>` allows you to put the value on the next lines (which must be indented). Even if you create a line break, the output will remove all of those line breaks, creating one paragraph. @@ -120,19 +131,24 @@ bikes: **Markdown + Liquid:** -{% raw %} + ```liquid +{% raw %}
    {% for item in site.data.samplelist.bikes %} -* {{item.title}} +
  • {{item.title}}
  • {% endfor %} +
{% endraw %} ``` -{% endraw %} **Result:** +
+
    {% for item in site.data.samplelist.bikes %} -* {{item.title}} +
  • {{item.title}}
  • {% endfor %} +
+
Here we use a "for" loop to get each item in the bikes list. By using `.title` we only get the `title` property from each list item. @@ -165,14 +181,17 @@ salesteams: {% endraw %} **Result:** + +
{% for item in site.data.samplelist.salesteams %}

{{item.title}}

    -{% for entry in item.subitems %} +{% for entry in item.subfolderitems %}
  • {{entry.location}}
  • {% endfor %}
{% endfor %} +
Hopefully you can start to see how to wrap more complex formatting around the YAML content. When you use a "for" loop, you choose the variable of what to call the list items. The variable you choose to use becomes how you access the properties of each list item. In this case, I decided to use the variable `item`. In order to get each property of the list item, I used `item.subitems`. @@ -218,6 +237,7 @@ toc: **Result:** +
{% for item in site.data.samplelist.toc %}

{{item.title}}

    @@ -226,6 +246,7 @@ toc: {% endfor %}
{% endfor %} +
This example is similar to the previous one, but it's more developed as a real table of contents. @@ -248,7 +269,9 @@ myref: *hello **Result:** +
{{ site.data.samplelist.myref }} +
This example is notably different. Here I'm showing how to reuse content in YAML file. If you have the same value that you want to repeat in other mappings, you can create a variable using the `&` symbol. Then when you want to refer to that variable's value, you use an asterisk `*` followed by the name of the variable. @@ -270,15 +293,14 @@ about: **Markdown:** -{% raw %} ``` -{{ site.data.samplelist.about[0] }} +{% raw %}{{ site.data.samplelist.about[0] }}{% endraw %} ``` -{% endraw %} **Result:** - +
{{ site.data.samplelist.about[0] }} +
You can see that I'm accessing one of the items in the list using `[0]`. This refers to the position in the array where a list item is. Like most programming languages, you start counting at zero, not one. @@ -309,8 +331,9 @@ numbercolors: {% endraw %} **Result:** - +
{{ site.data.samplelist.numbercolors[0].properties }} +
This example is similar as before; however, in this case were getting a specific property from the list item in the zero position. @@ -344,45 +367,57 @@ mypages: **Markdown + Liquid:** -{% raw %} + ```liquid +{% raw %}
    {% for sec in site.data.samplelist.mypages %} {% if sec.audience == "writers" %} -* {{sec.url}} +
  • {{sec.url}}
  • {% endif %} {% endfor %} -``` +
{% endraw %} +``` + **Result:** - +
+
    {% for sec in site.data.samplelist.mypages %} {% if sec.audience == "writers" %} -* {{sec.url}} +
  • {{sec.url}}
  • {% endif %} {% endfor %} +
+
This example shows how you can use conditions in order to selectively get the YAML content. In your table of contents, you might have a lot of different pages. However, you might only want to get the pages for a particular audience. Conditions lets you get only the items that meet those audience attributes. Now let's adjust the condition just a little. Let's add a second condition so that the `audience` property has to be `writers` and the `product` property has to be gizmo. This is how you would write it: -{% raw %} + ```liquid +{% raw %}
    {% for sec in site.data.samplelist.mypages %} {% if sec.audience == "writers" and sec.product == "gizmo" %} -* {{sec.url}} +
  • {{sec.url}}
  • {% endif %} {% endfor %} +
{% endraw %} ``` -{% endraw %} + And here is the result: +
+
    {% for sec in site.data.samplelist.mypages %} {% if sec.audience == "writers" and sec.product == "gizmo" %} -* {{sec.url}} +
  • {{sec.url}}
  • {% endif %} {% endfor %} +
+
## More resources