ignore a line in a markdown file with Jekyll - jekyll

Is there a way to ignore a text line in a markdown document from the Jekyll engine?
On the main README.md, I have a link to my generated pages url ala,
View the [Docs as a Website](https://gitpages.mycompany.com/myrepo/) which links to our enterprise equivalent of github.io pages powered by Jekyll reading the /docs/ folder.
For obvious reasons, I would like to not show this on the pages site as the viewer is already there and it ends up in an endless loop if users were to keep clicking it.
Is there a way to have it show on the code-view readme.md but not on the rendered jekyll version?

Solution :
If you want Jekyll to skip processing lines (or even a single character) into the baked /_site/ output, use the Liquid {% comment %} tag:
{% comment %}
Character or lines for Jekyll to skip.
{% endcomment %}
Example :
Before:
Code w/o {% comment %} + HTML render
After:
Code w/ {% comment %} + HTML render
Explanation :
If a markdown.md page has Jekyll Front Matter at the top, then it will be processed by Jekyll into a markdown.html page (see Jekyll's docs for more info).
Pages processed by Jekyll can contain Liquid code (specifically Jekyll's implementation of Liquid).
Liquid features a {% comment %} tag. And it works for Jekyll.
From Liquid's documentation of the comment tag:
Comment
Allows you to leave un-rendered code inside a Liquid template. Any
text within the opening and closing comment blocks will not be
printed, and any Liquid code within will not be executed.
If Jekyll processes your markdown.md page, it will process all Liquid statements, and will totally omit the {% comment %} tag + {% endcomment %} tag + and everything in between from the output file.
The text wrapped by a {% comment %} tag does not specifically need to contain Liquid for Jekyll to exclude it. Everything inside will be omitted from the output page: e.g. <html> elements, other code, plaintext, etc.
Word of Caution :
Jekyll will still throw an error if you have improper Liquid syntax, even if it is inside a comment tag.
The following results in an error, and Jekyll will not build:
{% comment %}
Character or lines for Jekyll to skip.
{% assign abc
{% endcomment %}
To prevent this, either ensure (1) all the code inside your comment tag is valid Liquid, or (2) prevent Jekyll from evaluating the code by wrapping it inside a {% raw %} tag:
{% comment %}
{% raw %}
Character or lines for Jekyll to skip.
{% assign abc
{% endraw %}
{% endcomment %}
Then everything inside the comment will be successfully excluded from the /_site/ files Jekyll outputs.
For more information, see Liquid's documentation of the raw tag.
Alternatively:
If you just want to link from the site's GitHub repository -> to the site generated by Jekyll + GitHub Pages
Log in
Go to https://github.com/ user-or-org / repository-name
Click the "Edit" button (above "Clone or download" and below "Settings")
Add the URL to your GitHub Pages website in the 2nd text field that prompts "Website for this repository (optional)", and click "Save"
Remove the URL from your README.md

Related

Import a static HTML website to Django CMS

I have designed and coded a website (with bootstrap 4) and now I would like to import it in Django CMS so the client can edit the content.
Any tips or guide that helps me to achieve this?
Thanks a lot
You have to make it into a template and import the information itself separately. Add new template to settings.py.
If your client already has a basic template that you're editing you may simply edit his existing files and CSS. Alternatively, you may also download/import an existing template and use it as your base for editing.
The template itself will look something like this: default template: base.html,
{% load i18n %}
{% extends 'base.html' %}
{% block title %}Title Here{% endblock %}
{% block content %}
{% endblock %}
#A-creative At first you should copy Bootstrap 4 static files (css and js) into your "projectname/appname/static" dir, run "python manage.py collectstatic" and then just copy your Bootstrap-ready html into the cms using Style, Text and Snippet plugin fields (Admin > Create new page > Edit > Add plugin/block > ...). You should do it page by page.
I doubt there is a shorter way... Yeap, and your should use a standard minimalistic template as mentioned by #Patriot to avoid dealing with template issues and plugin / html issues at the same time.

jekyll cannot List posts

I am leanging jekyll with the GitHub Pages
I follow the jekyll tutorial step by step, but still cannot list the post. here is my code
<ul>
{% for post in site.posts %}
<li>
<h2>{{ post.title }}</h2>
</li>
{% endfor %}
</ul>
and I also set
future: true
the github page cannot list the post.
My github page:https://v587ygq.github.io/blog.html
My github:https://github.com/v587ygq/v587ygq.github.io
I ran your Jekyll site locally. Looks like there's unknown characters in your post that are causing build errors.
The raw content of your blog post on GitHub shows that there are two quotation marks that aren't UTF-8. fruit �C botanically a berry �C produced. For some reason those quotation marks aren't the normal ones and are causing build errors. Replace them and the site builds fine.

How to use Jekyll site.pages to generate sitemap.xml

I'm trying to use site.pages to automatically generate sitemap.xml in Jekyll (GitHub Pages), This is the sitemap.xml code I got:
---
---
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{% for page in site.pages %}
<url>
<loc>https://example.com{{ page.url | remove: 'index.html' }}</loc>
</url>
{% endfor %}
</urlset>
It's output is something similar to this:
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://example.com/samplepage.html</loc>
<!--<loc>https://example.com/samplepage</loc>-->
</url>
</urlset>
My goal is to generate a sitemap.xml without the trailing .html as in the commented line. I've tried gsub (I assumed Jekyll takes Ruby syntax: Replace words in string - ruby) but it seems either doesn't change anything or remove page.url completely.
I'd appreciate if anyone can
modify the Jekyll syntax so that it generates URLs without the trailing .html.
explain the syntax of | remove: 'index.html' (which removes the URL https://example.com/index.html from the generated sitemap.xml).
I'm very unfamiliar with Jekyll so apologies if the question seems trivial.
Jekyll uses Liquid to process templates. The pipe syntax is a Liquid filter:
Filters are simple methods. The first parameter is always the output of the left side of the filter. The return value of the filter will be the new left value when the next filter is run. When there are no more filters, the template will receive the resulting string.
remove is one of the standard Liquid filters, so the Jekyll documentation does not list it.
If you have this file in your root folder, the page URL is straightforward:
samplepage.html # https://example.com/samplepage.html
Instead, if you have:
samplepage/
index.html # https://example.com/samplepage/index.html
# https://example.com/samplepage/
The page URL ends up being the folder name, and the server will automatically serve the index.html file inside if you use the second link.
site.pages will give you the first link. As you have a filter that removes index.html from your paths, you end up with extension-free URLs.
Any file in Jekyll folder is generated with his extension, except if you use permalink.
If you create a sitemap.xml file like this :
---
layout: null
---
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{% for page in site.pages %}
<url>
<loc>https://example.com{{ page.url | remove: 'index.html' }}</loc>
</url>
{% endfor %}
</urlset>
It will be generated as sitemap.xml.
You can also use jekyll-sitemap wich is supported by github pages.

Dynamic Links in jekyll

currently I'm working on static website, so I'm using jekyll to generate it. To have a nice structure and fancy URLs, I use permalinks.
permalink: /impressum/
So for example the impressum.html is rendered to impressum/index.html. And in my HTML i can simply link to that file with
<a href="/impressum">
That works for me very well. But you know, I'm a programmer. What if I want for example to change the URL to /imprint/? Well, I can change the permalink without any problems. But what's about all the other links on the site? Yeah, sure, I can use the search & replace function of my editor to change the linked URLs and check the whole site with a site checker for broken links, but that's not the fancy way I want to go. That's why I tried to create some kind of global variables with the permalink.
_config.yml:
lnk_impressum: /impressum/
impressum.html
---
layout: layout
title: Your New Jekyll Site
permalink: {{ site.lnk_impressum }}
---
But that does not work. I get this error:
Generating... error: no implicit conversion of Hash into String. Use --trace to view backtrace
So what's wrong or is there a better way?
It doesn't seem to be possible to place Liquid tags inside the YAML Frontmatter or _config files, per this SO answer.
Something else you could try is based on the approach used by the documentation pages for Bootstrap, which uses a Page Variable they call slug that provides a unique, unchanging reference to each page.
For instance, if you'd like to place a link to your impressum.html page (for which the permalink could change), you can place this code on another page, such as index.html:
{% for mypage in site.pages %}
{% if mypage.slug == 'impressum' %}
Link to Impressum page
{% endif %}
{% endfor %}
Then, in the YAML frontmatter for each of your pages, place code similar to the following:
---
slug: impressum
permalink: /my-permalink-to-impressum/
---
To change your permalinks in the future, you would just make the change to the Page Variable permalink in each page. The URLs referenced in your other pages would be automatically updated by Jekyll, as long as the slug variable remains unchanged.

Can jekyll use GET parameters?

I would like to make a categories page.
{% for post in site.categories[CATEGORY_NAME] %}
<li>{{ post.title }} ({{post.date|date:"%-d %B %Y"}})</li>
{% endfor %}
Is it possible to use a page parameter to fill in CATEGORY_NAME? Then I could have one file category.html which could serve as the index page for multiple categories (i.e. category.html?name=food and category.html?name=animals.
I've found a few plugins that handle this, but it seems like overkill to require a plugin.
https://github.com/zroger/jekyll-categories
http://blog.nitrous.io/2013/08/30/using-jekyll-plugins-on-github-pages.html
Here's the most related forum post I could find.
https://groups.google.com/forum/#!topic/jekyll-rb/y-dq-63Uvy4
If I can't do this without a plug in, is there a good reason?
I think the correct answer is that Jekyll pages must be compiled to html before they are served. This is not possible if the liquid language takes a parameter.