Pages

Saturday, 5 November 2016

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

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

运行brew install ghc来安装ghc.

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

stack install shake
brew install pkg-config 
brew install imagemagick
brew install zopfli
brew install bro
wget http://download.osgeo.org/gdal/2.1.2/gdal-2.1.2.tar.gz 
tar zxvf gdal-2.1.2.tar.gz 
cd gdal-2.1.2
./configure
make
make install
cd ~

git clone https://github.com/dikmax/dikmax.name-ng
cd dikmax.name-ng
stack build
会显示
...
Linking 
.stack-work/dist/x86_64-osx/Cabal-1.24.0.0/build/dikmax.name/dikmax.name
...
yudeMacBook-Air:dikmax.name-ng brite$ .stack-work/dist/x86_64-osx/Cabal-1.24.0.0/build/dikmax.name/dikmax.name build (此即生成静态网站的根目录的命令)
显示:
...
Error when running Shake build system:
  • build
  • sync-images
  • getDirectoryFiles "/Users/dikmax/Google Drive/dikmax.name-images/" [//*] /Users/dikmax/Google Drive/dikmax.name-images/: getDirectoryContents: does not exist (No such file or directory)
yudeMacBook-Air:dikmax.name-ng brite$ 
解决办法:
yudeMacBook-Air:dikmax.name-ng brite$ mkdir images
yudeMacBook-Air:dikmax.name-ng brite$ nano build.cfg
yudeMacBook-Air:dikmax.name-ng brite$ cat build.cfg
IMAGES_DIR = images/
(然后复制你mac机子中的一些图片到此images/目录)
yudeMacBook-Air:dikmax.name-ng brite$ .stack-work/dist/x86_64-osx/Cabal-1.24.0.0/build/dikmax.name/dikmax.name build
yudeMacBook-Air:dikmax.name-ng brite$ ls
404.md data package.json
HLint.hs demos postcss.json
LICENSE dikmax-name.cabal posts
Setup.hs favicons robots.txt
_build images scripts
about.md index.md src
build.cfg map stack.yaml
build.sh node_modules styles
(生成了_build目录)
yudeMacBook-Air:dikmax.name-ng brite$ cd _build
yudeMacBook-Air:_build brite$ ls
images map pandoc shake site
yudeMacBook-Air:_build brite$ cd site
yudeMacBook-Air:site brite$ ls
404 index.html
about manifest.json
android-chrome-192x192.png map
apple-touch-icon.png mstile-150x150.png
archive page
browserconfig.xml post
css publisher_logo.png
data robots.txt
dikmax.name.tar.gz safari-pinned-tab.svg
favicon-16x16.png scripts
favicon-32x32.png sitemap.xml
favicon.ico tag
feed.rss yandex-widget-manifest.json
images
(当前目录-site目录下有index.html,可见这个site目录即为静态网站的根目录)
yudeMacBook-Air:site brite$ python -m SimpleHTTPServer 2346 > /dev/null &
然后在mac机子上的浏览器中,访问http://localhost:2346,即可看到网站效果。

新建源帖:
yudeMacBook-Air:site brite$ pwd
/Users/brite/dikmax.name-ng/_build/site
yudeMacBook-Air:site brite$ cd ../..
yudeMacBook-Air:dikmax.name-ng brite$ cd posts 
yudeMacBook-Air:posts brite$ ls
2016
yudeMacBook-Air:posts brite$ cd 2016
yudeMacBook-Air:2016 brite$ nano 2016-11-06-test-1.md
yudeMacBook-Air:2016 brite$ cat 2016-11-06-test-1.md
---
title: 测试1
date: "2016-11-06T10:00:00+01:00"
collections: [latest-travel]
author: "brite fisher"
published: true
tags: [misc1, misc2, misc3]
cover:
      img: /images/hair.jpg
      hcenter: 0%
      vcenter: 0%
---

这是测试1.

看看如何呢?
(以上的粉红色部分可以不写)
yudeMacBook-Air:2016 brite$ 
yudeMacBook-Air:2016 brite$ pwd
/Users/brite/dikmax.name-ng/posts/2016
yudeMacBook-Air:2016 brite$ cd ../..
yudeMacBook-Air:dikmax.name-ng brite$ .stack-work/dist/x86_64-osx/Cabal-1.24.0.0/build/dikmax.name/dikmax.name build
(也可以运行stack exec dikmax.name)
yudeMacBook-Air:dikmax.name-ng brite$ cd _build/site
yudeMacBook-Air:site brite$ tar zcvf dikmax.name.tar.gz *
yudeMacBook-Air:site brite$ scp dikmax.name.tar.gz root@my_vps_ip:/var/www/dikmax.name/
(你必须先在linux vps上建立/var/www/dikmax.name目录.等待上传完成。出现提示符,则表明上传成功。上传成功后,即可删除dikmax.name.tar.gz,省得以后打包site目录时,把这个旧的dikmax.name.tar.gz也打包了进去。)

然后登陆linux vps,
cd /var/www/dikmax.name/
tar zxvf dikmax.name.tar.gz

root@AR:/var/www/dikmax.name# ls
404     favicon-16x16.png page
about     favicon-32x32.png post
android-chrome-192x192.png  favicon.ico publisher_logo.png
apple-touch-icon.png     feed.rss robots.txt
archive     images safari-pinned-tab.svg
browserconfig.xml     index.html scripts
css     manifest.json sitemap.xml
data     map tag
dikmax.name.tar.gz     mstile-150x150.png yandex-widget-manifest.json
root@AR:/var/www/dikmax.name# 
(可见/var/www/dikmax.name就是静态网站的根目录,你可绑定域名到该目录)

演示网站:http://dn.bright.biz.st, https://dikmax.name
项目地址:https://github.com/dikmax/dikmax.name-ng,
https://github.com/dikmax/dikmax.name-ng/issues/1

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

相关帖子:http://briteming.blogspot.com/2016/11/machakyllsproulxyzlinux-vps.html