Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> 關於Linux

Fedora 18 上安裝靜態網站產生器 Awestruct 的踩雷全記錄

Awestruct 是很出色的靜態網站產生框架,靈感來自 Jekyll,以 Ruby 撰寫。它能依模板產出相當漂亮的站點,例如搭配 Bootstrap 或 BluePrint 這兩個家喻戶曉的前端框架。以下記錄在 Fedora 18 上從零安裝的過程,以及一路踩到的坑。

先補依賴庫

否則安裝會直接卡在編譯原生擴充的階段:

Building native extensions. This could take a while...
ERROR: Error installing awestruct:
ERROR: Failed to build gem native extension.
checking for stdio.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.
... The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.

用 root 或 su 一次裝齊:

yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel \
  libyaml-devel libffi-devel openssl-devel make bzip2 \
  autoconf automake libtool bison iconv-devel

其他發行版的使用者請依對應的套件名稱自行替換。

安裝 Ruby 與 RubyGems

yum install ruby ruby-devel ruby-irb rubygems

Fedora 18 的源裡 Ruby 版本相當新,當時安裝的是 1.9.3.327:

libyaml-0.1.4-3.fc18.x86_64
ruby-libs-1.9.3.327-22.fc18.x86_64
ruby-irb-1.9.3.327-22.fc18.noarch
rubygem-json-1.6.5-2.fc18.x86_64
rubygems-1.8.24-3.fc18.noarch
ruby-1.9.3.327-22.fc18.x86_64
ruby-devel-1.9.3.327-22.fc18.x86_64

安裝 Awestruct

gem install awestruct --no-ri --no-rdoc

卻卡在 nokogiri:

Fetching: nokogiri-1.5.5.gem (100%)
ERROR: Error installing awestruct:
invalid gem format for /usr/local/share/gems/cache/nokogiri-1.5.5.gem

這個問題折騰了很久,最後改用 yum 繞過:

yum install -y rubygem-nokogiri

再執行一次安裝,看到下面的輸出就可以恭喜自己了:

Successfully installed awestruct-0.4.7
17 gems installed

但別高興太早,接著用 Bootstrap 模板試著產一個新站:

awestruct -i -f bootstrap

又報錯:

execjs/runtimes.rb:51:in `autodetect': Could not find a JavaScript runtime.
See https://github.com/sstephenson/execjs for a list of available runtimes.
(ExecJS::RuntimeUnavailable)

顧名思義,缺 JavaScript 引擎。我選 NodeJS,遺憾的是它當時沒有 yum 源,只能原始碼編譯:

wget -c 'https://nodejs.org/dist/v0.8.16/node-v0.8.16.tar.gz'
tar zxvf node-v0.8.16.tar.gz
cd node-v0.8.16
./configure
make && make install

編譯完成後驗證:

[root@localhost node-v0.8.16]# node -v
v0.8.16

再跑 awestruct,這次抱怨沒裝 Git:

git version 2>&1:sh: git: 未找到命令 (Git::GitExecuteError)

裝上就好:

yum install git

這回終於順利:

[root@localhost kuuyee.org]# awestruct -i -f bootstrap
Create directory: /root/git_project/kuuyee.org/_config
Create directory: /root/git_project/kuuyee.org/_layouts
Create file: /root/git_project/kuuyee.org/_ext/pipeline.rb
create stylesheets/styles.scss
create javascripts/bootstrap-alert.js
create javascripts/bootstrap-modal.js
create _site/stylesheets/styles.css
Now you're awestruct! To generate your site continuous during
development, simply run: awestruct -d and visit your site at
https://localhost:4242/
Create file: /root/git_project/kuuyee.org/index.html.haml

啟動開發模式:

[root@localhost kuuyee]# awestruct -d
Generating site: https://localhost:4242
Generating: /awestruct-sample/_site/index.html
>> Thin web server (v1.4.1 codename Chromeo)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:4242, CTRL+C to stop

打開 https://localhost:4242/ 就能看到成果。

把警告也清乾淨

輸出裡有一則 rb-inotify 的警告,不想看到任何警告就補裝:

gem install --version '~> 0.8.8' rb-inotify

之後 Listen 就不再退回 polling 模式,也就沒有警告了。大功告成,祝各位安裝順利。

Copyright © Linux教程網 All Rights Reserved