-
Notifications
You must be signed in to change notification settings - Fork 0
144 lines (127 loc) · 5.73 KB
/
update-page.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
name: Generate Pathoplexus Example Data List
on:
push:
schedule:
- cron: '0 0 * * 0' # Run weekly on Sundays at midnight
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install markdown
- name: Create Python script
run: |
cat << EOF > generate_list.py
import os
import html
from datetime import datetime
import markdown
def get_file_icon(file):
ext = os.path.splitext(file)[1].lower()
icon_map = {
('.fasta', '.fa', '.fna'): '<i class="fas fa-dna" title="FASTA file"></i>',
('.tsv', '.tab'): '<i class="fas fa-table" title="TSV file"></i>',
('.py', '.js', '.css', '.html', '.json'): '<i class="fas fa-file-code" title="{} file"></i>',
('.jpg', '.jpeg', '.png', '.gif', '.svg'): '<i class="fas fa-file-image" title="{} file"></i>',
('.pdf', '.doc', '.docx', '.txt'): '<i class="fas fa-file-alt" title="{} file"></i>',
}
for extensions, icon in icon_map.items():
if ext in extensions:
return icon.format(ext[1:])
return '<i class="fas fa-file"></i>'
def get_readme_content():
try:
with open('README.md', 'r') as f:
content = f.read()
return markdown.markdown(content)
except FileNotFoundError:
return "<p>README.md not found.</p>"
def generate_html():
file_list = []
for root, dirs, files in os.walk('example_files'):
for file in files:
if file != 'index.html' and not file.startswith('.'):
path = os.path.join(root, file)
size = os.path.getsize(path)
mtime = os.path.getmtime(path)
file_list.append((path, size, mtime))
readme_content = get_readme_content()
html_content = f'''
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pathoplexus Example Files</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css" rel="stylesheet">
<style>
body {{ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; line-height: 1.6; padding: 20px; background-color: #f4f4f4; color: #333; }}
.container {{ max-width: 800px; margin: 0 auto; background-color: #fff; padding: 20px; border-radius: 5px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }}
h1 {{ color: #2c3e50; text-align: center; margin-bottom: 20px; }}
table {{ width: 100%; border-collapse: collapse; margin-top: 20px; }}
th, td {{ padding: 12px; text-align: left; border-bottom: 1px solid #e0e0e0; }}
th {{ background-color: #f2f2f2; font-weight: bold; color: #2c3e50; }}
tr:hover {{ background-color: #f5f5f5; }}
a {{ color: #3498db; text-decoration: none; }}
a:hover {{ color: #2980b9; }}
.file-icon {{ margin-right: 10px; color: #7f8c8d; }}
.file-size, .file-date {{ color: #7f8c8d; font-size: 0.9em; }}
.readme-content {{ margin-bottom: 30px; padding: 20px; background-color: #f9f9f9; border-radius: 5px; }}
</style>
</head>
<body>
<div class="container">
<h1>Pathoplexus Example Files</h1>
<div class="readme-content">
{readme_content}
</div>
<table>
<thead>
<tr>
<th>File Name</th>
<th>Size</th>
<th>Last Modified</th>
</tr>
</thead>
<tbody>
'''
for file, size, mtime in sorted(file_list):
file = file.replace("example_files/", "")
icon = get_file_icon(file)
size_str = f'{size/1024:.1f} KB' if size >= 1024 else f'{size} bytes'
date_str = datetime.fromtimestamp(mtime).strftime('%Y-%m-%d %H:%M:%S')
html_content += f'''
<tr>
<td><a href="example_files/{html.escape(file)}">{icon} {html.escape(file)}</a></td>
<td class="file-size">{size_str}</td>
<td class="file-date">{date_str}</td>
</tr>
'''
html_content += '''
</tbody>
</table>
</div>
</body>
</html>
'''
with open('index.html', 'w') as f:
f.write(html_content)
generate_html()
EOF
- name: Generate Pathoplexus example data list
run: python generate_list.py
- name: Commit and push to gh-pages
run: |
git config --global user.name 'GitHub Action'
git config --global user.email '[email protected]'
git checkout -b gh-pages
git add index.html
git commit -m "Update Pathoplexus example data list" || exit 0
git push -f origin gh-pages