制作htmlbook方法
#!/bin/bash # 基本思路 # 获取主数据(data.dat) #=>获取标题(title.dat) <title></title> #=>制作目录(index.html),以章节标题为内容 #=>分章节{001..055} <p></p> #=>预备内容,分离样本html为两部分a.dat:DTD..<html>..<body><div> b.dat:</div></body></html> #合并文档 #修正标题 mkdir novel/bak -p sed -n '1,58p' data.dat >> index.html # vi... sed -n '1,58p' data.dat >>title.dat awk '{print $1}' title.dat >1.dat awk 'NR>1&&NR!=55{print $1};NR==55{print "$"}' title.dat>2.dat sed -n '1,/<div>/p' ex.html >a.dat sed -n '/<div>/,$p' ex.html | sed '1d' >b.dat cp ../philosophy/justice/htmlbook.css . cp * backup -fv data=`cat data.dat | tr '\n' '\034' | tr ' ' '\032'|tr '\t' '\033'` # 变量i的作用:行数/文件名 # 对于博客的代码高亮插件,千万不要缩进,否则会非常ugly. for i in {001..055};do sed -n "${i}p" title.dat | sed -e "s/^/<li><a href="$i.html">/;s/$/<\/a><\/li>/">>newtitle j=`sed -n "${i}p" 2.dat` echo "$data" | grep -oP "$i.*$j" | tr '\034' '\n' | tr '\032' ' ' | tr '\033' '\t' | sed -n '$d' >$i sed -e 's/^/<p>/g;s/$/<\/p>/g' -i $i cat a.dat $i b.dat >$i.html title=`sed -n "${i}p" title.dat` sed -r "s/<title>.*<\/title>/<title>$title<\/title>/" -i $i.html rm $i -f done
==> title.dat <==
001 河州小镇
002 兰州奇遇
003 迦夏之窟
004 剑使冰璃
005 凉州变故
006 神武观主
007 慕容璇玑
008 沙洲城堡
009 端倪乍现
010 大战周朱
==> 1.dat <==
001
002
003
004
005
006
007
008
009
010
==> 2.dat <==
002
003
004
005
006
007
008
009
010
011
==> a.dat <==
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="htmlbook.css" />
<title>第1课 谋杀的道德侧面 The moral side of murder </title>
</head>
<body>
<div>
==> b.dat <==
<a href="javascript:goPrevious()">上一页<a/> | <a href="javascript:goNext()">下一页<a/>
<script type="text/javascript">
var filename=location.href;
filename=filename.substr(filename.lastIndexOf('/')+1);
//下一页
function goNext(){
goPage(parseInt(filename,10)+1);
}
//上一页
function goPrevious(){
# htmlbook结构
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="htmlbook.css" /> <title>001 河州小镇</title> </head> <body> <div> <p>章节内容</p> <a href="javascript:goPrevious()">上一页<a/> | <a href="javascript:goNext()">下一页<a/> <script type="text/javascript"> var filename=location.href; filename=filename.substr(filename.lastIndexOf('/')+1); //下一页 function goNext(){ goPage(parseInt(filename,10)+1); } //上一页 function goPrevious(){ goPage(parseInt(filename,10)-1); } //进入页号为pagenumber的页面 function goPage(pagenumber){ if(pagenumber<10) pagenumber = "00"+pagenumber; else pagenumber = "0"+pagenumber; window.location.href=pagenumber+".html"; } </script> <a href="index.html">Index</a> </div> </body> </html>