This commit is contained in:
		@@ -141,3 +141,4 @@ nav:
 | 
				
			|||||||
    - AddUser 1Line: cmnds/adduser-1line.md
 | 
					    - AddUser 1Line: cmnds/adduser-1line.md
 | 
				
			||||||
    - Tasmota Backlogs: cmnds/tasmota-backlogs.md
 | 
					    - Tasmota Backlogs: cmnds/tasmota-backlogs.md
 | 
				
			||||||
  - sthope: '/portainer-stacks/'
 | 
					  - sthope: '/portainer-stacks/'
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
							
								
								
									
										62
									
								
								scripts/1.py
									
									
									
									
									
								
							
							
						
						
									
										62
									
								
								scripts/1.py
									
									
									
									
									
								
							@@ -1,47 +1,21 @@
 | 
				
			|||||||
import os
 | 
					# Read the original mkdocs.yml content
 | 
				
			||||||
import argparse
 | 
					with open('mkdocs.yml', 'r') as file:
 | 
				
			||||||
 | 
					    lines = file.readlines()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Define the directory containing Portainer Stack Markdown files
 | 
					# Find the start and end indexes of the section to replace
 | 
				
			||||||
markdown_dir = "./docs/portainer-stacks"
 | 
					start_index = None
 | 
				
			||||||
 | 
					end_index = None
 | 
				
			||||||
 | 
					for i, line in enumerate(lines):
 | 
				
			||||||
 | 
					    if line.strip() == '- Portainer Stacks:':
 | 
				
			||||||
 | 
					        start_index = i
 | 
				
			||||||
 | 
					    elif line.strip() == '- Swag:':
 | 
				
			||||||
 | 
					        end_index = i
 | 
				
			||||||
 | 
					        break
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Define the relative path prefix used in mkdocs.yml
 | 
					# Replace the lines between start and end indexes with the new content
 | 
				
			||||||
relative_path_prefix = "portainer-stacks/"
 | 
					if start_index is not None and end_index is not None:
 | 
				
			||||||
 | 
					    lines[start_index:end_index + 1] = ['  - Portainer Stacks:\n', '  - Swag:\n']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Read the existing mkdocs.yml content
 | 
					# Write the modified content back to the mkdocs.yml file
 | 
				
			||||||
with open("mkdocs.yml", "r") as f:
 | 
					with open('mkdocs.yml', 'w') as file:
 | 
				
			||||||
    mkdocs_content = f.read()
 | 
					    file.writelines(lines)
 | 
				
			||||||
 | 
					 | 
				
			||||||
# Generate navigation entries
 | 
					 | 
				
			||||||
nav_entries = []
 | 
					 | 
				
			||||||
for filename in os.listdir(markdown_dir):
 | 
					 | 
				
			||||||
    if filename.endswith(".md"):
 | 
					 | 
				
			||||||
        title = filename[:-3]  # Remove ".md" extension
 | 
					 | 
				
			||||||
        relative_path = f"{relative_path_prefix}{filename}"  # Generate relative path
 | 
					 | 
				
			||||||
        nav_entries.append(f"    - {title}: {relative_path}")  # Add 4 spaces
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# List of names to ignore
 | 
					 | 
				
			||||||
names_to_ignore = ["template"]  # Add names you want to ignore here
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Filter out entries to ignore
 | 
					 | 
				
			||||||
filtered_nav_entries = [entry for entry in nav_entries if not any(name in entry for name in names_to_ignore)]
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Sort the navigation entries alphabetically (case-insensitive)
 | 
					 | 
				
			||||||
sorted_nav_entries = sorted(filtered_nav_entries, key=lambda entry: entry.lower())
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Combine all the sorted navigation entries into a single string
 | 
					 | 
				
			||||||
new_section_content = "\n".join(sorted_nav_entries)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Parse command-line arguments
 | 
					 | 
				
			||||||
parser = argparse.ArgumentParser(description="Generate navigation entries for mkdocs.yml")
 | 
					 | 
				
			||||||
parser.add_argument("--replace", action="store_true", help="Replace mkdocs.yml with new content")
 | 
					 | 
				
			||||||
args = parser.parse_args()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# If --replace option is provided, replace the existing "Portainer Stacks" section
 | 
					 | 
				
			||||||
