Use per-page title with a Jekyll theme - jekyll

This is my personal GH Pages site.
I have this set in my /_config.yml:
theme: jekyll-theme-cayman
title: iBug # GitHub
description: The small personal site for iBug
Now it shows a big title iBug # GitHub and a tagline on every page GH Pages generates. I want to set overrides for specific pages. I tried
---
title: Blog index
---
in /blog/index.html, but it doesn't work. It only changes the HTML title of the page (browser title bar), but not the "title" in the big block on the top of the page.
How do I set an override title for a single page?

Update: I have since submitted a pull request to change this in the theme, and the answer below is no longer necessary since it's already been applied when you use the theme as of now. All you need to do is to specify the title override in the front matter:
---
title: My custom title
---
To specify another title, you need to change the layout file.
Copy the default layout and place it in <GitHub repo>/_layouts/default.html, and change line 16 to this:
<h1 class="project-name">{{ page.title | default: site.title }}</h1>
Then Jekyll will respect the title set in the front matter, and place it there.

This is just the way this theme is implemented, if you check the default layout for Cayman theme on line 14 you can see what exact variable it is using.
<h1 class="project-name">{{ site.title | default: site.github.repository_name }}</h1>
Hope that helps!

My approach is using javascript as follows.
<script>
document.getElementsByClassName("project-name").item(0).innerText = "{{ page.title }}";
</script>
You can write a html file in _includes dir and use {% include your_file.html %}.

Related

Hugo won't render front matter variables when I publish to Netlify

I am building a hugo blog site and I have some front matter that I would like to get rendered in the layouts. When I view the results on my localhost:1313, I can see the front matter being populated, but when I host the site on Netlify, the front matter and partial files won't render.
I'm not sure what else to do. I've cleared the console of any errors, made sure my content files match the layout files etc.
Any help?
Here is the link to the live netlify site: https://stoic-meninsky-a5758a.netlify.app/
Here is my directory structure:
-content
-about
-_index.md
-blog
-_index.md
-post-1.md
-_index.md
-layouts
-_default
-baseOf.html
-about
-section.html
-blog
-section.html
-single.html
_index.html
This is a sample file that is pulled from one of my content markdown files:
---
title: "The Herman Show | Blog"
linktitle: "Blog"
draft: true
newsletter: "This is the newsletter"
---
This is how I call the front matter: <p>{{ .Params.newsletter }}</p>
This is how I loop over the section pages to get a navbar
{{ range .Site.Sections }}
<li>{{ .LinkTitle }}</li>
{{ end }}
Make sure your markdown files in the content directory are marked to: drafts:false

Jekyll posts aren't using layout accordingly

As described in "specifying layout for html posts in jekyll", Jekyll _posts should behave as any other page when it comes from its _layouts, however it isn't doing this way to me right now.
I'm developing this static site to be hosted in a Github Pages and everything else is working fine, but my posts are not.
I also checked the errors in "Jekyll post not generated" about Jekyll _posts, but the problem wasn't solved.
# _posts/2020-06-27-how-I-long-for-summer.md
---
layout: post
title: How I long for Summer
cover: /assets/img/jhonny.jpg
date: 2020-06-27 20:56:28 -0300
categories: text
---
# _layouts/post.html
---
layout: default
---
# layouts/default.html
<!DOCTYPE html>
<html lang="en">
{% include head.html %}
<body>
{% include navbar.html %}
{{ content }}
{%- include footer.html -%}
</body>
</html>
So, even all regular pages are using default layout accordingly, my post pages have been rendered raw, as if I haven't declared any layout to them.
I'm using minima theme, but actually I was expecting it hasn't any effect since I overwrited post layout.
# _config.yml
markdown: kramdown
theme: minima
permalink: :year/:month/:day/:title
I tried what I could. Does anyone have a clue about what I'm doing wrong?
All of your CSS is using relative paths rather than absolute paths and therefore isn't being fetched correctly.
In your various source code files (head.html, footer.html etc.).
assets/js/main.min.js
assets/js/theme.js
assets/css/main.min.css
assets/css/theme.css
assets/main.css // not available
Should be:
/assets/js/main.min.js
/assets/js/theme.js
/assets/css/main.min.css
/assets/css/theme.css
/assets/main.css // not available
Another solution is to use Liquid's relative_url filter:
https://github.com/jekyll/minima/blob/master/_includes/head.html#L6
https://jekyllrb.com/docs/liquid/filters/

How can I limit the number of lines shown on the homepage of a Jekyll blog?

