generated from giswqs/gh-pages-html-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,30 @@ jobs: | |
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
##################################################### | ||
# Comment out this section if you don't need to generate the index.html file | ||
- name: execute python script | ||
run: | | ||
python create_index.py | ||
- name: file_check | ||
run: ls -l -a | ||
- name: commit files | ||
continue-on-error: true | ||
run: | | ||
today=$(date +"%Y-%m-%d") | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Action" | ||
git add -A | ||
git commit -m "Updated index.html ${today} UTC" -a | ||
git pull origin master | ||
- name: push changes | ||
continue-on-error: true | ||
uses: ad-m/github-push-action@master | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
branch: master | ||
##################################################### | ||
|
||
# Deploy the book's HTML to gh-pages branch | ||
- name: GitHub Pages action | ||
uses: peaceiris/actions-gh-pages@v4 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import os | ||
|
||
|
||
def generate_index_html(directories, output_file): | ||
# Start the HTML content | ||
html_content = """<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Directory Listing</title> | ||
</head> | ||
<body> | ||
<h1>Directory Listing</h1> | ||
<ul> | ||
""" | ||
|
||
for directory in directories: | ||
if os.path.isdir(directory): | ||
html_content += f"<li><strong>{directory}</strong></li><ul>" | ||
all_files = [] | ||
for root, dirs, files in os.walk(directory): | ||
for filename in files: | ||
file_path = os.path.join(root, filename) | ||
all_files.append(file_path) | ||
|
||
# Sort files alphabetically | ||
all_files.sort() | ||
|
||
for file_path in all_files: | ||
# Get the relative path to the file from the base directory | ||
relative_path = os.path.relpath(file_path, start=directory) | ||
html_content += f'<li><a href="{directory}/{relative_path}">{relative_path}</a></li>' | ||
html_content += "</ul>" | ||
|
||
# Close the HTML content | ||
html_content += """ | ||
</ul> | ||
</body> | ||
</html> | ||
""" | ||
|
||
# Write the HTML content to the output file | ||
with open(output_file, "w") as f: | ||
f.write(html_content) | ||
|
||
|
||
# Specify the directories to list | ||
directories_to_list = ["files"] | ||
# Specify the output HTML file | ||
output_html_file = "index.html" | ||
|
||
generate_index_html(directories_to_list, output_html_file) |