Skip to content

Commit

Permalink
Improve static site generation
Browse files Browse the repository at this point in the history
  • Loading branch information
cthoyt committed Jan 17, 2025
1 parent 889d73d commit 4ac0271
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 22 deletions.
10 changes: 3 additions & 7 deletions src/pyobo/ssg/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Static site generator."""

import itertools as itt
from collections import defaultdict
from collections.abc import Sequence
from operator import attrgetter
Expand Down Expand Up @@ -64,15 +63,12 @@ def make_site(
if resource is None:
raise KeyError

terms = [term for term in obo if term.prefix == obo.ontology]

if not manifest:
_manifest = None
else:
_manifest = sorted(
(term for term in itt.chain(obo, obo.typedefs or []) if term.prefix == obo.ontology),
key=attrgetter("identifier"),
)

terms = [term for term in obo if term.prefix == obo.ontology]
_manifest = sorted(terms, key=attrgetter("identifier"))

directory.joinpath("index.html").write_text(
index_template.render(
Expand Down
39 changes: 26 additions & 13 deletions src/pyobo/ssg/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ <h5 class="card-header">
Metadata
</h5>
<div class="card-body">
<p>{{ resource.get_description() }}</p>
<p>{{ resource.get_description(use_markdown=True) }}</p>
<dl>
{% if obo.data_version %}
<dt>Data Version</dt>
Expand Down Expand Up @@ -64,6 +64,30 @@ <h5 class="card-header">
</div>
{% endif %}

{% if obo.typedefs %}
<div class="card" style="margin-top: 1em;">
<h5 class="card-header">
Type Definitions
</h5>
<table class="table table-striped">
<thead>
<tr>
<th>CURIE</th>
<th>Name</th>
</tr>
</thead>
<tbody>
{%- for typedef in obo.typedefs %}
<tr>
<td>{{ typedef.curie }}</td>
<td>{% if typedef.name %}{{ typedef.name }}{% endif %}</td>
</tr>
{%- endfor %}
</tbody>
</table>
</div>
{% endif %}

{% if manifest %}
<div class="card" style="margin-top: 1em;">
<h5 class="card-header">
Expand All @@ -85,7 +109,7 @@ <h5 class="card-header">
{% if term.is_metadata_tag %}
Property
{% else %}
{{ term.__class__.__name__ }}
{{ term.type }}
{% endif %}
</td>
<td align="right"><a href="{{ term.identifier }}">{{ term.identifier }}</a></td>
Expand All @@ -96,16 +120,5 @@ <h5 class="card-header">
</tbody>
</table>
</div>
{% elif obo.typedefs %}
<div class="card" style="margin-top: 1em;">
<h5 class="card-header">
Relation Definitions
</h5>
<ul class="list-group list-group-flush">
{% for typedef in obo.typedefs %}
<li class="list-group-item">{{ typedef }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
{%- endblock content %}
14 changes: 12 additions & 2 deletions src/pyobo/ssg/term.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

{% block title %}{{ term.name or term.identifier }}{% endblock title %}

{% macro display_value(v) %}
{% if v.prefix %}
<a href="{{ v.bioregistry_link }}">{{ v.curie }}</a>
{% elif v.datatype.identifier == "anyURI" %}
<a href="{{ v.value }}">{{ v.value }}</a>
{% else %}
{{ v.value }}
{% endif %}
{% endmacro %}

{% block content -%}
<div class="card">
<h5 class="card-header">
Expand Down Expand Up @@ -69,11 +79,11 @@ <h5 class="card-header">
</dt>
<dd>
{% if values|length == 1 %}
{{ values[0] }}
{{ display_value(values[0]) }}
{% else %}
<ul>
{% for value in values %}
<li>{{ value }}</li>
<li>{{ display_value(value) }}</li>
{% endfor %}
</ul>
{% endif %}
Expand Down

0 comments on commit 4ac0271

Please sign in to comment.