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

added 'netloc-tag' to URL_RENDER_MODE values #802

Merged
merged 1 commit into from
Dec 16, 2024
Merged
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
2 changes: 1 addition & 1 deletion bukuserver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))|
Expand Down
2 changes: 1 addition & 1 deletion bukuserver/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion bukuserver/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def _list_entry(self, context: Any, model: Namespace, name: str) -> Markup:
res += [f'<span class="netloc"> ({link(netloc, url_for_index_view_netloc)})</span>']
if not parsed_url.scheme:
res += [f'<span class="link">{escape(model.url)}</span>']
elif self.url_render_mode is None or self.url_render_mode == 'full':
elif self.url_render_mode == 'full':
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No change in logic here; this property is actually implemented in a way that prevents returning None in the first place

res += [f'<span class="link">{link(model.url, model.url, new_tab=new_tab)}</span>']
tag_links = []
if netloc and self.url_render_mode != 'netloc' and url_for_index_view_netloc:
Expand Down
4 changes: 3 additions & 1 deletion tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -323,6 +323,8 @@ def test_env_entry_render_params(bukudb, app, client, mode, favicons, new_tab):
suffix = f'<div class="tag-list">{netloc_tag}{"".join(tags)}</div><div class="description">{desc}</div> </td>'
if mode == 'netloc':
assert cell == f'{prefix}<span class="netloc"> (<a href="/bookmark/?flt0_url_netloc_match={netloc}">{netloc}</a>)</span>{suffix}'
elif mode == 'netloc-tag':
assert cell == prefix + suffix
else:
assert cell == f'{prefix}<span class="link"><a href="{url}"{target}>{url}</a></span>{suffix}'

Expand Down