DEV Community

Cover image for Build a personal site with Next.js and Tailwindcss
EliasChen
EliasChen

Posted on • Edited on

Build a personal site with Next.js and Tailwindcss

Why Next.js?

Next.js is an open-source javascript framework built on Node.js that allows you to create React applications that you can render on the server. It provides out-of-the-box tooling like next/image , next/router and configuration you need to build fast, SEO-friendly React apps.

Note: There is other ways to using next.js like T3 Stack .

The Stacks

Fetch Github Rest API

to fetching data from github, you have to create a github account and create token of your github account.

You use axios or fetch to fetching api from github.
Example of fetching github user repository data with fetch.

import React from "react";

const tokenkey = "GITHUB_TOKENKEY";

export default function Fetchgithubapi() {
  const [data, setData] = React.useState(null);
  const [isLoading, setLoading] = React.useState(false);
  const loadingdisplay = (
    <div>
      <p>Loading...</p>
    </div>
  );
  useEffect(() => {
    setLoading(true);
    fetch("https://api.github.com/users/GITHUB_USERNAM/repos", {
      headers: {
        Authorization: { tokenkey },
      },
    })
      .then((res) => res.json())
      .then((data) => {
        setData(data);
        setLoading(false);
      });
  }, []);
  if (isLoading) return loadingdisplay;
  if (!data) return loadingdisplay;
  return (
    <div>
      {data.map((repo) => (
        <div>
          <p>{repo.name}</p>
        </div>
      ))}
    </div>
  );
}
Enter fullscreen mode Exit fullscreen mode

next-sitemap

The most easy way to do this is create a file called next-sitemap.config.js in the root floder of project and insert these few lines of code.

const siteUrl = 'http://www.eliaschen.dev/'
module.exports = { siteUrl }
Enter fullscreen mode Exit fullscreen mode

SEO

SEO also is a very important key for your personal website, It's about how people can search your website in the search engine.

To make your SEO better you can add robots.txt in /public floder, and add your website to Google Search Console .

  • robots.txt (insert these code to robots.txt under the /public floder)
User-agent: *
Allow: /
Sitemap: https://example.com/sitemap-0.xml
Enter fullscreen mode Exit fullscreen mode
  • Google Search Console Tools It's very simple to add your website to Google Search Console.
  • Visit Google Search Console
  • Create a new resource
  • Go to Produce an index > Site map add your sitemap with url

Deploy

I deploy my website with vercel.

Conclusion

Overall, If you want to build your own site, I would suggest using Next.js or checkout the scrose code of my personal site on github.

⚡Thanks for reading, see you in the next blog.

Top comments (3)

Collapse
 
govindappaarun profile image
Arun Kumar Govindappa

your preview site seems to be down

Collapse
 
eliaschen profile image
EliasChen • Edited

Sorry I already moved it to the main site.
eliaschen.dev

Collapse
 
blackmouse572 profile image
blackmouse572
  1. Tialwindcss -> Tailwindcss
  2. Cool SEO but with little more about header will be great