In my Jekyll theme, some of my blog posts are shown as it is on the home page. But I want to limit them up to certain lines. That is, I want to show only 5-6 lines of the blog on the home page.
For example,
In,
1. 5 lines of the blog post are visible
2. Only two lines of the blog post are visible
3. In the last post of the page the entire blog post is visible on the homepage.
I am new to Jekyll and I don't know how can I do that. The theme I am using is the earlier version of White Paper
The preview text from each blog posts are from {{ post.excerpt }} in index.html[1]. It looks like the White Paper jekyll theme is using the default behavior of Post excerpts[2].
By default this is the first paragraph of content in the post, however
it can be customized by setting a excerpt_separator variable in front
matter or _config.yml.
If you want to control how much text is previewed for each blog post, you can stop using {{ post.excerpt }} and do something like {{ post.content | truncatewords: 60 }} instead.
These {{ ... }} code snippets are from the Liquid templating language [3][4]
[1] https://github.com/vinitkumar/white-paper/blob/3995398d74b42ee70ad2e4c82a0ab8955ad49955/index.html#L10
[2] https://jekyllrb.com/docs/posts/#post-excerpts
[3] https://jekyllrb.com/docs/liquid/
[4] https://shopify.github.io/liquid/
If you'd like to have more variation in excerpt size by each post, you can also use an excerpt-separator anywhere you'd like in the body of your posts [1].
By default this is the first paragraph of content in the post, however
it can be customized by setting a excerpt_separator variable in front
matter or _config.yml
[1] https://jekyllrb.com/docs/posts/#post-excerpts

jekyll front matter variable don't work

I'm starting to use jekyll, but when trying to customize a variable it does not work.
My code
---
layout: default
hello: "teste liquid"
---
<h1>{{ page.hello }}</h1>
but this don't work, it does not print anything in html, it leaves empty
do I need to do any additional configuration on jekyll?
I'm writing this because I had the same problem and I lost half a day trying to figure out what caused it.
When I installed jekyll and created a new site I got the following file by default: index.markdown with an empty front matter in it (two lines of three dashes each).
I also created an index.html file as the Jekyll tutorial suggested.
Apparently, if you have both files and you try to add front matter to the HTML file the whole site breaks and the default jekyll page is displayed instead of the index.html page.
The solution is to remove or rename the index.markdown file so the HTML file is the only index.
Note, that if you don't add front matter to the HTML page the HTML page is displayed normally (but, of course, the liquid tags {{ }} don't work)
Hope this help.
Thanks to virginiarcrz for pointing this solution out.
I had this issue. There was an extra space after toggling a comment '#' tag in the frontmatter of my index.md:
---
#title: index
title: index2
----
and I fixed it by removing the space:
---
#title: index
title: index2
----

How to create sub md files with content that applies to the page md files

I'm creating a website using Jekyll.
so far I have four pages which are created automatically from four md files which md files are in the root of the project.
index.md
about.md
login.md
register.md
Here is the content inside my login.md file
---
layout: layout-default
title: some login title
permalink: /login
theme: secondary-theme
nav:
menu-items:
- type: text
text: Don't have an account?
- type: link
text: SIGN UP
class: button
linkPath: /register
sections:
- type: 3
class: form-section
header-line-2: Login Section!
form:
api: http://127.0.0.1:8080/login
submit-text: LOG IN
form-controls:
- label-text: EMAIL ADDRESS
input-type: email
input-placeholder: Enter your email
input-name: email
- label-text: PASSWORD
label-link-text: Forgot password?
label-link-path: #
input-type: password
input-placeholder: Enter your password
input-name: password
---
What i do is iterating the sections and applying html attribute values depending on the variables inside each section. That way i can have as many sections rendered as i want on one page. And they can also be different depending on the classes and content i put in the md file.
The problem is that if the project gets too complicated with different styles for sections and so on. I would like to separate each section content. It would be nice if i could make a folder lets say login/sections folder
and then put md files inside and then inside login.md file include these section md files. This way the code would be much more organized.
Is there way to do that, and is my approach actually good.
Jekyll provides the ability to include files into another files. The magic directory for this is _includes. Example:
If you create a file named _includes/sections/s1.html, you can include that into any other file with the following tag:
{% include sections/s1.html %}
This approach works for:
including HTML file into HTML
including HTML file into Markdown (since Markdown can contain HTML code)
including Markdown into Markdown
If you want to include a Markdown file into a HTML, you have to use some trick:
{% capture m %}{% include sections/s1.md %}{% endcapture %}
{{ m | markdownify }}