Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add wildcards and documentation about matching #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 3 additions & 3 deletions lua/gitlinker/hosts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ 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,
["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