1.7 KiB
1.7 KiB
Data files
- It is important to separate the content from layouts so store them in
_datafolder. Data files supported are YAML, JSON, and CSV. YAML ones are most common for this - To create a array of objects where each objects have property ie
nameandlinkat_data/navigation.yml
- name: Home
link: /
- name: About
link: /about.html
- this data will be available at
site.data.navigation. In_includes/navigation.html
<nav>
{% for item in site.data.navigation %}
<a href="{{ item.link }}" {% if page.url == item.link %} style="color: red;"{% endif %}>
{{ item.name }}
</a>
{% endfor %}
</nav>
Assets
- Other files like css,js and images can be included in
assetsfolder. ├── assets │ ├── css │ ├── images │ └── js ... - css is necessary too as inline styles are not a good idea always so in
assets/css/styles.scss
---
---
@import "main";
- then create
_sassat root directory as@import mainwill tell to look for filemain.scssat_sassso at_sass/main.scss
.current {
color: green;
}
in _layouts/default.html add this styles.css under <head>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>{{ page.title }}</title>
<link rel="stylesheet" href="/assets/css/styles.css">
</head>
<body>
{% include navigation.html %}
{{ content }}
</body>
</html>
- finally add the class
currenttoo in_includes/navigation.html
<nav>
{% for item in site.data.navigation %}
<a href="{{ item.link }}"{% if page.url == item.link %} class="current"{% endif %}>{{ item.name }}</a>
{% endfor %}
</nav>