Compare commits

..

3 commits

Author SHA1 Message Date
2ecdb81f62
qutebrowser: Enable javascript for docker hub 2025-02-18 17:07:22 +01:00
53f2c49385
qutebrowser: Refactor redirects as importable class
The redirects 'plugin' is now a simple class which can be imported into
the configuration and is automatically active when instantiated. For
that to work it needs access to the qutebrowser python library but that
should hopefully be a given if wanting to have a qutebrowser plugin.

To make the default redirects active, simply import the class and
instantiate it:

```python
from fossredirect import Redirects
_ = Redirects()
```

This loads the defaults and activates them in qutebrowser. Try to go to
e.g. 'reddit.com' and it will automatically open in a libreddit
frontend.
To customize the redirects, provide a custom list of Services:

```python
from fossredirect import Redirects
_ = Redirects(services=[Service(source=["fromhere.com"], target=["tohere"])])
```

It works a little more flexibly now:
Redirects contains a list of Services.
Each service is a simple data container with the following:

```python
Service(
     source=["list.of", "hosts.to", "redirect.com"],
     target=["farside-redirect"]
)
```

The above redirects any of the source hosts to the far-side provided
target (in this case it would be
`farside.link/farside-redirect/<original-path>`).

However we can also specify 'custom' targets if farside does not have a
service that we want to redirect.

```python
Service(
     source=["list.of", "hosts.to", "redirect.com"],
     target=["my-redirected-host.org"],
     custom_targets=True
)
```

This directly rewrites the host to
`https://my-redirected-host.org/<original-path>`.

Lastly, we can have custom preprocess/postprocess functions which fix
some more involved redirect:

```python
Service(
     source=["list.of", "hosts.to", "redirect.com"],
     target=["my-redirected-host.org"],
     postprocess=lambda item: item
)
```

Be aware that the functions take 'QUrl' objects so you have to access
e.g. the actual host with `item.host()` before rewriting. Look at the
breezewiki rewrite function for an easy example.
2025-02-18 17:07:21 +01:00
77ead6a618
qutebrowser: Refactor redirects plugin
Make more extensive using of dataclasses for typing and simpler future
refactors.
2025-02-18 17:07:21 +01:00
5 changed files with 2 additions and 10 deletions

View file

@ -5,8 +5,6 @@ from typing import cast
from qutebrowser.config.config import ConfigContainer # noqa: F401
from qutebrowser.config.configfiles import ConfigAPI
from freedirect.freedirect import Redirects
config: ConfigAPI = cast(ConfigAPI, config) # noqa: F821 pylint: disable=E0602,C0103
c: ConfigContainer = cast(ConfigContainer, c) # noqa: F821 pylint: disable=E0602,C0103
@ -61,9 +59,7 @@ config.source("alias.py")
config.source("maps.py")
config.source("content.py")
config.source("searchengines.py")
_ = Redirects()
config.source("fossredirect.py")
# Tab-Bar
# have tab bar on the right, not on the top

View file

@ -58,14 +58,10 @@ jloof() {
}
# show branches (i.e. head commits) w a couple previous commits
alias jh="jj log -r 'ancestors(heads(all()), 3)'"
alias jb="jj log -r 'ancestors(heads(all()), 3)'"
alias jrb="jj rebase"
# 'branching' bookmark work
alias jb="jj bookmark"
alias jbm="jj bookmark set main"
# remote work
alias jrv="jj git remote list"
alias jp="jj git push"