This commit is contained in:
nm1 2026-11-04 00:33:23 +05:30
commit 74ae93a96e

View file

@ -0,0 +1,79 @@
Blogging
- Blog page will contain list of posts and these posts are in `_posts`. for instance one post can be
`2018-08-20-bananas.md`
```md
---
layout: post
author: jill
---
A banana is an edible fruit – botanically a berry – produced by several
kinds of large herbaceous flowering plants in the genus Musa.
In some countries, bananas used for cooking may be called "plantains",
distinguishing them from dessert bananas. The fruit is variable in size,
color, and firmness, but is usually elongated and curved, with soft
flesh rich in starch covered with a rind, which may be green, yellow,
red, purple, or brown when ripe.
```
- Creating layout for the post. at `_layouts/post.html`
```html
---
layout: default
---
<h1>{{ page.title }}</h1>
<p>{{ page.date | date_to_string }} - {{ page.author }}</p>
{{ content }}
```
`date_to_string` filter, this formats a date into a nicer format
- listing posts : posts will be available at `site.posts`. at `/blog.html`
```html
---
layout: default
title: Blog
---
<h1> Latest Posts </h1>
<ul>
{% for post in site.posts %}
<li>
<h2> <a href="{{post.url}}"> {{post.title}} </a> </h2>
{{post.excerpt}}
</li>
{% endfor %}
</ul>
```
There’s a few things to note with this code:
- `post.url` is automatically set by Jekyll to the output path of the post
- `post.title` is pulled from the post filename and can be overridden by setting title in front matter
- `post.excerpt` is the first paragraph of content by default. excerpt literally means short piece taken from something.
- adding blog entry in `_data/navigation.yml`
```yml
- name: Home
link: /
- name: About
link: /about.html
- name: Blog
link: /blog.html
```
- more posts
at `_posts/2018-08-21-apples.md`
```md
---
layout: post
author: jill
---
An apple is a sweet, edible fruit produced by an apple tree.
Apple trees are cultivated worldwide, and are the most widely grown
species in the genus Malus. The tree originated in Central Asia, where
its wild ancestor, Malus sieversii, is still found today. Apples have
been grown for thousands of years in Asia and Europe, and were brought
to North America by European colonists.
```