Skip to content

Commit

Permalink
Merge pull request #802 from LeXofLeviafan/url-render-netloc-tag
Browse files Browse the repository at this point in the history
added 'netloc-tag' to URL_RENDER_MODE values
  • Loading branch information
jarun authored Dec 16, 2024
2 parents 0e9cb92 + a43c79b commit 349662a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
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':
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

0 comments on commit 349662a

Please sign in to comment.