Skip to content

Commit d9ae37f

Browse files
authored
Merge pull request #6 from btc-raspberrypiclub/3-dynamically-create-navbar-using-list
Dynamically create navbar using list in `_config.yml`
2 parents d1e94c4 + fc76aca commit d9ae37f

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,23 @@ included. Follow the instructions below for complete setup.
3232
3. Install the theme by running `bundle install` inside your site directory.
3333
4. Replace the current theme in your `_config.yml` file with
3434
`theme: jekyll-theme-cleaner-blog`.
35-
5. Build your site: `bundle exec jekyll serve`
35+
5. Add the following variable to your `_config.yml`:
36+
```yaml
37+
navigation:
38+
- name: Home
39+
link: /
40+
- name: About
41+
link: /about/
42+
- name: Posts
43+
link: /posts/
44+
- name: Contact
45+
link: /contact/
46+
```
47+
48+
This describes the navbar at the top of your site. If it is not present,
49+
there will be no links on your navbar. You can add or remove links here to
50+
customize your navigation.
51+
6. Build your site: `bundle exec jekyll serve`
3652
3753
Assuming there are no errors and the site is building properly, follow these
3854
steps next:
@@ -84,6 +100,7 @@ matter. Example:
84100
see how the files are set up.
85101
86102
<!-- TODO:
103+
87104
5. Add the form to the `contact.html` page. Add the following code to your
88105
`contact.html` page:
89106

_config.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ author: btc-raspberrypiclub
55
baseurl: "/cleaner-blog-jekyll"
66
url: "https://btc-raspberrypiclub.github.io"
77

8+
# Navigation links
9+
navigation:
10+
- name: Home
11+
link: /
12+
- name: About
13+
link: /about/
14+
- name: Posts
15+
link: /posts/
16+
- name: Contact
17+
link: /contact/
18+
819
# Social Profiles
920
twitter_username:
1021
github_username: btc-raspberrypiclub

_includes/navbar.html

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,11 @@
88
</button>
99
<div class="collapse navbar-collapse" id="navbarResponsive">
1010
<ul class="navbar-nav ms-auto">
11+
{% for item in site.navigation %}
1112
<li class="nav-item">
12-
<a class="nav-link" href="{{"/" | relative_url }}">Home</a>
13-
</li>
14-
<li class="nav-item">
15-
<a class="nav-link" href="{{"/about" | relative_url }}">About</a>
16-
</li>
17-
<li class="nav-item">
18-
<a class="nav-link" href="{{ "/posts" | relative_url }}">Posts</a>
19-
</li>
20-
<li class="nav-item">
21-
<a class="nav-link" href="{{"/contact" | relative_url }}">Contact</a>
13+
<a class="nav-link" href="{{ item.link | relative_url }}">{{ item.name }}</a>
2214
</li>
15+
{% endfor %}
2316
</ul>
2417
</div>
2518
</div>

0 commit comments

Comments
 (0)