Skip to content

Commit

Permalink
💄 Add option to clean titles
Browse files Browse the repository at this point in the history
  • Loading branch information
essembeh committed Feb 9, 2024
1 parent d65ddc4 commit 4f3fb91
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 14 deletions.
4 changes: 3 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ YOURSS_USER_demo=@jonnygiger,@berricks
# docker run --rm -ti -p 6379:6379 redis
#YOURSS_REDIS_URL=redis://localhost:6379/0
YOURSS_TTL_AVATAR=60
YOURSS_TTL_RSS=60
YOURSS_TTL_RSS=60

YOURSS_CLEAN_TITLES=true
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Then visit [http://localhost:8000/](http://localhost:8000/)
- `YOURSS_REDIS_URL`: you can use a redis instance to cache RSS feeds and avatars (for example: `redis://localhost:6379/0`)
- `YOURSS_TTL_AVATAR`: the TTL of cached avatars (default is `24 * 3600`, 24 hours)
- `YOURSS_TTL_AVATAR`: the TTL of cached RSS feeds (default is `3600`, 1 hour)
- `YOURSS_CLEAN_TITLES`: if set to `true`, videos titles are cleaned to prevent UPPERCASE TITLES
- `LOGURU_LEVEL` for logging level

> Note: channels can be Youtube username (like `@JonnyGiger`) or directly a *channel_id* (24 alnum chars) like `UCa_Dlwrwv3ktrhCy91HpVRw`, to provide a list, use a coma between channels
Expand Down
2 changes: 2 additions & 0 deletions charts/yourss/templates/yourss.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ spec:
- name: YOURSS_TTL_RSS
value: "{{ .Values.redis.ttl.rss }}"
{{- end }}
- name: YOURSS_CLEAN_TITLES
value: "{{ .Values.yourss.cleanTitles }}"
ports:
- name: http
containerPort: 8000
Expand Down
24 changes: 15 additions & 9 deletions charts/yourss/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ yourss:
pullPolicy: IfNotPresent
timezone: Europe/Paris
logLevel: INFO
defaultChannels:
- "@jonnygiger"
users: []
cleanTitles: true
defaultChannels:
- "@jonnygiger"
users:
[]
# - name: demo
# channels:
# channels:
# - "@jonnygiger"
# - "@berricks"

redis:
enabled: false
image:
repository: redis
tag: 7
tag: 7
pullPolicy: IfNotPresent
ttl:
avatar: 86400
Expand All @@ -47,10 +49,12 @@ serviceAccount:
podAnnotations: {}
podLabels: {}

podSecurityContext: {}
podSecurityContext:
{}
# fsGroup: 2000

securityContext: {}
securityContext:
{}
# capabilities:
# drop:
# - ALL
Expand All @@ -65,7 +69,8 @@ service:
ingress:
enabled: false
className: ""
annotations: {}
annotations:
{}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
hosts:
Expand All @@ -78,7 +83,8 @@ ingress:
# hosts:
# - chart-example.local

resources: {}
resources:
{}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
Expand Down
1 change: 1 addition & 0 deletions yourss/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class AppConfig:
REDIS_URL = environ.var(default=None)
TTL_AVATAR = environ.var(converter=int, default=24 * 3600)
TTL_RSS = environ.var(converter=int, default=3600)
CLEAN_TITLES = environ.bool_var(default=False)


YOURSS_USER_PREFIX = "YOURSS_USER_"
Expand Down
2 changes: 1 addition & 1 deletion yourss/templates/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ <h5 class="card-title h5">
<span class="fw-bold" style="cursor: pointer;" onclick="window.open('{{ feed.link }}')">{{ feed.title }}</span>
</h5>
<p class="card-text">
{{ video.title|escape }}
{{ video.title|escape|clean_title }}
</p>
<p class="card-text mt-auto">
<i class="new-item bi bi-bookmark-fill" style="color: rgb(34, 93, 219);" onclick="mark_as_read('{{ video.published }}')">
Expand Down
15 changes: 12 additions & 3 deletions yourss/webapp/www.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from fastapi import APIRouter, Depends, HTTPException, Query, Request
from fastapi.responses import RedirectResponse
from fastapi.templating import Jinja2Templates
from jinja2 import Environment, FileSystemLoader
from loguru import logger
from starlette.responses import HTMLResponse

Expand All @@ -14,9 +15,17 @@
from ..youtube import YoutubeWebClient
from .utils import get_youtube_client

TemplateResponse = Jinja2Templates(
directory=Path(yourss.__file__).parent / "templates"
).TemplateResponse

def clean_title(text: str) -> str:
if current_config.CLEAN_TITLES:
return text.capitalize()
return text


# Jinja customization
env = Environment(loader=FileSystemLoader(Path(yourss.__file__).parent / "templates"))
env.filters["clean_title"] = clean_title
TemplateResponse = Jinja2Templates(env=env).TemplateResponse

router = APIRouter()

Expand Down

0 comments on commit 4f3fb91

Please sign in to comment.