if args.replace:
 | 
					 | 
				
			||||||
    updated_mkdocs_content = mkdocs_content.replace("  - Portainer Stacks:\n", f"  - Portainer Stacks:\n{new_section_content}\n")
 | 
					 | 
				
			||||||
    with open("mkdocs.yml", "w") as f:
 | 
					 | 
				
			||||||
        f.write(updated_mkdocs_content)
 | 
					 | 
				
			||||||
else:
 | 
					 | 
				
			||||||
    # Print the sorted navigation entries with 4 spaces
 | 
					 | 
				
			||||||
    for entry in sorted_nav_entries:
 | 
					 | 
				
			||||||
        print(entry)
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,9 +4,10 @@ import os
 | 
				
			|||||||
import subprocess
 | 
					import subprocess
 | 
				
			||||||
import argparse
 | 
					import argparse
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Define and parse command-line arguments
 | 
					# Parse command-line arguments
 | 
				
			||||||
parser = argparse.ArgumentParser(description="Automate Git add, commit, and push operations.")
 | 
					parser = argparse.ArgumentParser(description="Generate navigation entries for mkdocs.yml")
 | 
				
			||||||
parser.add_argument("--COMMIT-MSG", help="Commit message for the changes.")
 | 
					parser.add_argument("--replace", action="store_true", help="Replace mkdocs.yml with new content")
 | 
				
			||||||
 | 
					parser.add_argument("--COMMIT_MSG", help="Commit message for Git")
 | 
				
			||||||
args = parser.parse_args()
 | 
					args = parser.parse_args()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Get the commit message from command-line argument or prompt user
 | 
					# Get the commit message from command-line argument or prompt user
 | 
				
			||||||
@@ -14,6 +15,8 @@ if args.COMMIT_MSG:
 | 
				
			|||||||
    commit_msg = args.COMMIT_MSG
 | 
					    commit_msg = args.COMMIT_MSG
 | 
				
			||||||
else:
 | 
					else:
 | 
				
			||||||
    commit_msg = input("Enter commit message: ")
 | 
					    commit_msg = input("Enter commit message: ")
 | 
				
			||||||
 | 
					    if not commit_msg.strip():  # Check if the input message is empty
 | 
				
			||||||
 | 
					        commit_msg = "Initial commit"  # Set default commit message
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Add changes to the staging area
 | 
					# Add changes to the staging area
 | 
				
			||||||
subprocess.run(["python3", "./scripts/list_new_docker_files.py", "--replace"], check=True)
 | 
					subprocess.run(["python3", "./scripts/list_new_docker_files.py", "--replace"], check=True)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,28 @@
 | 
				
			|||||||
import os
 | 
					import os
 | 
				
			||||||
import argparse
 | 
					import argparse
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Read the original mkdocs.yml content
 | 
				
			||||||
 | 
					with open('mkdocs.yml', 'r') as file:
 | 
				
			||||||
 | 
					    lines = file.readlines()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Find the start and end indexes of the section to replace
 | 
				
			||||||
 | 
					start_index = None
 | 
				
			||||||
 | 
					end_index = None
 | 
				
			||||||
 | 
					for i, line in enumerate(lines):
 | 
				
			||||||
 | 
					    if line.strip() == '- Portainer Stacks:':
 | 
				
			||||||
 | 
					        start_index = i
 | 
				
			||||||
 | 
					    elif line.strip() == '- Swag:':
 | 
				
			||||||
 | 
					        end_index = i
 | 
				
			||||||
 | 
					        break
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Replace the lines between start and end indexes with the new content
 | 
				
			||||||
 | 
					if start_index is not None and end_index is not None:
 | 
				
			||||||
 | 
					    lines[start_index:end_index + 1] = ['  - Portainer Stacks:\n', '  - Swag:\n']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Write the modified content back to the mkdocs.yml file
 | 
				
			||||||
 | 
					with open('mkdocs.yml', 'w') as file:
 | 
				
			||||||
 | 
					    file.writelines(lines)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Define the directory containing Portainer Stack Markdown files
 | 
					# Define the directory containing Portainer Stack Markdown files
 | 
				
			||||||
markdown_dir = "./docs/portainer-stacks"
 | 
					markdown_dir = "./docs/portainer-stacks"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user