layout html output

This commit is contained in:
Fabian Graßl 2010-10-15 18:00:22 +02:00
parent c831770aa2
commit 38ef73c4a7
4 changed files with 141 additions and 36 deletions

View File

@ -0,0 +1,60 @@
body{
padding:0px;
margin:0px;
background-color:#F6F3E9;
font-size:12px;
font-family:Arial, Helvetica, sans-serif;
}
.calibreMeta{
background-color:#39322B;
color:white;
padding:10px;
}
.calibreMeta a, .calibreEbNav a, .calibreEbNavTop a, .calibreToc a{
color:white;
}
.calibreMeta h1{
margin:0px;
font-size:18px;
background-color:#39322B;
}
.calibreEbookContent{
padding:20px;
}
.calibreEbNav, .calibreEbNavTop{
clear:both;
background-color:#39322B;
color:white;
padding:10px;
text-align:center;
}
.calibreEbNavTop{
margin-bottom:20px;
}
.calibreEbNav a, .calibreEbNavTop a{
padding:0px 5px;
}
.calibreTocIndex{
line-height:18px;
}
.calibreToc{
float:left;
margin:20px;
width:300px;
background-color:#39322B;
color:white;
padding:10px;
}
.calibreEbookContent{
width:600px;
float:left;
}

View File

@ -2,49 +2,73 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
${head_content}$
<link href="${cssLink}$" type="text/css" rel="stylesheet" />
</head>
<body>
<div class="meta">
<div class="metaTitle">
<div class="calibreMeta">
<div class="calibreMetaTitle">
${pos1=1}$
${for title in meta.titles():}$
${if pos1:}$
<h1>${print title}$</h1>
<h1>
<a href="${tocUrl}$">${print title}$</a>
</h1>
${:else:}$
<div class="metaSubtitle">${print title}$</div>
<div class="calibreMetaSubtitle">${print title}$</div>
${:endif}$
${pos1=0}$
${:endfor}$
</div>
<div class="metaAuthor">
<div class="calibreMetaAuthor">
${print ', '.join(meta.creators())}$
</div>
</div>
<div class="toc">
<h2>${print _('Table of contents'),}$</h2>
${print toc()}$
</div>
<div class="calibreMain">
<div class="ebookContent">
<div class="calibreEbookContent">
${if prevLink or nextLink:}$
<div class="calibreEbNavTop">
${if prevLink:}$
<a href="${prevLink}$" class="calibreAPrev">${print _('previous page'),}$</a>
${:else:}$
<a href="${tocUrl}$" class="calibreAPrev">${print _('previous page'),}$</a>
${:endif}$
${ebookContent}$
<div class="ebookNavigation">
${if prevLink:}$
<a href="${prevLink}$">${print _('previous page'),}$</a>
${if nextLink:}$
<a href="${nextLink}$" class="calibreANext">${print _('next page'),}$</a>
${:endif}$
</div>
${:endif}$
${ebookContent}$
</div>
${if has_toc:}$
<div class="calibreToc">
<h2><a href="${tocUrl}$">${print _('Table of contents'),}$</a></h2>
${print toc()}$
</div>
${:endif}$
<div class="calibreEbNav">
${if prevLink:}$
<a href="${prevLink}$" class="calibreAPrev">${print _('previous page'),}$</a>
${:else:}$
<a href="${tocUrl}$" class="calibreAPrev">${print _('previous page'),}$</a>
${:endif}$
<a href="${tocUrl}$" class="calibreAHome">${print _('start'),}$</a>
${if nextLink:}$
<a href="${nextLink}$">${print _('next page'),}$</a>
<a href="${nextLink}$" class="calibreANext">${print _('next page'),}$</a>
${:endif}$
</div>
</div>
</body>
</html>

View File

