How to create a website by using R blogdown and hugo theme
Image from Google
In this post, I want to share with you how to create a website for free by using R blogdown.
If you are totally new with R studio, github, git,…let’s get started by installing somethings.
1. Install things
- Install R studio
- Create Github account (free)
- Install git
- Download blogdown package, and devtools (if needed)
- Download hugo package
2. Set up your pre-born website
-
You go to your Github account: in the overview tab, click “New” to create a new repository that will store all content of your R documents related to your website. After you click “Create repository”, you will see that repository apprears as one of the project in you Github page, you click to “Code” and copy the url link.
-
You go to R: File -> New project -> Version control -> Git -> paste the link that you’ve just copied. Then a (semi-)empty project is created.
-
In the console, you check the version of hugo by type: hugo_version() -> enter. It’s very important, you will know why later.
-
Go to themes.gohugo.io to choose the theme that you like. Clicking to the link will lead you to that theme page. If you see the buttom “Homepage” click to it. If you don’t, search google: “[name_of_your_chosen_theme] github”. Then go to its Github repository. Copy the whole name of the theme (line on the top which includes author’s name/theme’s name)
-
Go to R studio. In the console, you type blogdown::new_site(theme = “it-gro/hugo-theme-w3css-basic”. Remove exceeded spaces. Then press enter. When it finish, you have a webpage built in your local computer.
-
Tell R/Git who you are: Go to Tools -> Shell. If you don’t find “shell” in tools, no worries, just go to terminal (the tab next to console). You type: git config –global user.name “put_your_Github_username”. Then hit enter
-
You type: git config –global user.email “put_your_email_you_used_for_github”. Then hit enter
-
Now you commit everything you’ve just added to github. STill in the terminal, you type: git add -A.
-
On the Git window, you see all boxes are checked. Click “commit”, type comments, click “commit”. when it’s done, close that small window. Then click “push”
3. Set up your website in Netlify:
- On your account page, click tab “Sites” -> “add new site” -> “import an existing project” -> “github” -> choose your github project
- Click “show advance” -> click “new variable”. In the “key” box, you type: “HUGO_VERSION”. In the “Value” box, you paste the version of hugo.
- Click “deploy”. When a new page appears, you click to “deploy new site”. Then you’re almost done.
- If you want to change domain, go to deploy setting, change the domain.
- If links in your website don’t appear in the way the should, go back to R studio, look for config.toml file. The first line (commonly), replace the baseurl link by your actual web link, save it, and commit it. Your’re done.
That’s it. Let try it and good luck!
Note: If you have any questions along the way, just google and seek for answers in Github. I think ChatGPT may not be very helpful in this case.
Additional materials: