jekyll markdownify not working like i thought it would - jekyll

I'm trying to work off a Jekyll template:
https://github.com/nathanrooy/Clean-and-Simple-Jekyll-Theme
I want to modify the About, but when I edit the text in Index.md:
https://github.com/nathanrooy/Clean-and-Simple-Jekyll-Theme/tree/master/about
it doesn't parse the markdown, I just wind up with the markdown as regular text in the result. I've tried using markdwonify with no luck, i.e:
{% capture m %}I am an associate professor of [electrical engineering](http://www.ee.cooper.edu) at [The Cooper Union](http://www.cooper.edu) {% endcapture %}{{ m | markdownify }}
Results in:
{% capture m %}I am an associate professor of electrical engineering at The Cooper Union {% endcapture %}{{ m | markdownify }}
In my resulting webpage.
Is there anyway I can get Jekyll to parse the markdown in this page?

Related

Jekyll filter to remove pages from site.pages based on page.url?

While generating a Google site map for my (non-github) Jekyll site, I would like to exclude certain files based on the page URL (or file name). In shell-speak, something like
site.pages | grep -v forbidden_name
In Liquid, I imagine a signature something like
site.pages | exclude 'url', forbidden_name
In a related note, is there a catalog of the standard, built-in filters, tags, and generator? Something a bit handier than grep -Rl register_filter ~/.rvm/gems?
You can try something like
{% for p in site.pages %}
{% if p.url contains 'ca' %}
{% comment %}Do nothing{% endcomment %}
{% else %}
{{ p.title }}
{% endif %}
{% endfor %}
A little hacky an case unsensitive and no wild card.
I've made a list of tags and filters that works on Github.

How to output settings.html json data into a query in shopify

I am attempting to output a name of a collection from the json data from the customize page of Shopify theme. I can do this fine when its on its own.
For Example:
{{ settings.collection1 }}
However I want it in a query and am not sure how to do this. Where the {{settings.collection1 is I want to output the collection name and have the products be outputted in that collection but currently all that happens is the collection name itself is outputted.
{% for product in collections.{{settings.collection1}}.products %}
{% capture productLink %}{{ product.url }}{% endcapture %}
{{product.title}}
{% endfor %}
Thanks!
Looked into the templating documentation, turns out I needed use square brackets inside of a tag when using a object.
{% for product in collections.[[settings.collection1]].products %}
{% capture productLink %}{{ product.url }}{% endcapture %}
{{product.title}}
{% endfor %}
Like This
[[settings.collection1]
{{ ... }} is used for output. You can access a collection with dot notation or square brackets. For example, these 2 lines do the same thing:
collections.frontpage.products
collections['frontpage'].products
If you want to get the collection name from the settings object, the square bracket notation is the one you'll need to use:
collections[settings.collection1].products

Post index for posts with several conditionals (categories, language, tags) in Jekyll

I'd like to have several post-indexes (indices?) on my Jekyll-powered website for several categories and languages, meaning more than one conditional.
My posts have YAML frontmatter including:
categories:
- research
- blog
lang: en
Now I'd like a post index, for, say all research posts in english.
I can do:
{% for post in site.posts %}
{% if post.lang == 'en' and post.categories contains 'research' %}
{{ post.title }}
{% endif %}
{% endfor %}
That, however, screws up such niceties as limits and sort by year etc. For limiting the number of posts (etc.), Jekyll still seems to be looking at the whole list of posts, not just for whom the conditional applies.
Something like this pseudocode would be ideal:
{% for post in site.posts where post.lang == 'en' and post.categories contains 'research' %}
Any thoughts?
Ps.: I can't use any plugins; want it to be GH Pages compatible.
Pps.: I know I could use language as a category, but that doesn't feel right -- these are different pieces of information.
I believe you can do this:
{% assign resindex = site.posts | where: "category", "research", | where: "lang", "en" | sort: "title" %}
{% for post in resindex limit:4 %}
<div>
<p>{{ post.title | truncate: 52 }}</p>
</div>
{% endfor %}
Though I am fairly confused by the use of category and categories and when you can/should use them. For my example category worked, but in my front matter I have: category: mycategory and am only using one. But the rest of the code should work, and you can limit and sort.

Strip url to 1 word in Jekyll

I am building a Jekyll blog, and I have come across an issue with permalinks.
My permalinks to blog posts are set like this in
_config.yml:
permalink: /:page/:categories/:title
It outputs like this when navigating to a blog post:
http://localhost:4000/blog/travel/netherlands-trip-prequesites/
I have some static pages in the site: Blog, Travel
The variable page.url outputs this url: /blog/travel/netherlands-trip-prequesites
The code my navigation bar uses to highlight the current page (giving it an "active" class):
{% assign url = page.url|remove:'index.html' %}
{% for nav in site.navigation %}
{% if nav.href == url %}
<li class="active">{{nav.name}}</li>
{% else %}
<li>{{nav.name}}</li>
{% endif %}
{%endfor%}
It works great when navigating to static pages, however when I click a blog post it doesn't highlight the correct static page. (ex.: If i navigate to a blog post with the url /blog/smth/title it should automatically highlight "Blog" in my navigation. When I navigate to /travel/smth/title it should highlight "Travel")
What I'd like to do is to strip down the output of page.url to its first part. For example I'd like to stip the following output
/blog/travel/netherlands-trip-prequesites
down to
/blog/
Why? So I can use it to check which static page it belongs to and highlight it accordigly.
The easiest way is to use split:
{{ page.url | split:'/' | first }}
That will give you the URL content up to the first / character.
I managed to solve it with three filters:
{{ page.url | replace:'/',' ' | truncatewords: 1 | remove:'...' }}
page.url outputs: /page/cat/title, then replace removes the forward slashes producing: page cat title. truncatewords truncates the string down to one word, producing: page... (for some reason three dots gets inserted after the remaining word). After all this I only needed to remove those dots with remove and voilá, my final string: page.
Hope this helps someone.
The answer provided by PeterInvincible was almost perfect, however, there's no need to get piping to remove involved...
The following also will produce desired output
{{ page.url | replace:'/',' ' | truncatewords: 1,"" }}
And to save it to a variable use capture redirection
{{ capture url_base }}{{ page.url | replace:'/',' ' | truncatewords: 1,"" }}{{ endcapture }}
Which can be called via {{url_base}} or mixed with other processing calls.
Also for file paths instead of URLs page.dir works well if you're not using permalink settings for layout, check the gh-pages branch (specifically _includes/nav_gen.html for functional, though rough'round the edges, example) for hosted examples of similar code examples related to liquid syntax and other magic.
Edits & Updates
The above linked script is now live/mostly-working/modular and auto-serving parsed sub-directories viewed currently at the related https://s0ands0.github.io/Perinoid_Pipes/ project site providing examples of recursive parsing of directories. Including and modding for nearly any theme should be possible just check the commented section at the top for currently recognized commands that maybe passed at inclusion call... on that note of inclusion and modularization here's how to turn the above example code for directory parsing into a function
{% comment %}
# Save this to _include/dir_path_by_numbers.html
# import with the following assigning arguments if needed
# {% include dir_path_by_numbers.html directory_argument_path="blog" directory_argument_depth=1 %}
{% endcomment %}
{% assign default_arg_directory_path = page.url %}
{% assign default_arg_directory_depth = 1 %}
{% if directory_argument_path %}
{% assign directory_to_inspect = directory_argument_path %}
{% else %}
{% assign directory_to_inspect = default_arg_directory_path %}
{% endif %}
{% if directory_argument_depth %}
{% assign directory_to_inspect_depth = directory_argument_path %}
{% else %}
{% assign directory_to_inspect_depth = default_arg_directory_depth %}
{% endif %}
{% comment %}
# Defaults read and assigned now to output results
{% endcomment %}
{{ directory_to_inspect_depth | replace:'/',' ' | truncatewords: directory_to_inspect_depth,"" | remove_first: '/' | replace:' ','/' }}
The above should output directory path lengths of whatever size desired and maybe included as shown previously or if feeling adventurous try what's shown below; though for looping and recursive features look to the linked script for how I've worked around stack size restrictions.
{% capture dir_sub_path %}{{include dir_path_by_numbers.html directory_argument_path="blog" directory_argument_depth=1}}{% endcapture %}
Note above is just speculation, untested, and maybe more buggy than scripts tested and hosted publicly... in other words inspiration.
Simplest way would be using
if page.url contains
example:
<li class="{% if page.url contains '/docs/' %}current{% endif %}">
Docs

Evaluate a liquid "if" statement based on value of liquid filter

I have a custom Liquid filter I use in a Jekyll site,
{{ page.url | git_modified }}
Which generates the modification date from the git log (plugin code here).
Often I may add the additional filter to convert this to a string or XML schema, depending on context, e.g. {{ page.url | git_modified | date_to_string }}. Everything is hunky-dory unless for some reason my git_modified filter fails to return a time object for some post. In that case, I am trying to write a decent fail condition but cannot quite figure this out.
I'd like to just wrap my call in a liquid if statement to check if the variable is defined first:
{% if defined?( {{ page.url | git_modified }} %}
But I don't seem to be able to use Liquid tags ({{) inside Liquid block options ({%, %}). I thought I could get around this with Liquid capture:
{% capture page_modified %}{{ page.url | git_modified }}{% endcapture %}
{% if defined?(page_modified) %}
{{ page.url | git_modified | date_to_string }}
{% endif %}
but said variables do not seem to be available to the if statements. Any suggestions?
try doing it this way:
{% capture page_modified %}
{{ page.url }}
{% endcapture %}
{% if page_modified %}
{{ page.url }}
{% endif %}
If page_modified isn't defined, its value will be nil anyway, so just use the if construct as you would in pure Ruby. I tested here with jekyll 1.0.0.beta2 — jekyll new test, then created a file with the above code — and it worked. :)