You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Netlify CMS is used to handle the CMS part of this static website. It uses Git as backend, so there is no need to maintain a different server. Maintained by the awesome folks of Netlify.
Eleventy is a simpler static site generator using JavaScript. Eleventy will compile all of our files and generate a static output where we can host it anywhere.
63
-
64
-
*[Alpine.js](https://alpinejs.dev/):
65
-
66
-
Alpine JS is a minimal framework to provide JavaScript behavior in our markup. Think it as a lite version of React & Vue. We use Alpine JS to add JavaScript components like Dropdown, Toggle etc.
67
-
68
-
*[Tailwind CSS](https://tailwindcss.com/):
69
-
70
-
Tailwind CSS is a utility first CSS Framework. It has a set of preset utility classes to style anything without touching CSS file.
71
-
72
-
## Folder Structure
73
-
74
-
Root `/` folder of our project contains all configuration files like `tailwind.config.js`, `.eleventy.js` etc..
75
-
76
-
`/src` folder contains all of our site contents and data. Before configuring anything, you go to the `/src` folder and make some changes to see if its working.
77
-
78
-
## Make Changes
79
-
80
-
Go to the `/src` folder and open `index.html` file. Now make any changes and save it to see if the changes are reloading or not. If it's reloading with your changes, then it means it's working perfectly. If you have any issues, comment here or raise an issue at GitHub.
81
-
82
-
* This is the new folder structure :
83
-
84
-
```
85
-
src
86
-
│ index.html
87
-
│
88
-
└───__data
89
-
│ │ navigation.yaml
90
-
│ │ settings.yaml
91
-
│
92
-
└───__includes
93
-
│ │ default.html
94
-
│ │
95
-
│ └───partials
96
-
│ │ navbar.html
97
-
│ │ footer.html
98
-
│
99
-
└───static
100
-
│ │
101
-
│ └───css
102
-
│ │
103
-
│ └───img
104
-
.eleventy.js
105
-
.eleventyignore
106
-
.gitignore
107
-
.nojekyll
108
-
CODE_OF_CONDUCT.md
109
-
LICENSE
110
-
package.json
111
-
package-lock.json
112
-
postscss.config.js
113
-
tailwind.config.js
114
-
README.md
115
-
```
116
-
117
-
## Nunjucks
118
-
119
-
Writing code with NEAT Stack is fun because of [Nunjucks](https://mozilla.github.io/nunjucks/). Eleventy supports Nunjucks Templating language by default. So that you can split HTML Code and avoid writing repetitive code like a boss.
120
-
121
-
Including a part of HTML is easy. Go to `src/_includes/partials/navbar.html` and make some changes there. Now we can include the navbar anywhere we wanted using `{% include ..}`
122
-
123
-
Another great feature of Nunjucks is the Loops. Suppose you have a card block repeating over 10 times, using Nunjucks, just write it once and loop it. That means you will be able to modify easily by changing in one place. The data should be separated here and it will be handled seamlessly by our Eleventy.
124
-
125
-
Example Nunjucks loop :
126
-
*`_data/navigation.yaml` :
127
-
```yaml
128
-
---
129
-
items:
130
-
- text: HOME
131
-
url: "/"
132
-
- text: LEARN
133
-
url: "/learn"
134
-
- text: BLOG
135
-
url: "/blog"
136
-
- text: ABOUT
137
-
url: "/about"
138
-
- text: PROJECTS
139
-
url: "/projects"
140
-
```
141
-
142
-
* `navbar.html` :
143
-
```html
144
-
<ul>
145
-
{% for item in navigation.items %}
146
-
<li class="nav__item">
147
-
<a href="{{ item.url }}">{{ item.text }}</a>
148
-
</li>
149
-
{% endfor %}
150
-
</ul>
151
-
```
152
-
153
-
That's it. Adding classes or modifying layout is now easier since Eleventy & Nunjucks combined do all the magic for us.
154
-
155
-
## Eleventy Data
156
-
157
-
Since we talked about the `_data` above. If you enter the data as raw text inside a page, it means you cannot edit that text using CMS. So it's important to plan initially according to your needs. Make a list on which data you need to change later and which is not.
158
-
159
-
By default, Eleventy looks for a folder called `_data/` and get the data from the files inside. They accept json, yaml, js etc. So you can write data in any format you like. If you have to fetch a data from a different server, you can create .js file which returns the data.
160
-
161
-
> The `_data` folder name can be changed using Eleventy configuration
162
-
163
-
## Writing HTML
164
-
165
-
Its really simple to create pages or sections in Eleventy. Just create an HTML file in the /src folder and it will automatically build it as a page. If you are writing a blog, you can even use Markdown (`.md` file type) as well.
166
-
167
-
#### Example to create a blog page
168
-
169
-
1. Create a file called `blog.html`
170
-
171
-
```html
172
-
---
173
-
title: Our Blog
174
-
layout: default
175
-
path: blog
176
-
---
177
-
178
-
<div class="container max-w-3xl mt-6 px-6">
179
-
180
-
<h1 class="font-bold text-5xl">{{title}}</h1>
181
-
182
-
{{ content | safe }}
183
-
184
-
</div>
185
-
```
186
-
187
-
2. Access it to localhost:8080/blog/
188
-
189
-
## Alpine JS
190
-
191
-
Adding interactivity is easy using Alpine JS. You can learn more about from the docs. Here's how a simple Toggle works with Alpine JS.
Here you can see the initial data is created for `isOpen` and its set to `false` and it changes the data on button click. Based on the Value, we just toggle the `div` visibility. Wasn't it easy compared to jQuery? We didn't even created a `js` file.
0 commit comments