Skip to content

Commit 5f99877

Browse files
authored
Merge pull request #168 from WebXDAO/nextjs-upgrade
Landing: 11ty to Nextjs by @AbhinavMV
2 parents 94c3835 + 82b8f70 commit 5f99877

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+3850
-14346
lines changed

.eleventy.js

Lines changed: 0 additions & 70 deletions
This file was deleted.

.eleventyignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.eslintrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "next/core-web-vitals"
3+
}

.gitignore

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,37 @@
1-
_site/
2-
_tmp/
3-
.DS_Store
4-
node_modules/
5-
.vscode/
6-
*git/
7-
.env
8-
.cache/
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
#package-lock.json
94
package-lock.json
5+
6+
# dependencies
7+
/node_modules
8+
/.pnp
9+
.pnp.js
10+
11+
# testing
12+
/coverage
13+
14+
# next.js
15+
/.next/
16+
/out/
17+
18+
# production
19+
/build
20+
21+
# misc
22+
.DS_Store
23+
*.pem
24+
25+
# debug
26+
npm-debug.log*
27+
yarn-debug.log*
28+
yarn-error.log*
29+
30+
# local env files
31+
.env.local
32+
.env.development.local
33+
.env.test.local
34+
.env.production.local
35+
36+
# vercel
37+
.vercel

.nojekyll

Whitespace-only changes.

README.md

Lines changed: 1 addition & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -43,160 +43,10 @@ This step is only required the very first time.
4343
npm run build
4444
```
4545

46-
### 6\. Run Eleventy
46+
### 6\. Run Nextjs
4747

4848
```
4949
npm run start
5050
```
5151

5252
### 7\. ✨ Enjoy
53-
54-
## Technologies used
55-
56-
* [Netlify CMS](https://www.netlifycms.org/) (Currently WIP 🚧):
57-
58-
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.
59-
60-
* [Eleventy (11ty)](https://github.com/11ty/eleventy):
61-
62-
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.
192-
193-
```html
194-
<nav x-data="{ isOpen: false }" @keydown.escape="isOpen = false">
195-
<button @click="isOpen = !isOpen"">Menu </button>
196-
<div :class="{ 'block': isOpen, 'hidden': !isOpen }" @click.away="isOpen = false" x-show.transition="true">
197-
... menu
198-
</div>
199-
</nav>
200-
```
201-
202-
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.

components/Global/Blogs.jsx

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import Image from 'next/image'
2+
import Link from 'next/link'
3+
4+
const Blogs = ({ articles, contentOnly = false, show = articles.length }) => {
5+
return (
6+
<section className='bg-white py-8'>
7+
{!contentOnly && (
8+
<div className='container max-w-5xl mx-auto'>
9+
<h1 className='w-full my-2 text-4xl font-bold leading-tight text-center text-gray-800'>
10+
Blogs
11+
</h1>
12+
<div className='w-full mb-4'>
13+
<div className='h-1 mx-auto gradient w-64 opacity-25 my-0 py-0 rounded-t'></div>
14+
</div>
15+
</div>
16+
)}
17+
<div className='container max-w-screen-xl mx-auto pt-4 pb-8 grid grid-cols-3 mb-8 gap-6 px-8'>
18+
{articles.length > 0 ? (
19+
articles.slice(0, show).map((article, index) => (
20+
<Link key={article.title + index} href={article.url} passHref>
21+
<div className='flex flex-col justify-between items-stretch col-span-3 md:col-span-1 cursor-pointer p-2 shadow rounded-md focus:outline-none focus:shadow-outline transform transition hover:shadow-lg hover:scale-105 duration-300 ease-in-out'>
22+
<div className='bg-white p-4 rounded-lg'>
23+
<div className='relative bg-contain'>
24+
<Image
25+
alt={article.title}
26+
layout='responsive'
27+
height={150}
28+
width={150}
29+
className='lg:h-60 xl:h-56 md:h-64 sm:h-72 xs:h-72 h-72 rounded-md w-full object-cover object-center mb-6'
30+
src={article.social_image}
31+
/>
32+
</div>
33+
<div className='flex justify-between'>
34+
<h2 className='text-xl text-gray-900 font-semibold mb-4'>{article.title}</h2>
35+
</div>
36+
<p className='leading-relaxed text-sm text-gray-600'>{article.description}</p>
37+
</div>
38+
<time className='p-4 text-gray-500 text-xs flex items-end'>
39+
<Image
40+
layout='fixed'
41+
width={40}
42+
height={40}
43+
src={article?.user?.profile_image}
44+
alt={article.user.name}
45+
className='rounded-full'
46+
/>
47+
<p className='ml-2 opacity-50'>
48+
by {article.user.name} on
49+
{' ' + article.readable_publish_date}
50+
</p>
51+
</time>
52+
</div>
53+
</Link>
54+
))
55+
) : (
56+
<div className='text-center w-full'>No Blogs found....</div>
57+
)}
58+
</div>
59+
{!contentOnly && (
60+
<div className='flex justify-center'>
61+
<a href='https://dev.to/web3community' target='_blank' rel='noreferrer'>
62+
<button className='bg-gray-700 text-white mx-auto lg:mx-0 rounded-md py-2 px-8 shadow transform transition hover:scale-85 hover:shadow-lg duration-300 ease-in-out'>
63+
See All
64+
</button>
65+
</a>
66+
</div>
67+
)}
68+
</section>
69+
)
70+
}
71+
72+
export default Blogs

0 commit comments

Comments
 (0)