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

feat(posts): green title for sticky posts + other improvements #170

Merged
merged 5 commits into from
May 28, 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
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,16 @@ jobs:
with:
image_name: ${{ env.GHCR_REGISTRY_IMAGE }}
registry: ghcr
create-release:
name: Create release
runs-on: ubuntu-latest
needs:
- docker_merge
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v4
- uses: taiki-e/create-gh-release-action@v1
with:
changelog: CHANGELOG.md
token: ${{ secrets.GITHUB_TOKEN }}
title: Version $version
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Version 0.8.6

- Sticky posts now have a green title

# Version 0.8.5

- Docker image: add more architectures
Expand Down
2 changes: 1 addition & 1 deletion eddrit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from eddrit import config

__version__ = "0.8.5"
__version__ = "0.8.6"

logger.remove()
logger.add(sys.stderr, level=config.LOG_LEVEL)
40 changes: 35 additions & 5 deletions eddrit/routes/common/context.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections.abc import Iterable
from typing import Any
from enum import Enum
from typing import Any, TypeVar
from urllib.parse import urlparse

from starlette.requests import Request
Expand All @@ -8,6 +9,25 @@
from eddrit.models.settings import LayoutMode, ThumbnailsMode
from eddrit.routes.common.cookies import get_bool_setting_value_from_cookie

EnumTypeVar = TypeVar("EnumTypeVar", bound=Enum)


def _get_setting_with_default_fallback(
cookies_source: dict[str, str],
setting_name: str,
enum_cls: type[EnumTypeVar],
default_value: EnumTypeVar,
) -> EnumTypeVar:
"""
Get setting value for the given setting from the cookies_source for the given enum class with
a fallback to the default value provided.
"""
try:
setting_value = enum_cls(cookies_source.get(setting_name, default_value.value))
except ValueError:
setting_value = default_value
return setting_value


def get_templates_common_context(
request: Request, cookies: dict[str, str] | None = None
Expand All @@ -20,11 +40,21 @@ def get_templates_common_context(
not in the original request.
"""
cookies_source = cookies if cookies else request.cookies

# Get settings
layout = _get_setting_with_default_fallback(
cookies_source, "layout", LayoutMode, LayoutMode.WIDE
)
thumbnails = _get_setting_with_default_fallback(
cookies_source,
"thumbnails",
ThumbnailsMode,
ThumbnailsMode.SUBREDDIT_PREFERENCE,
)

settings = models.Settings(
layout=LayoutMode(cookies_source.get("layout", LayoutMode.WIDE.value)),
thumbnails=ThumbnailsMode(
cookies_source.get("thumbnails", ThumbnailsMode.SUBREDDIT_PREFERENCE.value)
),
layout=layout,
thumbnails=thumbnails,
nsfw_popular_all=get_bool_setting_value_from_cookie(
"nsfw_popular_all", cookies_source
),
Expand Down
270 changes: 133 additions & 137 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "eddrit"
version = "0.8.5"
version = "0.8.6"
description = "Alternative Reddit frontend"
authors = ["corenting <corenting@gmail.com>"]
license = "MIT"
Expand Down
3 changes: 3 additions & 0 deletions static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ html[data-theme='dark'] .dark-inverted {
align-items: baseline;
flex-wrap: wrap;
gap: var(--pico-nav-link-spacing-horizontal);
}

.post-sticky {
color: green;
}

.posts-list-pagination-button {
Expand Down
2 changes: 1 addition & 1 deletion templates/macros/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
{# Title + flairs #}
<div class="col post-title">
<a href="{{ post.url }}">
<strong>{{ post.title }}</strong>
<strong class="{{ 'post-sticky' if post.is_sticky else '' }}">{{ post.title }}</strong>
</a>
<small>({{ post.domain }}) </small>
<small>
Expand Down