forked from retoor/devplacepy
feat: add dynamic gist language sidebar filtering based on existing database entries
Add a new `get_gist_languages()` function in database.py that queries distinct language codes from the gists table and caches results for 60 seconds. Create a database index on the `language` column of the gists table for efficient queries. Update the gists router to pass the set of active language codes to the template. Modify the gists.html sidebar to only display language filter links for codes that actually have gists in the database, hiding empty language categories and conditionally showing the plaintext link.
This commit is contained in:
@@ -4,7 +4,7 @@ from datetime import datetime, timezone
|
||||
from fastapi import APIRouter, Request, HTTPException, Form
|
||||
from devplacepy.models import GistForm, GistEditForm
|
||||
from fastapi.responses import HTMLResponse, RedirectResponse
|
||||
from devplacepy.database import get_table, get_users_by_uids
|
||||
from devplacepy.database import get_table, get_users_by_uids, get_gist_languages
|
||||
from devplacepy.content import load_detail, edit_content_item, delete_content_item, enrich_items
|
||||
from devplacepy.templating import templates
|
||||
from devplacepy.utils import generate_uid, get_current_user, require_user, make_combined_slug, create_mention_notifications
|
||||
@@ -65,6 +65,7 @@ async def gists_page(request: Request, language: str = None, user_uid: str = Non
|
||||
"total_count": total_count,
|
||||
"current_language": language,
|
||||
"languages": LANGUAGES,
|
||||
"gist_language_codes": get_gist_languages(),
|
||||
})
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user