Skip to content

Commit

Permalink
feat: add wildcards and documentation about matching
Browse files Browse the repository at this point in the history
  • Loading branch information
Sayrus committed Nov 23, 2022
1 parent c68d487 commit 2844378
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -168,6 +168,9 @@ url_data = {
}
```

`host` supports wildcards (`*`) for pattern matching. `<host.tld>` takes
precedence over `<host.*>`.

`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.
Expand Down
7 changes: 4 additions & 3 deletions lua/gitlinker/hosts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 2844378

Please sign in to comment.