From a43c79bd9e0a56767f9104de870e96f97d1a2510 Mon Sep 17 00:00:00 2001 From: LeXofLeviafan Date: Sun, 15 Dec 2024 21:26:03 +0100 Subject: [PATCH] added 'netloc-tag' to URL_RENDER_MODE values --- bukuserver/README.md | 2 +- bukuserver/server.py | 2 +- bukuserver/views.py | 2 +- tests/test_views.py | 4 +++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/bukuserver/README.md b/bukuserver/README.md index 86cee542..6a1602b1 100644 --- a/bukuserver/README.md +++ b/bukuserver/README.md @@ -112,7 +112,7 @@ The following are os env config variables available for bukuserver. | --- | --- | --- | | PER_PAGE | bookmarks per page | positive integer [default: 10] | | SECRET_KEY | [flask secret key](https://flask.palletsprojects.com/config/#SECRET_KEY) | string [default: os.urandom(24)] | -| URL_RENDER_MODE | url render mode | `full` or `netloc` [default: `full`] | +| URL_RENDER_MODE | url render mode | `full`, `netloc` or `netloc-tag` [default: `full`] | | DB_FILE | full path to db file | path string [default: standard path for buku] | | READONLY | read-only mode | boolean [default: `false`] | | DISABLE_FAVICON | disable bookmark [favicons](https://wikipedia.org/wiki/Favicon) | boolean [default: `true`] ([here's why](#why-favicons-are-disabled-by-default))| diff --git a/bukuserver/server.py b/bukuserver/server.py index 5ae498eb..5257ae3f 100644 --- a/bukuserver/server.py +++ b/bukuserver/server.py @@ -90,7 +90,7 @@ def create_app(db_file=None): per_page = per_page if per_page > 0 else views.DEFAULT_PER_PAGE app.config['BUKUSERVER_PER_PAGE'] = per_page url_render_mode = os.getenv('BUKUSERVER_URL_RENDER_MODE', views.DEFAULT_URL_RENDER_MODE) - if url_render_mode not in ('full', 'netloc'): + if url_render_mode not in ('full', 'netloc', 'netloc-tag'): url_render_mode = views.DEFAULT_URL_RENDER_MODE app.config['BUKUSERVER_URL_RENDER_MODE'] = url_render_mode app.config['SECRET_KEY'] = os.getenv('BUKUSERVER_SECRET_KEY') or os.urandom(24) diff --git a/bukuserver/views.py b/bukuserver/views.py index 0c00eed9..96e95ca3 100644 --- a/bukuserver/views.py +++ b/bukuserver/views.py @@ -135,7 +135,7 @@ def _list_entry(self, context: Any, model: Namespace, name: str) -> Markup: res += [f' ({link(netloc, url_for_index_view_netloc)})'] if not parsed_url.scheme: res += [f'{escape(model.url)}'] - elif self.url_render_mode is None or self.url_render_mode == 'full': + elif self.url_render_mode == 'full': res += [f'{link(model.url, model.url, new_tab=new_tab)}'] tag_links = [] if netloc and self.url_render_mode != 'netloc' and url_for_index_view_netloc: diff --git a/tests/test_views.py b/tests/test_views.py index 274a7297..971b42cb 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -300,7 +300,7 @@ def test_env_per_page(bukudb, app, client, total, per_page, pages, last_page): @pytest.mark.slow @pytest.mark.parametrize('new_tab', [False, True, None]) @pytest.mark.parametrize('favicons', [False, True, None]) -@pytest.mark.parametrize('mode', ['full', 'netloc', None]) +@pytest.mark.parametrize('mode', ['full', 'netloc', 'netloc-tag', None]) def test_env_entry_render_params(bukudb, app, client, mode, favicons, new_tab): url, netloc, title, desc, tags = 'http://example.com', 'example.com', 'Sample site', 'Foo bar baz', ',bar,baz,foo,' _add_rec(bukudb, url, title, tags, desc) @@ -323,6 +323,8 @@ def test_env_entry_render_params(bukudb, app, client, mode, favicons, new_tab): suffix = f'
{netloc_tag}{"".join(tags)}
{desc}
' if mode == 'netloc': assert cell == f'{prefix} ({netloc}){suffix}' + elif mode == 'netloc-tag': + assert cell == prefix + suffix else: assert cell == f'{prefix}{url}{suffix}'