Changes

Jump to navigation Jump to search
2,219 bytes added ,  14:08, 17 January 2015
m
add links to new pages
{{todo|Beware, this doesn’t fit the current export files and ePub workflow as of January 2015!}} < [[Epub]] | [[XML]] | [[Export]] | [[ePub|New ePub docs]] >
Creating an ebook with ConTeXt is still tedious and needs a lot of manual work - that will not change, since everyone has other needs, uses different structures etc.
Beware, you need a current beta version of ConTeXt, since Hans fixed some export related bugs in the last few days!
--[[User:Hraban|Hraban]] 31 August 13 September 2014.
== ConTeXt setup ==
Make sure to tag all your structural elements with {{cmd|start...}}-{{cmd|stop...}}, e.g. {{cmd|startchapter}}, but even {{cmd|startparagraph}}!
 
In places where {{cmd|startparagraph}} does not work, such as itemizations, where it causes a blank line after the bullet and before the item text, use {{cmd|bpar}} (and closing {{cmd|epar}}) to tag paragraphs.
Then you can call ConTeXt and its ePub script:
/>
<xsl:variable name="within-paragraph">0</xsl:variable ><!-- statusxsl: are we variable name="within a paragraph? -section">0</xsl:variable ><xsl:variable name="previous-section">0</xsl:variable >
<xsl:template match='section'><!-- <xsl:if test="@detail='part'"> <xsl:text disable-output-escaping="yes"><![CDATA[</div></body></html>]]></xsl:text> </xsl:if>--> <xsl:result-document method="xml" href="aut_{@implicit}.html"> <htmlxmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8" /> <title><xsl:value-of select='.//metavariable[@name="title"]sectiontitle'/> </title> <xsl:for-each select="//metavariable"> <meta> <xsl:attribute name="name"> <xsl:value-of select="@name"/> </xsl:attribute> <xsl:attribute name="content"> <xsl:apply-templates/> </xsl:attribute> </meta> </xsl:for-each> <link rel="stylesheet" href="../Styles/style.css" type="text/css" ></link> </head> <body> <xsl:attributename="lang"> <xsl:value-of select='//document/@language'/> </xsl:attribute > <!-- <xsl:variable name="contentprevious-section">{$within-section}</xsl:variable > <xsl:variable name="within-section">{@detail}</xsl:variable > -->
<xsl:apply-templates/>
</xsl:attribute> </meta> </xsl:for-each> <link rel="stylesheet" href="style.css" type="text/css" ></link> <!-- for testing the html outside the ePub tree --> <link rel="stylesheet" href="Styles/style.css" type="text/css" ></link></head><body lang="de"> <h1 class="booktitle"> <xsl:value-of select='//metavariable[@variable name="titlewithin-section"]'/>{$previous-section}</h1xsl:variable > <h2 class="subtitle"> <xsl:value-of select='//metavariable[@variable name="subtitleprevious-section"]'/>0</h2xsl:variable > <p class="author"><xsl:value --of select='//metavariable[@name="author"]'/></p> <xsl:apply-templates/body> </bodyhtml> </htmlxsl:result-document></xsl:template>
<xsl:template match="metadata">
</xsl:template>
 
<xsl:template match="section">
<a name="{translate(@location,':','_')}"/>
<div class="{@detail}">
<xsl:apply-templates/>
</div>
</xsl:template>
<xsl:template match="sectiontitle">
<xsl:choose>
<xsl:when test="../@detail='part'">
<h2h1><xsl:apply-templates/> </h2h1>
</xsl:when>
<xsl:when test="../@detail='chapter'">
<h3h2><xsl:apply-templates/></h2> </xsl:when> <xsl:when test="../@detail='Titel'"> <h2><xsl:apply-templates/></h2> </xsl:when> <xsl:when test="../@detail='TitelKlein'"> <h2><xsl:apply-templates/></h3h2>
</xsl:when>
<xsl:when test="../@detail='section'">
<h4h3><xsl:apply-templates/> </h4h3>
</xsl:when>
<xsl:when test="../@detail='subsection'">
<h5h4><xsl:apply-templates/> </h5h4>
</xsl:when>
<xsl:otherwise>
<h6 class="../@detail"><xsl:apply-templates/> </h6>
</xsl:otherwise>
</xsl:choose>
<xsl:template match="delimited">
<span class="delim-{@detail}"><xsl:apply-templates/></span>
</xsl:template>
 
<xsl:template match="construct">
<div class="struct-{@detail}"><xsl:apply-templates/></div>
</xsl:template>
<!-- all the images in my songbook are notes generated by LilyPond via t-filter; in ePub I shorten the file names -->
 
<xsl:template match="image">
<img src="../Images/{substring-after(@name,'prd_songbookprd_hraban-temp-lilypond-')}.png" id="{@id}" alt="{@name}" />
</xsl:template>
<xsl:template match="link">
<a href="#{@location}" title="{@destination}"><xsl:apply-templates/></a>
</xsl:template>
 
<xsl:template match="register">
</xsl:template>
 
<xsl:template match="registerentry">
</xsl:template>
 
<xsl:template match="registerpage">
</xsl:template>
 
</xsl:stylesheet>
 
</xmlcode>
<xsl:template match="/">
<package version="2.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId">
<!-- see http://www.idpf.org/epub/20/spec/OPF_2.0.1_draft.htm -->
 
<identifier id="1"><xsl:value-of select='//metavariable[@name="identifier"]'/></identifier>
<identifier id="isbn" scheme="isbn"><xsl:value-of select='//metavariable[@name="isbn"]'/></identifier>
<title><xsl:value-of select='//metavariable[@name="title"]'/></title>
<creator><xsl:value-of select='//metavariable[@name="author"]'/></creator>
<subject><xsl:value-of select='//metavariable[@name="subject"]'/></subject>
<description><xsl:value-of select='//metavariable[@name="description"]'/></description>
<publisher><xsl:value-of select='//metavariable[@name="publisher"]'/></publisher>
<language><xsl:value-of select='//document/@language'/></language>
<rights><xsl:value-of select='//metavariable[@name="rights"]'/></rights>
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
<dc:creator><xsl:value-of select='//metavariable[@name="author"]'/></dc:creator>
<dc:date><xsl:value-of select='//document/@date'/></dc:date>
<meta name="cover" content="cover-html" />
</metadata>
<xsl:for-each select='//section'>
<item media-type="application/xhtml+xml">
<xsl:attribute name="id">aut_<xsl:value-of select="translate(@location,':','_')implicit"/>-html</xsl:attribute> <xsl:attribute name="href">Text/aut_<xsl:value-of select="translate(@location,':','_')implicit"/>.html</xsl:attribute>
</item>
</xsl:for-each>
<item media-type="image/jpeg" id="cover" href="Images/cover.jpg"/>
<!-- again, LilyPond related images -->
<xsl:for-each select='//image'>
<item media-type="image/png" id="{@id}">
</item>
</xsl:for-each>
<!-- add fonts manually? --> <!-- <item media-type="application/x-font-otf" id="" href="Fonts/xyz.otf" /> <item media-type="application/x-font-ttf" id="" href="Fonts/xyz.ttf" /> -->
</manifest>
<xsl:for-each select='//section'>
<itemref>
<xsl:attribute name="idref">aut_<xsl:value-of select="translate(@location,':','_')implicit"/>-html</xsl:attribute>
</itemref>
</xsl:for-each>
<meta name="dtb:totalPgeCount" >
<xsl:attribute name="content">
<xsl:value-of select='count(section[starts-with(@detail=,"Titel")])' />
</xsl:attribute>
</meta>
<meta name="dtb:maxPageNumber">
<xsl:attribute name="content">
<xsl:value-of select='count(section[starts-with(@detail=,"Titel")])' />
</xsl:attribute>
</meta>
<navMap>
<navPoint id="aut_0" origin="aut_0" playOrder="0">
<navLabel>
<text>Cover</text>
</navLabel>
<content src="cover.html"/>
</navPoint>
<navPoint id="aut_1" origin="aut_1" playOrder="1">
<navLabel>
</xsl:variable >
<xsl:variable name="origin">
<xsl:value-of select='translate(//registerlocation[@locationinternal=$location]/ancestor::section[starts-with(@detail=,"Titel")]/@location, ":", "_")implicit'/>
</xsl:variable >
<navPoint>
<xsl:attribute name="id">
<xsl:value-of select='translate($location, ":", "_")'/>
</xsl:attribute>
<xsl:attribute name="origin"><xsl:value-of select="$origin" /></xsl:attribute>
</navLabel>
<content>
<xsl:attribute name="src">Text/aut_<xsl:value-of select='$origin' />.html</xsl:attribute>
</content>
</navPoint>
</xsl:stylesheet>
 
</xmlcode>
<pre>
cd songbook.tree
zip -ur uqr ../songbook.epub *
</pre>
Now test it with your reader or editor (e.g. Calibre). (Apple iBooks or Adobe Digital Editions don’t work, don’t know why.)
== Shell script ==

Navigation menu