[Change] use index.html

This commit is contained in:
2024-04-28 15:55:58 +07:00
parent 7839a14a6f
commit fee2be41b4
3 changed files with 23 additions and 51 deletions
-51
View File
@@ -1,51 +0,0 @@
name: Generate Directory Listing and Deploy to GitHub Pages
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install beautifulsoup4
- name: Generate Directory Listing
run: |
import os
import pathlib
from bs4 import BeautifulSoup
def create_index_html(path):
soup = BeautifulSoup("<html><body><ul></ul></body></html>", "html.parser")
ul = soup.find("ul")
for child in sorted(path.iterdir()):
li = soup.new_tag("li")
a = soup.new_tag("a", href=str(child))
a.string = str(child)
li.append(a)
ul.append(li)
with open(path / "index.html", "w") as f:
f.write(str(soup))
root = pathlib.Path(".")
for path in sorted(root.rglob('*')):
if path.is_dir():
create_index_html(path)
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: .
+1
View File
@@ -0,0 +1 @@
.idea
+22
View File
@@ -0,0 +1,22 @@
<html lang="vi">
<body>
<script>
const owner = `tiennm99`;
const repo = `cv`;
const url = `https://api.github.com/repos/${owner}/${repo}/contents/`;
fetch(url).then(response => {
if (!response.ok) {
throw new Error("HTTP error " + response.status);
}
return response.json();
}).then(data => {
let htmlString = "<ul>";
for (let file of data) {
htmlString += `<li><a href="${file.path}">${file.name}</a></li>`;
}
htmlString += "</ul>";
document.getElementsByTagName("body")[0].innerHTML = htmlString;
}).catch(error => console.error("Error:", error));
</script>
</body>
</html>