Skip to content

ramsayleung/blog

Repository files navigation

*Attention*: Because Rocket is sensitive with compiler and it highly depends on lately nightly compiler, so it’s so easy to fail when compiling this project.

Update(2021-06-10): Since Rocket can compile on stable Rust with v0.5, this project leveraging on Rocket's features can also compile on stable Rust now. Cheers!

About

This is my personal blog, and its also my first Rust project.

Why Rust

Well, I know there are a lot of alternatives to writing a blog, but I find other languages such as Java, Python, Javascript,Php, are not fancy enough ;-) Kidding, the truth is that I have learned Rust for more that a half years, but I still could not build real some stuff on Rust. Yes, I lack of idea or I not am skillful enough to fulfill my thought. Finally, I decided to rewrite my blog which was built on Github Page and Org-mode.

Getting Started

Requirement

Rust

Install Rust via shell script

curl https://sh.rustup.rs -sSf | sh

After installing, you might need to

source $HOME/.cargo/env

Because this project is built on Rocket, and Rocket depends on Rust nightly, so you need change Rust environment to nightly

rustup default stable

Diesel Cli

This project use Diesel as Orm framework, so you need to install its command line tool via Rust package manager(eg, Cargo)

cargo install diesel_cli --no-default-features --features postgres

Postgresql

you need to install Postgresql database, and then configure postgresql by following document’s guide

Init database

After everything is done, it is time to create table in database for this project, just run

diesel migration run

Set up envirnment variables

In the last step, you need to create a file named .env in the root of your repository, set up the following envirnment variables, for examples:

DATABASE_URL=postgres://postgres:postgres@localhost/blog
STACKOVERFLOW_URL=https://stackoverflow.com/users/5738112/samray
GITHUB_URL=https://github.com/ramsayleung/
ERROR_LOG_PATH=/tmp/common-error.log
APP_LOG_PATH=/tmp/app-default.log
[email protected]
SLOGAN="Ramsay's Utopia"
SUB_SLOGAN="fn<T:time+joy>(resource: T)-> Ramsay's Blog"
DB_NAME=blog
DB_USER=username
DB_PASSWORD=passwd

Launch Rocket

Everything is ok, now, launch Rocket:

cargo run

And open your favourite browser, enter localhost:1337

If you want to login admin page, you could enter localhost:1337/admin/login Email: admin Password: 123456

Todo List

  • refactor admin page, it is unacceptedly ugly.

Screenshot

About Page

./images/about.png

Index Page

./images/index.png