Total Pageviews

Tuesday 1 November 2016

在mac上搭建基于hakyll的静态博客程序sproul.xyz,然后把本地mac机器的静态网站上传到linux vps

首先在mac上运行
curl -sSL https://get.haskellstack.org/ | sh (安装stack)

运行brew install ghc来安装ghc.

stack install hakyll (最好在vpn下运行)

brew install sassc
会显示:
...
==> Installing dependencies for sassc: libsass
==> Installing sassc dependency: libsass
==> Downloading https://homebrew.bintray.com/bottles/libsass-3.3.6.el_capitan.bo
######################################################################## 100.0%
==> Pouring libsass-3.3.6.el_capitan.bottle.tar.gz
🍺  /usr/local/Cellar/libsass/3.3.6: 15 files, 4.8M
==> Installing sassc
==> Downloading https://homebrew.bintray.com/bottles/sassc-3.3.2.el_capitan.bott
######################################################################## 100.0%
==> Pouring sassc-3.3.2.el_capitan.bottle.tar.gz
🍺  /usr/local/Cellar/sassc/3.3.2: 5 files, 23.9K

 git clone https://github.com/michaelsproul/sproul.xyz
 cd sproul.xyz
 stack setup --resolver ghc-7.10.3
 stack build
 会显示:
...
 Linking .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/site/site

 Installing executable(s) in
 /Users/brite/sproul.xyz/.stack-work/install/x86_64-osx/lts-6.14/7.10.3/bin

运行:
  .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/site/site build (此即生成静态网站的根目录的命令。会在当前目录下生成_site目录)

 cd _site
 python -m SimpleHTTPServer 34567 > /dev/null &

 demo site: http://localhost:34567 (在mac机器上的浏览器,访问此网址即可看到网站效果)

 tar zcvf _site.tar.gz * (此命令的意思是把_site目录内的所有东西打包为_site.tar.gz文件)

 scp _site.tar.gz root@my_vps_ip:/var/www/sproul.xyz (此命令的意思是把_site.tar.gz文件上传到我的vps的/var/www/sproul.xyz/目录(你必须先在linux vps上建立/var/www/sproul.xyz目录)

然后登陆linux vps,
cd /var/www/sproul.xyz/
tar zxvf _site.tar.gz

root@AR:/var/www/sproul.xyz# ls
404.html    favicon.ico  js       posts   _site.tar.gz
about.html  foundation papers       posts.html  tags
css     index.html papers.html  rss.xml
root@AR:/var/www/sproul.xyz#
(/var/www/sproul.xyz/里有index.html文件,可见/var/www/sproul.xyz/就是静态网站的根目录,你可绑定域名到该目录)

新建源贴:
回到mac的terminal.
yudeMacBook-Air:~ brite$ cd sproul.xyz
yudeMacBook-Air:sproul.xyz brite$ ls
404.html _site favicon.ico papers site.hs
LICENSE about.md foundation papers.md stack.yaml
README.md config index.md posts templates
_cache css js site.cabal
yudeMacBook-Air:sproul.xyz brite$ cd posts
yudeMacBook-Air:posts brite$ nano test-1.md
yudeMacBook-Air:posts brite$ cat test-1.md
---
title: 测试1
date: 2016-10-30
tags: misc1, misc2
metadescription: abc
---

这是测试1.

看看如何呢?
yudeMacBook-Air:posts brite$ cd ..
yudeMacBook-Air:sproul.xyz brite$ .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/site/site build
yudeMacBook-Air:sproul.xyz brite$ cd _site
yudeMacBook-Air:_site brite$ ls
404.html css index.html papers.html rss.xml
_site.tar.gz favicon.ico js posts tags
about.html foundation papers posts.html
yudeMacBook-Air:_site brite$ rm _site.tar.gz (删除旧的_site.tar.gz)
yudeMacBook-Air:_site brite$ tar zcvf _site.tar.gz *
yudeMacBook-Air:_site brite$ scp _site.tar.gz root@my_vps_ip:/var/www/sproul.xyz/

然后登陆linux vps,
cd /var/www/sproul.xyz/
tar zxvf _site.tar.gz (此命令解压新的_site.tar.gz文件,解压出来的内容将覆盖之前的旧内容,这样网站就得到了更新。)

演示网站:http://sx.bright.biz.st
项目地址:https://github.com/michaelsproul/sproul.xyz/

我为什么不直接在linux vps上,搭建这个静态博客程序呢?因为在linux vps上,运行"./site build"遇错,而在linux vps上,这个错误(https://github.com/michaelsproul/sproul.xyz/issues/1)一时解决不了,而在mac上,不会遇到这个错误,所以就先在mac上,搭建这个程序,然后把mac上所生成的静态网站上传到linux vps。