Hexo 静态网页博客

SVN

1
2
3
4
5
6
sudo apt-get install subversion
sudo apt-get install libapache2-svn

## 以 ~/SOME_PROJ 作文章源为例
cd ~
svn co https://xxxx.com/SOME_PROJ

发布脚本

  • 受 SVN 控制的文章(页面)源目录: ~/SOME_PROJ/pages
  • build 过后生成 hexo 所支持的 md 文件目录: ~/SOME_PROJ/bin/pages
  • 博客工程目录: ~/blog
  • 发布脚本路径: ~/publish.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash

page="$1"
content="$2"

cd ~/SOME_PROJ
svn up

echo "${content}" > "./pages/${page}/index.md"
svn ci -m "## Update ${page}"

## 自定义「编译」脚本
./build.sh

## 此处博客工程为 ~/blog
cp -r ./bin/pages/* ~/blog/source/

. ~/.bash_profile
cd ~/blog; hexo g -d

echo "Publish successfully!!!"

Apache 用户 - 特定脚本执行免 sudo 密码

sudo visudo,添加内容。当前用户为 SOMEONE

1
www-data ALL=(ALL) NOPASSWD: /home/SOMEONE/apache-publish.sh

新建 ~/apache-publish.sh,内容为

1
2
3
4
5
#!/bin/bash

page="$1"
content="$2"
su SOMEONE -c "~/publish.sh \"${page}\" \"${content}\""

PHP 后端调用

1
2
$shell = sprintf('sudo /home/SOMEONE/apache-publish.sh "%s" "%s"', $page, $content);
shell_exec($shell);

.htaccess 支持

Set Up Apache Virtual Hosts on Ubuntu

创建 xxxx.com.conf 文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<VirtualHost *:80>

<Directory /var/www/xxxx.com>
AllowOverride All
Require all granted
</Directory>

ServerAdmin admin@xxxx.com
ServerName xxxx.com
ServerAlias www.xxxx.com
DocumentRoot /var/www/xxxx.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

载入配置,重启 apache

1
2
3
sudo a2enmod rewrite
sudo a2ensite xxxx.com.conf
sudo service apache2 restart