From 2844378ef2663d1e20565c97542472bf73360137 Mon Sep 17 00:00:00 2001 From: Mathis Raguin Date: Wed, 23 Nov 2022 14:49:07 +0100 Subject: [PATCH] feat: add wildcards and documentation about matching --- README.md | 9 ++++++--- lua/gitlinker/hosts.lua | 7 ++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 269d5718..0cf0e1ba 100644 --- a/README.md +++ b/README.md @@ -128,11 +128,11 @@ require"gitlinker".setup({ print_url = true, }, callbacks = { - ["github.com"] = require"gitlinker.hosts".get_github_type_url, - ["gitlab.com"] = require"gitlinker.hosts".get_gitlab_type_url, + ["github.*"] = require"gitlinker.hosts".get_github_type_url, + ["gitlab.*"] = require"gitlinker.hosts".get_gitlab_type_url, ["try.gitea.io"] = require"gitlinker.hosts".get_gitea_type_url, ["codeberg.org"] = require"gitlinker.hosts".get_gitea_type_url, - ["bitbucket.org"] = require"gitlinker.hosts".get_bitbucket_type_url, + ["bitbucket.*"] = require"gitlinker.hosts".get_bitbucket_type_url, ["try.gogs.io"] = require"gitlinker.hosts".get_gogs_type_url, ["git.sr.ht"] = require"gitlinker.hosts".get_srht_type_url, ["git.launchpad.net"] = require"gitlinker.hosts".get_launchpad_type_url, @@ -168,6 +168,9 @@ url_data = { } ``` +`host` supports wildcards (`*`) for pattern matching. `` takes +precedence over ``. + `port` will always be `nil` except when the remote URI configured locally is http(s) **and specifies a port** (e.g. `http://localhost:3000/user/repo.git`), in which case the generated url permalink also needs the right port. diff --git a/lua/gitlinker/hosts.lua b/lua/gitlinker/hosts.lua index b7c34a85..e3f6f201 100644 --- a/lua/gitlinker/hosts.lua +++ b/lua/gitlinker/hosts.lua @@ -187,11 +187,12 @@ function M.get_matching_callback(target_host) end M.callbacks = { - ["github.com"] = M.get_github_type_url, - ["gitlab.com"] = M.get_gitlab_type_url, + ["github.*"] = M.get_github_type_url, + ["ghe.*"] = M.get_github_type_url, + ["gitlab.*"] = M.get_gitlab_type_url, ["try.gitea.io"] = M.get_gitea_type_url, ["codeberg.org"] = M.get_gitea_type_url, - ["bitbucket.org"] = M.get_bitbucket_type_url, + ["bitbucket.*"] = M.get_bitbucket_type_url, ["try.gogs.io"] = M.get_gogs_type_url, ["git.sr.ht"] = M.get_srht_type_url, ["git.launchpad.net"] = M.get_launchpad_type_url,