How do I display most recent blog post on Octorpess/Jekyll landing page - blogs

I created a landing page for my octopress website and I'd like to have the most recent blog post displayed on the home page, but just the most recent blog. I am not sure quite how to proceed. Is there a code like {% include post %} that will allow me to do this?
Thanks.

As per usual, I tend to find the solution after I ask it.
On home page:
<div class="blog-index">
{% assign post = site.posts.first %}
{% assign content = post.content %}
{% include custom/asides/recent_post.html %}
</div>
In separate document saved to custom/asides/recent_post.html:
<h2 class="entry-title">
{% if post.title %}
{{ post.title }}
{% endif %}
</h2>
<div class="entry-content">{{ content | excerpt }}</div>
<a class="btn btn-default" href="{{ root_url }}{{ post.url }}">{{ site.excerpt_link }}</a>
Found solution here: https://gist.github.com/nimbupani/1421828

Related

Django html set up

I have a basic website set up with Django and have been following the sentdex tutorials. I cannot figure out how to include the blog posts (I'm assuming this would be either blog.html or post.html) in the bootstrap 'about' section, which I Have renamed blog. Basically, I want the blog posts (derived from the database) to appear here in the 'about' section in bootstrap, rather than at the bottom or in a separate page.
I have an 'aboutme' app (main website) that contains the home.html
{%extends "aboutme/header.html" %}
{%block content%}
<p>Welcome to this "about" page that is all about the website:
{%include "aboutme/includes/mysnippet.html"%}
{% endblock %}
{%block blogcontent%}
{% endblock %}
..and a header.html which contains the whole index.html of the bootstrap site itself. Below is the about section of the bootstrap websit about/blog section that includes the django templating logic (block content)
<!-- About Section (Blog)-->
<section class="bg-primary text-white mb-0" id="about">
<div class="container">
<h2 class="text-center text-uppercase text-white">Blog</h2>
<hr class="star-light mb-5">
<div class="row">
<div class="col-lg-4 ml-auto">
<p class="lead">This is the blog section</p>
{%block blogcontent%}
{%endblock %}
</div>
<div class="col-lg-4 mr-auto">
<p class="lead">The blogs outlined in the models section and stored in the database, are going to be displayed here.</p>
</div>
</div>
<div class="text-center mt-4">
<a class="btn btn-xl btn-outline-light" href="#">
<i class="fa fa-download mr-2"></i>
Download Now!
</a>
</div>
</div>
</section>
Finally, I have another app called 'blog', and inside the templates/blog directory for that app:
post.html and blog.html
blog.html
{% extends "aboutme/header.html" %}
{%block content %}
{% for post in object_list %}
<h5>{{post.date|date:"Y-m-d"}}{{post.title}}</h5>
{% endfor %}
{% endblock %}
post.html
{% extends "aboutme/header.html" %}
{%block content %}
<h3>{{post.title}}</h3>
<h6>on{{post.date}}</h6>
{{post.body|safe|linebreaks}}
{% endblock %}
at the moment when I type http://127.0.0.1:8000/blog ...the blog posts appear at the bottom of the page, or wherever I place the {%block content %}{% endblock %} (but it only seems to work at the bottom of the page).
How do I get the blog posts to appear in the 'about me' section of the bootstrap website?
I'd also love an explanation on what exactly the home.html page does and can it be named anything or does it have to be 'home'. Is there where everything is defined in terms of what is displayed, and how does it work?
Edit/Design your codes like that:
Html stuff for index or aboutme/header.html
// codes here
{% block blogcontent %}
{% include 'path/blog.html' %}
{% enblock %}
// codes here
{% block postcontent %}
{% include 'path/post.html' %}
{% enblock %}
<!-- end -->
when you call 127.0.0.1:8000, everything will be available there.
and for other links, if you don't want to display the blog or post block,
just use {% block blogcontent %}{% endblock %} {% block postcontent %}{% endblock %} whitout anything inside

Jekyll: Display all posts in the same page

I have been reading everything at Jekyll Docs, but I couldn't find a way to do this.
By default when generating a web, jekyll displays a list of the links of all your blog posts. Is there a way to display the content of all your blog posts in the same page? (alla blogspot/wordpress/traditional blog...)
Found my solution from: This tutorial, which consists of editing index.md and adding the following:
{% for post in site.posts %}
<article>
<h2>
<a href="{{ post.url }}">
{{ post.title }}
</a>
</h2>
<time datetime="{{ post.date | date: "%Y-%m-%d" }}">{{ post.date | date_to_long_string }}</time>
{{ post.content }}
</article>
{% endfor %}

Sorting posts by category using Jekyll works locally but not on Github pages?

I have posts in Jekyll sorted by categories that wont display on github pages. The yaml font matter in the post has the categories set to CSS and design but don't display on the category page with the code below:
{% for post in site.categories.CSS %}
{% if post.url %}
<a id="h1a" href="{{ post.url }}">{{ post.title }}</a>
<p id="date">{{ post.author }} • {{ post.date | date: "%b %-d, %Y" }}</p>
<div id="excerpt">{{ post.excerpt }} </div>
<div id="readmore">Read More</div>
{% endif %}
{% endfor %}
It works locally, and the URL path (/css/design/2016/01/10/responsive-web-design-css-viewport.html) shows that the categories are there, but does not display in the link above. Here is my repository, the code above can be found in the css folder of the root directory.
Jekyll 3.x uses categories "as is" : CSS stays CSS.
Jekyll 2.x is down-casing categories : CSS becomes css.
So, on Github pages site.categories.CSS == nil
In order to work locally in Github pages configuration, you can follow install instructions here.

Jekyll: code is getting highligheted unwantingly

I've got the following page:
---
layout: default
status: publish
published: true
title: Categories
author:
display_name: lucas
---
{% for category in site.categories %}
<li><a name="{{ category | first }}">{{ category | first }}</a>
<ul>
{% for posts in category %}
{% for post in posts %}
<li>{{ post.title }}</li>
{% endfor %}
{% endfor %}
</ul>
</li>
{% endfor %}
Instead of listing the hrefs per categery, it somehow gets code highlighting:
Can anyone help me out preventing the code getting highlighted? Thanks!
As mentioned by #David Jacquel, .md files are automatically parsed as markdown, in which four space indentations are treated as preformatted code.
I followed his suggestion on my website: change all files to .html. This disabled Markdown parsing in the file. However, if you are unwilling to write in pure HTML and would still like to use Markdown, there is a workaround.
For each element that you would like Markdown to ignore, give it the attribute markdown="0".
For each element that you would like Markdown to parse, give it the attribute markdown="1".
In your case, the following is a possible implementation.
...
<div markdown="0">
{% for category in site.categories %}
<li><a name="{{ category | first }}">{{ category | first }}</a>
<ul>
{% for posts in category %}
{% for post in posts %}
<li>{{ post.title }}</li>
{% endfor %}
{% endfor %}
</ul>
</li>
{% endfor %}
</div>
Is it a .md file ? If yes, try to change for an .html extension.
In markdown four space indentation is used to print code tag.

jekyll blog title to include pagination variables

I am trying to get Page 2+ of my blog to have a different title for search engines to index.
I have read several other stackoverflow answers stating that you cannot use liquid tags in the front matter yaml. One suggested to use JS to update the title, however this will not work for me as I want the search engine to index the parsed title.
I thought there may be another way. I can perhaps create a HTML page for each of my pages. I would like to do that without having to manually add each one of my posts into each of the pages (resulting in an ongoing time consuming task each time I post a new article).
I was thinking I could make one page for 1-10, another page for 11-20, etc... Something like this:
---
title: Blog Page 2
---
{% for post in paginator.posts %}
{% if post.index > 10 %}{% if post.index <= 20 %}
<div class="post-preview">
<a href="{{ post.url | prepend: site.baseurl }}">
<h2 class="post-title"> {{ post.title }}</h2>
{{ post.excerpt }}
</a>
</div>
{% endif %}{% endif %}
{% endfor %}
It seems there is no post.index variable available. Is there anything similar I can use?
Or are there any other ways to achieve "Blog Page X" in my title?
Supposing that your head tags are in your _includes/head.html file. In the title tag just add :
{% if paginator %} - page {{ paginator.page }}{% endif %}
Your title tag now looks like this :
<title>
{% if page.title %}{{ page.title }}{% else %}{{ site.title }}{% endif %}
{%if paginator %} - page {{ paginator.page }}{% endif %}
</title>