Skip to content

Commit

Permalink
Merge pull request #1 from KordingLab/add-website-builder
Browse files Browse the repository at this point in the history
Add workflow to make table
  • Loading branch information
felipe-parodi committed Mar 22, 2024
2 parents 68e469d + 645f89d commit 99e81b3
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/website.py
@@ -0,0 +1,45 @@
#%%
# !pip3 install pandas
import pandas as pd
import re

def to_link_if_markdown(cell_text: str) -> str:
# Matches [alt](url) with regex and converts to html <a>:
cell_text = re.sub(r'\[(.*?)\]\((.*?)\)', r'<a href="\2">\1</a>', cell_text)
return cell_text

text = open("../../README.md", "r").readlines()
table = []
# | Year | Paper | Topic | Animal | Model? | Data? | Image/Video Count |
for line in text:
# If line has the correct number of columns
if len(re.findall("\|", line)) == 8:
table.append(line.split("|")[1:-1])
table = pd.DataFrame(table[2:], columns=table[0])

# Substitutions:
table = table.applymap(to_link_if_markdown)


# %%
with open("index.html", "w") as f:
f.write("""<html>
<head>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/2.0.2/css/dataTables.dataTables.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css">
<script src="https://cdn.datatables.net/2.0.2/js/dataTables.js"></script>
</head>
<body>
<h1>Awesome Computational Primatology</h1>
<h3>Parodi et al., 2024</h3>
""")
f.write(table.to_html(table_id="table", escape=False, index=False))
f.write("""<script>$(document).ready( function () {
$('#table').DataTable({
paging: false
});
} );</script>
</body>
</html>""")
# %%
22 changes: 22 additions & 0 deletions .github/workflows/website.yml
@@ -0,0 +1,22 @@
name: Build Website

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.x
- name: Install dependencies
run: pip install pandas
- name: Run website.py
run: python .github/workflows/website.py
- uses: stefanzweifel/git-auto-commit-action@v5

0 comments on commit 99e81b3

Please sign in to comment.