updated git and svn scripts
[xrzperl.git] / epub_blank
blobbd6746e7ad5eb57246ccfe2f253b4f11572fea7f
1 #!/usr/bin/perl -w
2 ###APPNAME: epub_blank
3 ###APPAUTHOR: xiaoranzzz
4 ###APPDATE: Sat Jun 5 00:08:28 2010
5 ###APPVER: 0.1
6 ###APPDESC: epub_blank
7 ###APPUSAGE:
8 ###APPEXAMPLE: epub_blank
9 ###APPOPTION:
10 use strict;
12 #ENV variable MUST be defined somewhere,
13 #FOR perl to search modules from,
14 #OR nothing will work
15 use lib $ENV{XR_PERL_MODULE_DIR};
17 use MyPlace::Script::Usage qw/help_required help_even_empty/;
18 exit 0 if(help_required($0,@ARGV));
19 #exit 0 if(help_even_empty($0,@ARGV));
22 sub make_directory {
23 foreach(@_) {
24 next if(-d $_);
25 mkdir $_ or die("$!\n");
26 print STDERR "directory created $_ \n";
29 sub write_file {
30 my $file = shift;
31 print STDERR "Creating $file ...";
32 if(-f $file) {
33 print STDERR " [Ignored] File exist.\n";
34 return;
36 open FO,">:utf8",$file or die("$!\n");
37 print FO @_;
38 close FO;
39 print STDERR " [OK]\n";
42 my $dir = shift;
43 if($dir) {
44 make_directory($dir);
45 print STDERR "change to \"$dir\"\n";
46 chdir $dir or die("$!\n");
50 make_directory("META-INF");
51 write_file(
52 "META-INF/container.xml",
53 <<'CONTAINER'
54 <?xml version="1.0" encoding="UTF-8" ?>
55 <container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
56 <rootfiles>
57 <rootfile full-path="OPS/content.opf" media-type="application/oebps-package+xml"/>
58 </rootfiles>
59 </container>
60 CONTAINER
63 write_file(
64 "mimetype",
65 "application/epub+zip",
68 make_directory("OPS");
69 my $opf_uuid=`uuid`;
70 chomp $opf_uuid;
72 use POSIX qw/strftime/;
73 my $date=strftime "%Y-%m-%d",localtime;
75 write_file(
76 "OPS/content.opf",
77 <<'OPF'
78 <?xml version="1.0" encoding="UTF-8" ?>
79 <package version="2.0" unique-identifier="PrimaryID" xmlns="http://www.idpf.org/2007/opf">
80 <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
81 <dc:title>NO TITLE</dc:title>
82 OPF
84 "<dc:identifier id=\"PrimaryID\" opf:scheme=\"URN\">urn:uuid:$opf_uuid</dc:identifier>\n"
86 "<dc:date opf:event=\"original-publication\">$date</dc:date>\n"
88 <<'OPF'
89 <dc:language>en</dc:language>
90 <dc:creator opf:role="aut" opf:file-as="NO CREATOR">NO CREATOR</dc:creator>
91 <dc:publisher>NO PUBLISHER</dc:publisher>
92 <dc:description>NO DESCRIPTION</dc:description>
93 <dc:coverage>NO COVERAGE</dc:coverage>
94 <dc:source>NO SOURCE</dc:source>
95 <dc:rights>NO RIGHTS</dc:rights>
96 <dc:subject>NO SUBJECT</dc:subject>
97 <dc:subject>NO SUBJECT</dc:subject>
98 <meta name="cover" content="images-cover"/>
99 </metadata>
101 <manifest>
102 <!-- Content Documents -->
103 <item id="cover"
104 href="cover.xhtml"
105 media-type="application/xhtml+xml"/>
106 <item id="images-cover"
107 href="images/cover.jpg"
108 media-type="image/jpeg"/>
109 <item id="css-style"
110 href="css/style.css"
111 media-type="text/css"/>
112 <item id="ncx"
113 href="toc.ncx"
114 media-type="application/x-dtbncx+xml"/>
115 </manifest>
117 <spine toc="ncx">
118 <itemref idref="cover" linear="yes"/>
119 </spine>
121 <guide>
122 <reference type="cover" title="Cover" href="cover.xhtml"/>
123 </guide>
125 </package>
129 my $ncx_uuid = `uuid`;
130 chomp $ncx_uuid;
131 write_file(
132 "OPS/toc.ncx",
133 <<'NCX'
134 <?xml version="1.0" encoding="UTF-8"?>
136 <!DOCTYPE ncx PUBLIC
137 "-//NISO//DTD ncx 2005-1//EN"
138 "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">
140 <ncx version="2005-1"
141 xml:lang="en"
142 xmlns="http://www.daisy.org/z3986/2005/ncx/">
144 <head>
145 <!-- The following four metadata items are required for all
146 NCX documents, including those conforming to the relaxed
147 constraints of OPS 2.0 -->
150 "<meta name=\"dtb:uid\" content=\"$ncx_uuid\"/>\n"
152 <<'NCX'
153 <meta name="dtb:depth" content="1"/>
154 <meta name="dtb:totalPageCount" content="0"/>
155 <meta name="dtb:maxPageNumber" content="0"/>
156 </head>
157 <docTitle>
158 <text>NO TITLE</text>
159 </docTitle>
160 <docAuthor>
161 <text>NO AUTHOR</text>
162 </docAuthor>
163 <navMap>
164 <navPoint class="cover" id="cover" playOrder="1">
165 <navLabel><text>Cover</text></navLabel>
166 <content src="cover.xhtml"/>
167 </navPoint>
168 </navMap>
169 </ncx>
173 write_file(
174 "OPS/cover.xhtml",
175 <<'COVER'
176 <?xml version="1.0" encoding="UTF-8" ?>
177 <!DOCTYPE html PUBLIC
178 "-//W3C//DTD XHTML 1.1//EN"
179 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
180 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
181 <head>
182 <title>Cover</title>
183 <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8"/>
184 </head>
185 <body>
186 <div style="text-align: center; page-break-after: always;">
187 <img src="images/cover.jpg" alt="Cover" style="height: 100%; max-width: 100%;" />
188 </div>
189 </body>
190 </html>
191 COVER
194 make_directory("OPS/images");
195 make_directory("OPS/css");
196 write_file(
197 "OPS/css/style.css",
198 <<'CSS'
199 .chapter {
202 .chapter_title {
205 .chapter_content {
208 .paragraph {
211 .footer {
214 .copyright {