Skip to content

Commit

Permalink
Merge pull request #1 from open223/gtf-new-site-build
Browse files Browse the repository at this point in the history
New site build
  • Loading branch information
gtfierro authored Dec 11, 2024
2 parents 4db4f6b + 20f2fae commit c739cb1
Show file tree
Hide file tree
Showing 10 changed files with 36,838 additions and 14,276 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build-site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ jobs:
- name: install deps
run: poetry install

- name: download constraints.json from gitlab
run: poetry run python download_constraints.py

- name: make index.html
run: poetry run python generate_interactive_doc.py ontologies/223p.ttl
run: poetry run python make_site.py

- name: Commit Built Files
run: |
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
serve: index.html
python3 -m http.server --bind 0.0.0.0 8000

index.html: ontologies/223p.ttl generate_interactive_doc.py templates/index.html templates/static/app.js check-links.sh check-links.py
constraints.json: download-constraints.py

index.html: ontologies/223p.ttl generate_interactive_doc.py templates/index.html templates/static/app.js check-links.sh check-links.py constraints.json
#. .venv/bin/activate && python3 generate_interactive_doc.py ontologies/223p.ttl ontologies/223standard.ttl ontologies/223enumerations.ttl
. .venv/bin/activate && python3 gendoc.py ontologies/223p.ttl ontologies/223standard.ttl ontologies/223enumerations.ttl
#. .venv/bin/activate && python3 gendoc.py ontologies/223p.ttl ontologies/223standard.ttl ontologies/223enumerations.ttl
. .venv/bin/activate && python3 make_site.py
bash check-links.sh
9,182 changes: 9,182 additions & 0 deletions constraints.json

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions download_constraints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import requests
import zipfile
import io
import json
import os

# Define the URL and headers
url = "https://bas-im.emcs.cornell.edu/api/v4/projects/3/jobs/artifacts/master/download?job=document"
headers = {
"PRIVATE-TOKEN": os.environ.get('GITLAB_TOKEN'),
}

# Download the ZIP file
response = requests.get(url, headers=headers)

# Check if the request was successful
if response.status_code == 200:
print("Download successful. Unpacking the ZIP file...")

# Unpack the ZIP file
with zipfile.ZipFile(io.BytesIO(response.content)) as z:
# Extract all files to the current directory or specify a different path
z.extractall()
print("Unpacking completed.")

# Check if 'constraints.json' is in the extracted files
if 'constraints.json' in z.namelist():
# Read 'constraints.json'
with open('constraints.json', 'r') as json_file:
data = json.load(json_file)
print("Contents of 'constraints.json':")
print(json.dumps(data, indent=4)) # Pretty print the JSON data
# save the json data to a file
with open('constraints_data.json', 'w') as json_file:
json.dump(data, json_file, indent=4)
else:
print("'constraints.json' not found in the extracted files.")
else:
print(f"Failed to download file. Status code: {response.status_code}")
25,487 changes: 11,254 additions & 14,233 deletions index.html

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions make_site.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import json
from jinja2 import Environment, FileSystemLoader, select_autoescape
from rdflib import Namespace, BNode, RDF, RDFS, Graph

class SiteBuilder:
def __init__(self, constraints_json_file: str):
with open(constraints_json_file, 'r') as f:
self.constraints = json.load(f)

def build_definitions(self):
# list of dictionaries, each with:
# - class (concept URI)
# - name
# - label
# - immediate_subgraph (cbd)
# - see also (all constraints and rules)
definitions = []
for concept, defn in self.constraints.items():
print(concept)
print(json.dumps(defn, indent=2))
print('---')
definitions.append({
"class": concept,
"name": defn["stable_id"],
"label": defn["label"],
"immediate_subgraph": defn["cbd"],
})
return definitions

def build(self):
env = Environment(
loader=FileSystemLoader('templates'),
autoescape=select_autoescape()
)
template = env.get_template("index.html")

definitions = self.build_definitions()
#prop_defns = self.build_property_shapes()

# Now render the template
with open("index.html", "w") as f:
f.write(template.render(
concepts=definitions,
#property_shapes=[d.to_dict() for d in prop_defns],
))

if __name__ == "__main__":
builder = SiteBuilder("constraints.json")
builder.build()
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ readme = "README.md"
python = "^3.11"
Jinja2 = "^3.1.2"
rdflib = "^7.0.0"
requests = "^2.32.3"


[build-system]
Expand Down
27 changes: 1 addition & 26 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h1>Docs</h1>
<h3><a href="#{{ concept.name }}" id="{{ concept.name}}">{{ concept.label }}</a></h3>
<p>URI: <a href="{{ concept.class }}">{{ concept.class }}</a></p>
<pre><code class="language-turtle">
{{ concept.immediate_subgraph.serialize(format='turtle') }}
{{ concept.immediate_subgraph }}
</code></pre>
{% if concept.see_alsos|length > 0 %}
<h4>See Also</h4>
Expand All @@ -23,25 +23,6 @@ <h4>See Also</h4>
{% endfor %}
</ul>
{% endif %}
<h4>Details</h4>
<details>
<summary>All related shapes and rules</summary>
<pre><code class="language-turtle">
{{ concept.subgraph.serialize(format='turtle') }}
</code></pre>
</details>
</div>
{% endfor %}
{% for concept in property_shapes %}
<div class="card" data-concept="{{concept.name}}">
<h3><a href="#{{ concept.name }}" id="{{ concept.name}}">{{ concept.label }}</a></h3>

{% if concept.class is not none %}
<p>URI: <a href="{{ concept.class }}">{{ concept.class }}</a></p>
{% endif %}
<pre><code class="language-turtle">
{{ concept.immediate_subgraph.serialize(format='turtle') }}
</code></pre>
</div>
{% endfor %}
<script>
Expand All @@ -50,10 +31,4 @@ <h3><a href="#{{ concept.name }}" id="{{ concept.name}}">{{ concept.label }}</a>
{% include "static/prism-autoloader.min.js" %}
{% include "static/prism-turtle.min.js" %}
</script>
<!--
<script src="app.js"></script>
<script src="prism.min.js"></script>
<script src="prism-autoloader.min.js"></script>
<script src="prism-turtle.min.js"></script>
-->
</body>
30 changes: 16 additions & 14 deletions templates/static/app.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
(function() {
const search = document.getElementById("search");
search.addEventListener("change", function() {
for (const item of document.getElementsByClassName("card")) {
// if search.value is not empty OR
// if the 'language-turtle' section of the card contains the string,
// then show the card
// else hide the card
if (item.dataset.concept.toLowerCase().indexOf(search.value) > -1) {
item.style.display = "block";
} else {
item.style.display = "none";
}
const cards = Array.from(document.getElementsByClassName("card"));
let debounceTimeout;

}
search.addEventListener("input", function() {
clearTimeout(debounceTimeout);
debounceTimeout = setTimeout(() => {
const query = search.value.toLowerCase();
for (const item of cards) {
if (item.dataset.concept.toLowerCase().includes(query)) {
item.style.display = "block";
} else {
item.style.display = "none";
}
}
}, 300); // Adjust the delay as needed (e.g., 300ms)
});
for (const item of document.getElementsByClassName('a')) {
item.click( function(e) {
for (const item of document.querySelectorAll('a.reset-search')) { // Example selector
item.addEventListener("click", function(e) {
e.preventDefault();
for (const item of document.getElementsByClassName("card")) {
item.style.display = "block";
Expand Down
Loading

0 comments on commit c739cb1

Please sign in to comment.