@ -6,37 +6,55 @@
<link rel="schema.DC" href="http://purl.org/dc/elements/1.1/" />
<link rel="schema.DCTERMS" href="http://purl.org/dc/terms/" />
<title></title>
<title>${print ', '.join(meta.creators()),}$ - ${print meta.titles().next(); meta.titles().close()}$</title>
${for item in meta:}$
<meta ${print 'name="DC.'+item['name']+'"',}$ ${print 'content="'+item['value']+'"',}$ />
${:endfor}$
<link href="${cssLink}$" type="text/css" rel="stylesheet" />
</head>
<body>
<div class="meta">
<div class="metaTitle">
<div class="calibreMeta">
<div class="calibreMetaTitle">
${pos1=1}$
${for title in meta.titles():}$
${if pos1:}$
<h1>${print title}$</h1>
<h1>
<a href="${tocUrl}$">${print title}$</a>
</h1>
${:else:}$
<div class="metaSubtitle">${print title}$</div>
<div class="calibreMetaSubtitle">${print title}$</div>
${:endif}$
${pos1=0}$
${:endfor}$
</div>
<div class="metaAuthor">
<div class="calibreMetaAuthor">
${print ', '.join(meta.creators()),}$
</div>
</div>
<h2>${print _('Table of contents'),}$</h2>
<div class="calibreMain">
<div class="calibreEbookContent">
<div class="ebookContent">
${if has_toc:}$
<div class="calibreTocIndex">
<h2>${print _('Table of contents'),}$</h2>
${toc}$
</div>
${:else:}$
<h2>${print _('No table of contents present'),}$</h2>
<div><strong><a href="${nextLink}$">${print _('begin to read'),}$</a></strong></div>
${:endif}$
${toc}$
</div>
<div class="calibreEbNav">
${if nextLink:}$
<a href="${nextLink}$" class="calibreANext">${print _('next page'),}$</a>
${:endif}$
</div>
</div>
</body>

View File

@ -56,11 +56,6 @@ class HTMLOutput(OutputFormatPlugin):
return etree.tostring(root, pretty_print=True, encoding='utf-8', xml_declaration=False)
def convert(self, oeb_book, output_path, input_plugin, opts, log):
if oeb_book.toc.count() == 0:
if len(oeb_book.spine) > 1:
pass
else:
pass
self.log = log
self.opts = opts
output_file = output_path
@ -69,12 +64,18 @@ class HTMLOutput(OutputFormatPlugin):
if not exists(output_dir):
os.makedirs(output_dir)
css_path = output_dir+os.sep+'calibreHtmlOutBasicCss.css'
with open(css_path, 'wb') as f:
f.write(P('templates/html_export_default.css', data=True))
with open(output_file, 'wb') as f:
link_prefix=basename(output_dir)+'/'
html_toc = self.generate_html_toc(oeb_book, output_file, output_dir)
templite = Templite(P('templates/html_export_default_index.tmpl', data=True))
print oeb_book.metadata.items
t = templite.render(toc=html_toc, meta=meta)
nextLink = oeb_book.spine[0].href
nextLink = relpath(output_dir+os.sep+nextLink, dirname(output_file))
cssLink = relpath(abspath(css_path), dirname(output_file))
t = templite.render(has_toc=bool(oeb_book.toc.count()), toc=html_toc, meta=meta, nextLink=nextLink, tocUrl=output_file, cssLink=cssLink)
f.write(t)
with CurrentDir(output_dir):
@ -121,10 +122,12 @@ class HTMLOutput(OutputFormatPlugin):
else:
prevLink = None
cssLink = relpath(abspath(css_path), dir)
# render template
templite = Templite(P('templates/html_export_default.tmpl', data=True))
toc = lambda: self.generate_html_toc(oeb_book, path, output_dir)
t = templite.render(ebookContent=ebook_content, prevLink=prevLink, nextLink=nextLink, toc=toc, head_content=head_content, meta=meta)
t = templite.render(ebookContent=ebook_content, prevLink=prevLink, nextLink=nextLink, has_toc=bool(oeb_book.toc.count()), toc=toc, tocUrl=output_file, head_content=head_content, meta=meta, cssLink=cssLink)
# write html to file
with open(path, 'wb') as f: