summaryrefslogtreecommitdiff
path: root/templates/partials/history_url.html
diff options
context:
space:
mode:
Diffstat (limited to 'templates/partials/history_url.html')
-rw-r--r--templates/partials/history_url.html26
1 files changed, 26 insertions, 0 deletions
diff --git a/templates/partials/history_url.html b/templates/partials/history_url.html
new file mode 100644
index 0000000..8327ca3
--- /dev/null
+++ b/templates/partials/history_url.html
@@ -0,0 +1,26 @@
+{%- set relative_path = page.relative_path -%}
+{%- set repository_url = config.extra.remote_repository_url | trim_end_matches(pat='/') -%}
+{%- set branch = config.extra.remote_repository_branch | default(value="main") -%}
+{%- set git_platform = config.extra.remote_repository_git_platform | default(value="auto") -%}
+
+{# Auto-detect the git platform based on the URL#}
+{%- if git_platform == "auto" %}
+ {%- if repository_url is containing("github.") -%}
+ {%- set git_platform = "github" -%}
+ {%- elif repository_url is containing("gitlab.") -%}
+ {%- set git_platform = "gitlab" -%}
+ {%- elif repository_url is matching("(gitea\.|codeberg\.)") -%}
+ {%- set git_platform = "gitea" -%}
+ {%- endif -%}
+{%- endif -%}
+
+{# Generate the commit history URL based on the git platform #}
+{%- if git_platform == "github" -%}
+ {{ repository_url ~ '/commits/' ~ branch ~ '/content/' }}{{ relative_path | urlencode }}
+{%- elif git_platform == "gitlab" -%}
+ {{ repository_url ~ '/-/commits/' ~ branch ~ '/content/' }}{{ relative_path | urlencode }}
+{%- elif git_platform in ["gitea", "codeberg"] -%}
+ {{ repository_url ~ '/commits/branch/' ~ branch ~ '/content/' }}{{ relative_path | urlencode }}
+{%- else -%}
+ {{ throw(message="ERROR: Unknown, unsupported, or unspecified git platform. If you're using a custom domain, please specify the 'git_platform' in the config. If you think this is a bug, please report it: https://github.com/welpo/tabi/issues/new?assignees=&labels=bug&template=bug_report.md&title=Unsupported%20Git%20Platform%20Detected") }}
+{%- endif -%}