Skip to content

Commit

Permalink
Update index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs committed Jul 6, 2024
1 parent 0ed8f57 commit e48f1c5
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 51 additions & 0 deletions create_index.py
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)

0 comments on commit e48f1c5

Please sign in to comment.