##language:zh #pragma section-numbers off ##含有章节索引导航的 ZPyUG 文章通用模板 <> ## 默许导航,请保留 <> = ScrapBook输出重整 = ##startInc == 问题 == 常常有人问: * http://floss.zoomquiet.org * http://skm.zoomquiet.org 首页怎么生成的... {{attachment:zq_2010-09-16-171526_523x471_scrot.png}} * 其实是[[https://addons.mozilla.org/zh-CN/firefox/addon/427/|ScrapBook]] 人家自个儿的功能哪! * Ctrl+f 打开 ScrapBook 侧栏->工具->导出项目列表 ^选择"连帧输出"^ * 只是有个小问题: * 默认输出的 index.html 是索引页面,frame.html 才是帧结构页 * 想同步发布到网站中,就得转换一下: 1. 将 index.html 复制成 idx.html 1. 将 frame.html 复制成 index.html 1. 修订 frame.html 对应将 idx.html 定义成包含的页面 所以,写了个脚本来自动修订... == fixhtmlexp.py == {{{ #!python # coding : utf-8 import sys,os,string,stat import time,datetime __version__="fixhtmlexp.py 0.9.1" class fixhtmlexp: """main class zip all done """ def __init__(self): """ini all """ self.dirbook = sys.argv[1] self.dirtree = "tree/" self.tree = "frame.html" self.index = "index.html" self.idx = "idx.html" self.daylog = "%s"%(time.strftime("%y%m%d %H:%M:%S",time.localtime())) def idxit(self): """re index the tree of ScrapBook: - replace src="./index.html" as src="./idx.html" in frame.html - if replaced ,cancel flow ..! judge by SIZE of index.html - cp index.html as idx.html - cp frame.html as index.html """ root = self.dirbook+self.dirtree oldframe = open(root+self.tree).read() print "%s ST_SIZE::%s"%((root+self.index),os.stat(root+self.index)[stat.ST_SIZE]) if 800 < os.stat(root+self.index)[stat.ST_SIZE]: # not replace yet newframe = string.replace(oldframe,"index.html","idx.html") open(root+self.idx,"w").write(open(root+self.index).read()) open(root+self.index,"w").write(newframe) else: print "replaced! do nothing..." def title(self): """readt scrpabook export index.html: - fixed Title for zoomquiet.org """ expname = self.dirbook.split("/")[1] orgiIdx = open(self.dirbook+self.dirtree+self.index) mark = "" retit = "" for line in orgiIdx: if mark in line: #print line if "" not in line: retit += line else: print line newTit=''' %s in zoomquiet.org reformat by %s {%s}-ScrapBook '''%(expname,__version__,self.daylog) print newTit retit += newTit else: retit += line orgiIdx.close() open(self.dirbook+self.dirtree+self.index,"w").write(retit) if __name__ == '__main__': fix = fixhtmlexp() fix.idxit() print ":::And fixed title" fix.title() }}} === 使用 === {{{ # 将脚本部属在任何目录中 $ python fixhtmlexp.py /path/2/my/scrapbook/ # 指定要处理哪个 ScrapBook 本地目录中的导出含帖索引页面, # 一般目录下的文件结构是: +-- backup +-- data +-- GDscratchPad +-- icon +-- tree |-- blockcomment.css |-- folders.txt |-- note.html |-- note_template.html `-- scrapbook.rdf }}} ##endInc ---- '''反馈''' 创建 by -- ZoomQuiet [<>]