FossilRepo
Fix doc directory links and index file fallback - Directory-style links (www/caps/) fall back to index.html/md/wiki - Strip trailing slashes before file lookup - Fossil /setup_* routes left as-is (no good mapping) - Fixes "Back to Administering" link in www/caps/ref.html
Commit
8c43f6668a54c68e3cee57ff0c119b6552726b55b5e84135a7050a66ae09daa3
Parent
23e8ddeccf99ae4…
1 file changed
+17
-1
+17
-1
| --- fossil/views.py | ||
| +++ fossil/views.py | ||
| @@ -161,10 +161,13 @@ | ||
| 161 | 161 | return f'href="{base}/docs/www/help.wiki"' |
| 162 | 162 | # Bare .wiki or .md file paths (from relative link resolution) |
| 163 | 163 | m = re.match(r"/([^/]+\.(?:wiki|md|html))", url) |
| 164 | 164 | if m: |
| 165 | 165 | return f'href="{base}/docs/www/{m.group(1)}"' |
| 166 | + # /setup_*, /admin_* -> these are Fossil server routes, link to admin | |
| 167 | + if re.match(r"/(setup_|admin_)", url): | |
| 168 | + return match.group(0) # Keep as-is, no good mapping | |
| 166 | 169 | # Keep external and unrecognized links as-is |
| 167 | 170 | return match.group(0) |
| 168 | 171 | |
| 169 | 172 | def replace_scheme_link(match): |
| 170 | 173 | """Handle Fossil URI schemes like forum:/forumpost/HASH, wiki:PageName, info:HASH.""" |
| @@ -770,14 +773,27 @@ | ||
| 770 | 773 | with reader: |
| 771 | 774 | checkin_uuid = reader.get_latest_checkin_uuid() |
| 772 | 775 | files = reader.get_files_at_checkin(checkin_uuid) if checkin_uuid else [] |
| 773 | 776 | |
| 774 | 777 | target = None |
| 778 | + # Strip trailing slash for directory-style links | |
| 779 | + clean_path = doc_path.rstrip("/") | |
| 775 | 780 | for f in files: |
| 776 | - if f.name == doc_path: | |
| 781 | + if f.name == clean_path: | |
| 777 | 782 | target = f |
| 778 | 783 | break |
| 784 | + | |
| 785 | + # If not found, try index files for directory links | |
| 786 | + if not target: | |
| 787 | + for index_name in [f"{clean_path}/index.html", f"{clean_path}/index.md", f"{clean_path}/index.wiki"]: | |
| 788 | + for f in files: | |
| 789 | + if f.name == index_name: | |
| 790 | + target = f | |
| 791 | + doc_path = index_name | |
| 792 | + break | |
| 793 | + if target: | |
| 794 | + break | |
| 779 | 795 | |
| 780 | 796 | if not target: |
| 781 | 797 | raise Http404(f"Documentation file not found: {doc_path}") |
| 782 | 798 | |
| 783 | 799 | content_bytes = reader.get_file_content(target.uuid) |
| 784 | 800 |
| --- fossil/views.py | |
| +++ fossil/views.py | |
| @@ -161,10 +161,13 @@ | |
| 161 | return f'href="{base}/docs/www/help.wiki"' |
| 162 | # Bare .wiki or .md file paths (from relative link resolution) |
| 163 | m = re.match(r"/([^/]+\.(?:wiki|md|html))", url) |
| 164 | if m: |
| 165 | return f'href="{base}/docs/www/{m.group(1)}"' |
| 166 | # Keep external and unrecognized links as-is |
| 167 | return match.group(0) |
| 168 | |
| 169 | def replace_scheme_link(match): |
| 170 | """Handle Fossil URI schemes like forum:/forumpost/HASH, wiki:PageName, info:HASH.""" |
| @@ -770,14 +773,27 @@ | |
| 770 | with reader: |
| 771 | checkin_uuid = reader.get_latest_checkin_uuid() |
| 772 | files = reader.get_files_at_checkin(checkin_uuid) if checkin_uuid else [] |
| 773 | |
| 774 | target = None |
| 775 | for f in files: |
| 776 | if f.name == doc_path: |
| 777 | target = f |
| 778 | break |
| 779 | |
| 780 | if not target: |
| 781 | raise Http404(f"Documentation file not found: {doc_path}") |
| 782 | |
| 783 | content_bytes = reader.get_file_content(target.uuid) |
| 784 |
| --- fossil/views.py | |
| +++ fossil/views.py | |
| @@ -161,10 +161,13 @@ | |
| 161 | return f'href="{base}/docs/www/help.wiki"' |
| 162 | # Bare .wiki or .md file paths (from relative link resolution) |
| 163 | m = re.match(r"/([^/]+\.(?:wiki|md|html))", url) |
| 164 | if m: |
| 165 | return f'href="{base}/docs/www/{m.group(1)}"' |
| 166 | # /setup_*, /admin_* -> these are Fossil server routes, link to admin |
| 167 | if re.match(r"/(setup_|admin_)", url): |
| 168 | return match.group(0) # Keep as-is, no good mapping |
| 169 | # Keep external and unrecognized links as-is |
| 170 | return match.group(0) |
| 171 | |
| 172 | def replace_scheme_link(match): |
| 173 | """Handle Fossil URI schemes like forum:/forumpost/HASH, wiki:PageName, info:HASH.""" |
| @@ -770,14 +773,27 @@ | |
| 773 | with reader: |
| 774 | checkin_uuid = reader.get_latest_checkin_uuid() |
| 775 | files = reader.get_files_at_checkin(checkin_uuid) if checkin_uuid else [] |
| 776 | |
| 777 | target = None |
| 778 | # Strip trailing slash for directory-style links |
| 779 | clean_path = doc_path.rstrip("/") |
| 780 | for f in files: |
| 781 | if f.name == clean_path: |
| 782 | target = f |
| 783 | break |
| 784 | |
| 785 | # If not found, try index files for directory links |
| 786 | if not target: |
| 787 | for index_name in [f"{clean_path}/index.html", f"{clean_path}/index.md", f"{clean_path}/index.wiki"]: |
| 788 | for f in files: |
| 789 | if f.name == index_name: |
| 790 | target = f |
| 791 | doc_path = index_name |
| 792 | break |
| 793 | if target: |
| 794 | break |
| 795 | |
| 796 | if not target: |
| 797 | raise Http404(f"Documentation file not found: {doc_path}") |
| 798 | |
| 799 | content_bytes = reader.get_file_content(target.uuid) |
| 800 |