Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
kthoden committed Nov 14, 2019
2 parents 06f0f90 + fa97c34 commit 931a076
Show file tree
Hide file tree
Showing 9 changed files with 651 additions and 349 deletions.
2 changes: 1 addition & 1 deletion tei2html.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def main(
)
parser.add_argument(
"--root-dir",
default = Path.cwd(),
default = Path.cwd() / "output",
help="internal html links on the page will use this location as a prefix"
)
parser.add_argument(
Expand Down
36 changes: 30 additions & 6 deletions tei2html/tei2html.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
indent="yes"
/>

<xsl:include href="tei2html_index_utils.xsl"/>
<xsl:include href="tei2html_publ_frontpage_utils.xsl"/>
<xsl:include href="tei2html_chapter_utils.xsl"/>
<xsl:include href="utils/html_rules.xsl"/>
<xsl:include href="utils/common.xsl"/>
<xsl:include href="utils/print.xsl"/>

<xsl:param name="output_dir" as="xs:string" select="'.'"/>
<xsl:param name="static_dir" as="xs:string" select="'static'"/>
<xsl:param name="output_dir" as="xs:string" select="'./output'"/>
<xsl:param name="static_dir" as="xs:string" select="'../static'"/>
<xsl:param name="intermediate_dir" as="xs:string?" select="concat($output_dir, '/intermediate')"/>
<xsl:param name="logo_dir" as="xs:string" select="concat($static_dir, '/assets/images')"/>
<xsl:param name="nav_items" as="element(eoa:entry)*">
<eoa:entry active="1">
Expand All @@ -35,21 +37,43 @@
-->

<xsl:template match="/">
<xsl:message> domain: <xsl:value-of select="$domain"/> </xsl:message>
<xsl:sequence select="eoa:info(concat('domain: ', $domain))"/>
<xsl:variable name="output_subdir" as="xs:string">
<xsl:value-of select="concat($output_dir, '/', $series, '/', $publication_number)"/>
</xsl:variable>
<xsl:variable name="indices" as="element(eoa:index)*">
<xsl:variable name="ctxt" select="."/>
<xsl:for-each select="$index_types">
<xsl:variable name="index_type" as="xs:string" select="."/>
<xsl:for-each select="$ctxt">
<xsl:call-template name="create_index">
<xsl:with-param name="indextype" select="$index_type"/>
</xsl:call-template>
</xsl:for-each>
</xsl:for-each>
</xsl:variable>
<xsl:if test="$intermediate_dir">
<xsl:result-document
method="xml"
encoding="UTF-8"
indent="yes"
href="{concat($intermediate_dir, '/indices.xml')}"
>
<xsl:copy-of select="$indices"/>
</xsl:result-document>
</xsl:if>
<xsl:result-document
method="html"
encoding="UTF-8"
include-content-type="yes"
indent="yes"
href="{concat($output_subdir, '/index.html')}"
>
<xsl:call-template name="writeindexfile">
<xsl:call-template name="render_publication_frontpage">
<xsl:with-param name="static_dir" select="concat('../../', $static_dir)"/>
<xsl:with-param name="logo_dir" select="concat('../../', $logo_dir)"/>
<xsl:with-param name="nav_items" as="element(eoa:entry)*" select="$nav_items"/>
<xsl:with-param name="indices" as="element(eoa:index)*" select="$indices"/>
</xsl:call-template>
</xsl:result-document>
<xsl:for-each select="//tei:div[@type='chapter']">
Expand All @@ -60,7 +84,7 @@
indent="yes"
href="{concat($output_subdir, '/', position(), '/index.html')}"
>
<xsl:call-template name="writechapterfile">
<xsl:call-template name="render_chapter">
<xsl:with-param name="static_dir" select="concat('../../../', $static_dir)"/>
<xsl:with-param name="logo_dir" select="concat('../../../', $logo_dir)"/>
<xsl:with-param name="nav_items" as="element(eoa:entry)*" select="$nav_items"/>
Expand Down
8 changes: 3 additions & 5 deletions tei2html/tei2html_chapter.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@
<xsl:include href="tei2html_chapter_utils.xsl"/>

<xsl:template match="/">
<!--
<xsl:message> domain: <xsl:value-of select="$domain"/> </xsl:message>
-->
<xsl:sequence select="eoa:info(concat('domain: ', $domain))"/>
<xsl:for-each select="(//tei:div[@type='chapter'])[position() = $chapter_nr]">
<xsl:message>printing chapter <xsl:value-of select="$chapter_nr"/>. head: <xsl:value-of select="tei:head"/></xsl:message>
<xsl:call-template name="writechapterfile">
<xsl:sequence select="eoa:info(concat('printing chapter ', $chapter_nr, '. head: ', tei:head))"/>
<xsl:call-template name="render_chapter">
<xsl:with-param name="static_dir" select="$static_dir"/>
<xsl:with-param name="logo_dir" select="$logo_dir"/>
<xsl:with-param name="nav_items" as="element(eoa:entry)*" select="$nav_items"/>
Expand Down
17 changes: 10 additions & 7 deletions tei2html/tei2html_chapter_utils.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<xsl:key name="kWith1stLetter" match="family" use="substring(.,1,1)"/>

<!-- context: //tei:div[@type='chapter'] -->
<xsl:template name="writechapterfile">
<xsl:template name="render_chapter">
<xsl:param name="static_dir" as="xs:string"/>
<xsl:param name="logo_dir" as="xs:string"/>
<xsl:param name="nav_items" as="element(eoa:entry)*"/>
Expand Down Expand Up @@ -176,7 +176,7 @@
</xsl:with-param>
<xsl:with-param name="script">
<xsl:if test=".//tei:formula">
<xsl:message>putting in mathjax</xsl:message>
<xsl:sequence select="eoa:info('adding mathjax...')"/>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js"],
Expand Down Expand Up @@ -216,17 +216,20 @@ tex2jax: {inlineMath: [["$","$"],["\\(","\\)"]]}
<div class="publication-detail__footnotes">
<ol>
<xsl:for-each select="$chapter//tei:note[@place = 'bottom']">
<xsl:variable name="paragraph_id" as="xs:string?">
<xsl:variable name="container_id" as="xs:string?">
<xsl:for-each select="parent::tei:*">
<xsl:call-template name="paragraph_id"/>
<xsl:call-template name="container_id"/>
</xsl:for-each>
</xsl:variable>
<xsl:if test="$paragraph_id">
<li id="fn{@n}">
<xsl:variable name="footnote_id" as="xs:string">
<xsl:call-template name="footnote_id"/>
</xsl:variable>
<xsl:if test="$container_id">
<li id="{$footnote_id}">
<xsl:for-each select="tei:p">
<p><xsl:apply-templates mode="html"/></p>
</xsl:for-each>
<a href="#{$paragraph_id}">to paragraph</a>
<a href="#{$container_id}">to paragraph</a>
</li>
</xsl:if>
</xsl:for-each>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<xsl:include href="utils/common.xsl"/>
<xsl:include href="utils/html_rules.xsl"/>
<xsl:include href="tei2html_index_utils.xsl"/>
<xsl:include href="tei2html_publ_frontpage_utils.xsl"/>

<!-- use-character-maps="texreplacements"/>-->
<xsl:variable name="langid" select="//tei:langUsage/tei:language/@ident"/>
Expand All @@ -36,7 +36,7 @@
<xsl:key name="kWith1stLetter" match="family" use="substring(.,1,1)"/>

<xsl:template match="/">
<xsl:call-template name="writeindexfile">
<xsl:call-template name="render_publication_frontpage">
<xsl:with-param name="static_dir" select="$static_dir"/>
<xsl:with-param name="logo_dir" select="$logo_dir"/>
<xsl:with-param name="nav_items" as="element(eoa:entry)*" select="$nav_items"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
<!-- index sorting, https://stackoverflow.com/questions/13763271 -->
<xsl:key name="kWith1stLetter" match="family" use="substring(.,1,1)"/>

<xsl:template name="writeindexfile">
<xsl:variable name="index_types" as="xs:string*" select="('keyword', 'location', 'person')"/>

<xsl:template name="render_publication_frontpage">
<xsl:param name="static_dir" as="xs:string"/>
<xsl:param name="logo_dir" as="xs:string"/>
<xsl:param name="nav_items" as="element(eoa:entry)*"/>
<xsl:param name="indices" as="element(eoa:index)*"/>
<xsl:call-template name="website_template">
<xsl:with-param name="static_dir" select="$static_dir"/>
<xsl:with-param name="title">
Expand Down Expand Up @@ -354,55 +357,11 @@
</xsl:for-each>
</div>
</div>
<xsl:if test="//tei:body//tei:index[@indexName='keyword']">
<div class="tabs__content-item">
<div class="publications__index-name">
<div class="accordion">
<a class="accordion__showall" href="#">Show All</a>
<xsl:call-template name="create_index">
<xsl:with-param name="indextype" select="'keyword'"/>
</xsl:call-template>
<div class="accordion__item">
<a class="accordion__title" href="#">
<h2>B</h2>
</a>
<div class="accordion__content">
<h4>Peter Becksbaum</h4>
<ul>
<li>1</li>
<li>2</li>
</ul>
<a class="accordion__pageup" href="#"/>
</div>
</div>
</div>
</div>
</div>
</xsl:if>
<xsl:if test="//tei:body//tei:index[@indexName='location']">
<div class="tabs__content-item">
<div class="publications__index-name">
<div class="accordion">
<a class="accordion__showall" href="#">Show All</a>
<xsl:call-template name="create_index">
<xsl:with-param name="indextype" select="'location'"/>
</xsl:call-template>
</div>
</div>
</div>
</xsl:if>
<xsl:if test="//tei:body//tei:index[@indexName='person']">
<div class="tabs__content-item">
<div class="publications__index-name">
<div class="accordion">
<a class="accordion__showall" href="#">Show All</a>
<xsl:call-template name="create_index">
<xsl:with-param name="indextype" select="'person'"/>
</xsl:call-template>
</div>
</div>
</div>
</xsl:if>
<xsl:for-each select="$indices">
<xsl:call-template name="render_index">
<xsl:with-param name="indextype" select="@type"/>
</xsl:call-template>
</xsl:for-each>
</div>
</div>
</div>
Expand Down Expand Up @@ -499,57 +458,117 @@
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="eoa:debug(3, 'No book author. Exiting.', '')"/>
<xsl:sequence select="eoa:error('No book author.')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template name="create_index">
<xsl:template name="render_index" as="element()*">
<xsl:param name="indextype"/>
<xsl:message>creating index...</xsl:message>
<!-- all index elements starting with the same letter: -->
<xsl:for-each-group select="//tei:index[lower-case(@indexName) = $indextype]" group-by="substring(if (exists(./tei:term/@sortKey)) then ./tei:term/@sortKey else ./tei:term/text(),1,1)">
<xsl:sort select="current-grouping-key()"/>
<xsl:variable name="chapter" select="ancestor::tei:div[@type = 'chapter']"/>
<xsl:variable name="chapter_nr" select="count($chapter/preceding-sibling::*)"/>
<div class="accordion__item">
<a class="accordion__title" href="#">
<h2 class="border">
<xsl:value-of select="current-grouping-key()"/>
</h2>
</a>
<div class="accordion__content">
<!-- all index elements with the same "term": -->
<xsl:for-each-group select="current-group()" group-by="if (exists(tei:term/@sortKey)) then tei:term/@sortKey else tei:term/text()">
<xsl:sort select="current-grouping-key()"/>
<h4>
<xsl:value-of select="current-grouping-key()"/>
</h4>
<ul>
<xsl:for-each select="current-group()">
<xsl:variable name="paragraph_nr" select="index-of($chapter//tei:p/tei:index/generate-id(), generate-id(.))"/>
<xsl:variable name="local_uri" select="concat($series, '/', $publication_number, '/', $chapter_nr , '/index.html#', $paragraph_nr)"/>
<xsl:variable name="global_uri" select="concat($domain, '/', $local_uri)"/>
<xsl:message>
<xsl:value-of select="concat(current-grouping-key(), ': ', $global_uri)"/>
</xsl:message>
<li>
<a href="{$global_uri}"> <xsl:value-of select="position()"/></a>
</li>
</xsl:for-each>
</ul>
<!-- below that, ul/li for each jumping point -->
<div class="tabs__content-item">
<div class="publications__index-name">
<div class="accordion">
<a class="accordion__showall" href="#">Show All</a>
<xsl:for-each-group
select="eoa:term"
group-by="substring(@key,1,1)"
>
<div class="accordion__item">
<a class="accordion__title" href="#">
<h2 class="border">
<xsl:value-of select="current-grouping-key()"/>
</h2>
</a>
<div class="accordion__content">
<xsl:for-each
select="current-group()"
>
<h4>
<xsl:value-of select="@key"/>
</h4>
<ul>
<xsl:for-each select="eoa:entry">
<li>
<a href="{concat(string-join(($domain, eoa:link/eoa:entry[position() != last()]),'/'), '/index.html#', eoa:link/eoa:entry[last()])}"> <xsl:value-of select="position()"/></a>
</li>
</xsl:for-each>
</ul>
</xsl:for-each>
</div>
</div>
</xsl:for-each-group>
</div>
</div>
<!--
<xsl:message>
<xsl:value-of select="$sortkey"/>
<xsl:text>: </xsl:text>
<xsl:value-of select="./tei:term//text()"/>
</xsl:message>
-->
</xsl:for-each-group>
</div>
</div>
</div>
</xsl:template>

<xsl:template name="create_index" as="element(eoa:index)">
<xsl:param name="indextype"/>
<xsl:sequence select="eoa:info(concat('creating index ', $indextype))"/>
<!-- all index elements starting with the same letter: -->
<eoa:index type="{$indextype}">
<xsl:for-each-group
select="//tei:body//tei:index[lower-case(@indexName) = $indextype][not(ancestor::tei:index)]"
group-by="if (exists(tei:term/@sortKey)) then tei:term/@sortKey else tei:term/text()"
>
<xsl:sort select="current-grouping-key()"/>
<eoa:term key="{current-grouping-key()}">
<xsl:for-each select="current-group()">
<xsl:sequence select="eoa:info(concat('adding index element ', tei:term, '!'))"/>
<xsl:variable name="chapter" select="ancestor::tei:div[@type = 'chapter']"/>
<xsl:variable name="chapter_nr" select="count($chapter/preceding-sibling::*)"/>
<xsl:variable name="dest_id" as="xs:string?">
<xsl:variable name="candidates" as="xs:string*">
<xsl:for-each select="ancestor::tei:*">
<xsl:variable name="footnote_id" as="xs:string?">
<xsl:call-template name="footnote_id"/>
</xsl:variable>
<xsl:variable name="container_id" as="xs:string?">
<xsl:call-template name="container_id"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="$footnote_id">
<xsl:value-of select="$footnote_id"/>
</xsl:when>
<xsl:when test="$container_id">
<xsl:value-of select="$container_id"/>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="if( count($candidates) != 0) then $candidates[1] else ()"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="not($dest_id)">
<xsl:sequence select="eoa:warning(concat('paragraph not found for index element ', tei:term, '!'))"/>
</xsl:when>
<xsl:otherwise>
<eoa:entry>
<eoa:tei-element>
<xsl:copy-of select="."/>
</eoa:tei-element>
<eoa:link>
<eoa:entry>
<xsl:value-of select="$series"/>
</eoa:entry>
<eoa:entry>
<xsl:value-of select="$publication_number"/>
</eoa:entry>
<eoa:entry>
<xsl:value-of select="$chapter_nr"/>
</eoa:entry>
<eoa:entry>
<xsl:value-of select="$dest_id"/>
</eoa:entry>
</eoa:link>
</eoa:entry>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</eoa:term>
</xsl:for-each-group>
</eoa:index>
<xsl:sequence select="eoa:info('finished creating index')"/>
</xsl:template>

</xsl:stylesheet>
Loading

0 comments on commit 931a076

Please sign in to comment.