daizutabi / mkapi

A plugin for MkDocs to generate API documentation
https://daizutabi.github.io/mkapi/
MIT License
95 stars 19 forks source link

Links: Option to add trailing slash? Use trailing slash by default? #25

Closed tony closed 7 months ago

tony commented 4 years ago

This is anecdotal, but CloudFront wants paths to end in a slash:

https://libvcs.git-pull.com/api/source/libvcs.hg/#libvcs.hg.MercurialRepo

https://libvcs.git-pull.com/api/source/libvcs.hg#libvcs.hg.MercurialRepo

image

Thoughts on adding this as a default behavior? Setting?

diff --git a/mkapi/core/postprocess.py b/mkapi/core/postprocess.py
index 959aa77..bab3313 100644
--- a/mkapi/core/postprocess.py
+++ b/mkapi/core/postprocess.py
@@ -11,7 +11,7 @@ def sourcelink(object: Object) -> str:
         link = f'<span id="{object.id}"></span>'
     else:
         link = ""
-    link += f'<a class="mkapi-src-link" href="../source/{object.module}'
+    link += f'<a class="mkapi-src-link" href="../source/{object.module}/'
     link += f'#{object.id}" title="Source for {object.id}">&lt;/&gt;</a>'
     return link

diff --git a/mkapi/templates/object.jinja2 b/mkapi/templates/object.jinja2
index da1ef7f..f7a0a11 100644
--- a/mkapi/templates/object.jinja2
+++ b/mkapi/templates/object.jinja2
@@ -11,7 +11,7 @@
   </div>
   {% if 'sourcelink' in filters or 'link' in filters or 'apilink' in filters -%}
   <div class="mkapi-src-link">
-    <a class="mkapi-src-link" href="../source/{{ object.module }}#{{ object.id }}" title="Source for {{ object.id }}">&lt;/&gt;</a>
+    <a class="mkapi-src-link" href="../source/{{ object.module }}/#{{ object.id }}" title="Source for {{ object.id }}">&lt;/&gt;</a>
   </div>
   {%- endif %}
 </div>

Currently I hard-code this in a forked package since I feel its too specialized (and I'm not sure what other static file hosts use)

daizutabi commented 4 years ago

Thank you for reporting this issue. Adding a trailing slash is correct. I updated these files + mkapi/core/code.py.