feat: Enhance project channel search flexibility
Introduced `unslugify` function to expand search capabilities by generating possible original titles from slugs, allowing for a broader search when matching project channels. This function is utilized in the `project_list` method to attempt queries with different variants of a channel's name, enhancing the likelihood of matching user-desired content. The update optimizes search functionality and user experience by accommodating varied naming conventions. Version incremented to 0.2.2 in project metadata to reflect new feature addition and improvements.
This commit is contained in:
parent
c593904a19
commit
c60da5ec3a
2 changed files with 37 additions and 6 deletions
|
@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|||
|
||||
[project]
|
||||
name = "structables"
|
||||
version = "0.2.1"
|
||||
version = "0.2.2"
|
||||
authors = [
|
||||
{ name="Private.coffee Team", email="support@private.coffee" },
|
||||
]
|
||||
|
|
|
@ -14,6 +14,7 @@ from urllib.error import HTTPError
|
|||
from traceback import print_exc
|
||||
from urllib.parse import urlparse
|
||||
from argparse import ArgumentParser
|
||||
from typing import List
|
||||
|
||||
from werkzeug.exceptions import BadRequest, abort, InternalServerError, NotFound
|
||||
from bs4 import BeautifulSoup
|
||||
|
@ -59,6 +60,26 @@ invidious = None
|
|||
unsafe = False
|
||||
|
||||
|
||||
def unslugify(slug: str) -> List[str]:
|
||||
"""Return a list of possible original titles for a slug.
|
||||
|
||||
Args:
|
||||
slug (str): The slug to unslugify.
|
||||
|
||||
Returns:
|
||||
List[str]: A list of possible original titles for the slug.
|
||||
"""
|
||||
|
||||
results = []
|
||||
|
||||
results.append(slug.replace("-", " ").title())
|
||||
|
||||
if "and" in slug:
|
||||
results.append(results[0].replace("And", "&").title())
|
||||
|
||||
return results
|
||||
|
||||
|
||||
def projects_search(
|
||||
query="*",
|
||||
category="",
|
||||
|
@ -402,9 +423,18 @@ def project_list(head, sort="", per_page=20):
|
|||
category = parts[1]
|
||||
channel = "" if parts[2] == "projects" else parts[2]
|
||||
|
||||
project_ibles, total = projects_search(
|
||||
category=category, channel=channel, per_page=per_page, page=page
|
||||
)
|
||||
channel_names = unslugify(channel)
|
||||
|
||||
for channel_name in channel_names:
|
||||
project_ibles, total = projects_search(
|
||||
category=category,
|
||||
channel=channel_name,
|
||||
per_page=per_page,
|
||||
page=page,
|
||||
)
|
||||
|
||||
if project_ibles:
|
||||
break
|
||||
|
||||
elif "search" in path.split("/"):
|
||||
ibles = []
|
||||
|
@ -1275,6 +1305,7 @@ def main():
|
|||
|
||||
app.run(port=args.port, host=args.listen_host, debug=debugmode)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
|
Loading…
Reference in a new issue