mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-29 00:35:00 +00:00
fix: handle Windows-style paths in fname_to_url function
This commit is contained in:
parent
3ce1cfb908
commit
eaaf05d964
1 changed files with 13 additions and 10 deletions
|
@ -44,6 +44,9 @@ def fname_to_url(filepath):
|
|||
index = "index.md"
|
||||
md = ".md"
|
||||
|
||||
# Convert backslashes to forward slashes for consistency
|
||||
filepath = filepath.replace('\\', '/')
|
||||
|
||||
# Convert to Path object for easier manipulation
|
||||
path = Path(filepath)
|
||||
|
||||
|
@ -52,29 +55,29 @@ def fname_to_url(filepath):
|
|||
|
||||
# Find the 'website' part in the path
|
||||
try:
|
||||
website_index = parts.index(website)
|
||||
website_index = [p.lower() for p in parts].index(website.lower())
|
||||
except ValueError:
|
||||
return "" # 'website' not found in the path
|
||||
|
||||
# Extract the part of the path starting from 'website'
|
||||
relevant_parts = parts[website_index + 1 :]
|
||||
relevant_parts = parts[website_index + 1:]
|
||||
|
||||
# Handle _includes directory
|
||||
if relevant_parts and relevant_parts[0] == "_includes":
|
||||
if relevant_parts and relevant_parts[0].lower() == "_includes":
|
||||
return ""
|
||||
|
||||
# Join the remaining parts
|
||||
url_path = "/".join(relevant_parts)
|
||||
url_path = '/'.join(relevant_parts)
|
||||
|
||||
# Handle index.md and other .md files
|
||||
if url_path.endswith(index):
|
||||
url_path = url_path[: -len(index)]
|
||||
elif url_path.endswith(md):
|
||||
url_path = url_path[: -len(md)] + ".html"
|
||||
if url_path.lower().endswith(index.lower()):
|
||||
url_path = url_path[:-len(index)]
|
||||
elif url_path.lower().endswith(md.lower()):
|
||||
url_path = url_path[:-len(md)] + ".html"
|
||||
|
||||
# Ensure the URL starts and ends with '/'
|
||||
url_path = url_path.strip("/")
|
||||
|
||||
url_path = url_path.strip('/')
|
||||
|
||||
return f"https://aider.chat/{url_path}"
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue