mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
layout html output
This commit is contained in:
parent
c831770aa2
commit
38ef73c4a7
60
resources/templates/html_export_default.css
Normal file
60
resources/templates/html_export_default.css
Normal 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;
|
||||||
|
}
|
@ -2,49 +2,73 @@
|
|||||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
<head>
|
<head>
|
||||||
${head_content}$
|
${head_content}$
|
||||||
|
|
||||||
|
<link href="${cssLink}$" type="text/css" rel="stylesheet" />
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div class="meta">
|
<div class="calibreMeta">
|
||||||
<div class="metaTitle">
|
<div class="calibreMetaTitle">
|
||||||
${pos1=1}$
|
${pos1=1}$
|
||||||
${for title in meta.titles():}$
|
${for title in meta.titles():}$
|
||||||
${if pos1:}$
|
${if pos1:}$
|
||||||
<h1>${print title}$</h1>
|
<h1>
|
||||||
|
<a href="${tocUrl}$">${print title}$</a>
|
||||||
|
</h1>
|
||||||
${:else:}$
|
${:else:}$
|
||||||
<div class="metaSubtitle">${print title}$</div>
|
<div class="calibreMetaSubtitle">${print title}$</div>
|
||||||
${:endif}$
|
${:endif}$
|
||||||
${pos1=0}$
|
${pos1=0}$
|
||||||
${:endfor}$
|
${:endfor}$
|
||||||
</div>
|
</div>
|
||||||
<div class="metaAuthor">
|
<div class="calibreMetaAuthor">
|
||||||
${print ', '.join(meta.creators())}$
|
${print ', '.join(meta.creators())}$
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="toc">
|
<div class="calibreMain">
|
||||||
<h2>${print _('Table of contents'),}$</h2>
|
|
||||||
${print toc()}$
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="ebookContent">
|
<div class="calibreEbookContent">
|
||||||
|
${if prevLink or nextLink:}$
|
||||||
${ebookContent}$
|
<div class="calibreEbNavTop">
|
||||||
|
|
||||||
<div class="ebookNavigation">
|
|
||||||
${if prevLink:}$
|
${if prevLink:}$
|
||||||
<a href="${prevLink}$">${print _('previous page'),}$</a>
|
<a href="${prevLink}$" class="calibreAPrev">${print _('previous page'),}$</a>
|
||||||
|
${:else:}$
|
||||||
|
<a href="${tocUrl}$" class="calibreAPrev">${print _('previous page'),}$</a>
|
||||||
${:endif}$
|
${:endif}$
|
||||||
|
|
||||||
${if nextLink:}$
|
${if nextLink:}$
|
||||||
<a href="${nextLink}$">${print _('next page'),}$</a>
|
<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}$" class="calibreANext">${print _('next page'),}$</a>
|
||||||
${:endif}$
|
${:endif}$
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -6,37 +6,55 @@
|
|||||||
<link rel="schema.DC" href="http://purl.org/dc/elements/1.1/" />
|
<link rel="schema.DC" href="http://purl.org/dc/elements/1.1/" />
|
||||||
<link rel="schema.DCTERMS" href="http://purl.org/dc/terms/" />
|
<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:}$
|
${for item in meta:}$
|
||||||
<meta ${print 'name="DC.'+item['name']+'"',}$ ${print 'content="'+item['value']+'"',}$ />
|
<meta ${print 'name="DC.'+item['name']+'"',}$ ${print 'content="'+item['value']+'"',}$ />
|
||||||
${:endfor}$
|
${:endfor}$
|
||||||
|
|
||||||
|
<link href="${cssLink}$" type="text/css" rel="stylesheet" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div class="meta">
|
<div class="calibreMeta">
|
||||||
<div class="metaTitle">
|
<div class="calibreMetaTitle">
|
||||||
${pos1=1}$
|
${pos1=1}$
|
||||||
${for title in meta.titles():}$
|
${for title in meta.titles():}$
|
||||||
${if pos1:}$
|
${if pos1:}$
|
||||||
<h1>${print title}$</h1>
|
<h1>
|
||||||
|
<a href="${tocUrl}$">${print title}$</a>
|
||||||
|
</h1>
|
||||||
${:else:}$
|
${:else:}$
|
||||||
<div class="metaSubtitle">${print title}$</div>
|
<div class="calibreMetaSubtitle">${print title}$</div>
|
||||||
${:endif}$
|
${:endif}$
|
||||||
${pos1=0}$
|
${pos1=0}$
|
||||||
${:endfor}$
|
${:endfor}$
|
||||||
</div>
|
</div>
|
||||||
<div class="metaAuthor">
|
<div class="calibreMetaAuthor">
|
||||||
${print ', '.join(meta.creators()),}$
|
${print ', '.join(meta.creators()),}$
|
||||||
</div>
|
</div>
|
||||||
</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}$
|
${toc}$
|
||||||
|
</div>
|
||||||
|
${:else:}$
|
||||||
|
<h2>${print _('No table of contents present'),}$</h2>
|
||||||
|
<div><strong><a href="${nextLink}$">${print _('begin to read'),}$</a></strong></div>
|
||||||
|
${:endif}$
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="calibreEbNav">
|
||||||
|
${if nextLink:}$
|
||||||
|
<a href="${nextLink}$" class="calibreANext">${print _('next page'),}$</a>
|
||||||
|
${:endif}$
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
@ -56,11 +56,6 @@ class HTMLOutput(OutputFormatPlugin):
|
|||||||
return etree.tostring(root, pretty_print=True, encoding='utf-8', xml_declaration=False)
|
return etree.tostring(root, pretty_print=True, encoding='utf-8', xml_declaration=False)
|
||||||
|
|
||||||
def convert(self, oeb_book, output_path, input_plugin, opts, log):
|
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.log = log
|
||||||
self.opts = opts
|
self.opts = opts
|
||||||
output_file = output_path
|
output_file = output_path
|
||||||
@ -69,12 +64,18 @@ class HTMLOutput(OutputFormatPlugin):
|
|||||||
if not exists(output_dir):
|
if not exists(output_dir):
|
||||||
os.makedirs(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:
|
with open(output_file, 'wb') as f:
|
||||||
link_prefix=basename(output_dir)+'/'
|
link_prefix=basename(output_dir)+'/'
|
||||||
html_toc = self.generate_html_toc(oeb_book, output_file, 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))
|
templite = Templite(P('templates/html_export_default_index.tmpl', data=True))
|
||||||
print oeb_book.metadata.items
|
nextLink = oeb_book.spine[0].href
|
||||||
t = templite.render(toc=html_toc, meta=meta)
|
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)
|
f.write(t)
|
||||||
|
|
||||||
with CurrentDir(output_dir):
|
with CurrentDir(output_dir):
|
||||||
@ -121,10 +122,12 @@ class HTMLOutput(OutputFormatPlugin):
|
|||||||
else:
|
else:
|
||||||
prevLink = None
|
prevLink = None
|
||||||
|
|
||||||
|
cssLink = relpath(abspath(css_path), dir)
|
||||||
|
|
||||||
# render template
|
# render template
|
||||||
templite = Templite(P('templates/html_export_default.tmpl', data=True))
|
templite = Templite(P('templates/html_export_default.tmpl', data=True))
|
||||||
toc = lambda: self.generate_html_toc(oeb_book, path, output_dir)
|
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
|
# write html to file
|
||||||
with open(path, 'wb') as f:
|
with open(path, 'wb') as f:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user