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

Allow URL shortening for non-gitlab.com GitLab repositories #2065

Open
mattpitkin opened this issue Dec 3, 2024 · 2 comments
Open

Allow URL shortening for non-gitlab.com GitLab repositories #2065

mattpitkin opened this issue Dec 3, 2024 · 2 comments
Labels
kind: enhancement New feature or request

Comments

@mattpitkin
Copy link

Currently, the ShortLinkTransform class is hardcoded to work for URLs in the github.com or gitlab.com domains. It would be nice if it would also work with non-gitlab.com domained GitLab repositories, if you have specified a gitlab_url in the Sphinx conf.py html_context dictionary, e.g.

html_context = {
    "gitlab_url": "https://gitlab.mydomain.com/",
    ...
}

I've created my own hacked version of the pydata-sphinx-theme, by editing the setup() function to contain:

    if hasattr(app.config, "html_context"):
        gitlab_url = app.config.html_context.get("gitlab_url", "")

        if gitlab_url.startswith("https://"):
            gitlab_url = {gitlab_url[8:].rstrip("/"): "gitlab"}
        elif gitlab_url.startswith("http://"):
            gitlab_url = {gitlab_url[7:].rstrip("/"): "gitlab"}
        else:
            gitlab_url = {}

        class ShortenLinkTransformCustom(short_link.ShortenLinkTransform):
            supported_platform = short_link.ShortenLinkTransform.supported_platform
            supported_platform.update(gitlab_url)

        app.add_post_transform(ShortenLinkTransformCustom)
    else:
        app.add_post_transform(short_link.ShortenLinkTransform)

where I've created a new locally scoped class that add the required URL into the supported_platform class attribute from the ShortenLinkTransform class. This is not particularly elegant, and there's probably a better way, but if this is considered useful I can open a PR with the changes (and some added documentation).

@drammock
Copy link
Collaborator

drammock commented Dec 3, 2024

agree that it seems like a useful improvement. Haven't thought much about the implementation so no comment yet on

This is not particularly elegant, and there's probably a better way

@mattpitkin
Copy link
Author

I've created a PR for this in #2068.

@trallard trallard added the kind: enhancement New feature or request label Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants