Skip to content

Commit

Permalink
Extract shortened URLs to /s/ path
Browse files Browse the repository at this point in the history
This exact feature is not quite popular,
so it's better to do it earlier as possible.
This will solve problems with indexing by search engines,
problems with paths, etc.
  • Loading branch information
koldakov committed Sep 6, 2024
1 parent 9769c65 commit 364dd7f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion futuramaapi/routers/root/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ async def robots():


@router.get(
"/{shortened}",
"/s/{shortened}",
include_in_schema=False,
name="user_link_redirect",
)
Expand Down
5 changes: 3 additions & 2 deletions futuramaapi/routers/users/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,16 +295,17 @@ class Link(BaseModel, BaseModelDatabaseMixin):
)
created_at: datetime
counter: int
path_prefix: ClassVar[str] = "s"

@computed_field( # type: ignore[misc]
examples=[
settings.build_url(path="LWlWthH", is_static=False).unicode_string(),
settings.build_url(path=f"{path_prefix}/LWlWthH", is_static=False).unicode_string(),
],
return_type=str,
)
@property
def shortened_url(self) -> str:
return settings.build_url(path=self.shortened, is_static=False).unicode_string()
return settings.build_url(path=f"{self.path_prefix}/{self.shortened}", is_static=False).unicode_string()

@classmethod
async def create(
Expand Down
3 changes: 3 additions & 0 deletions robots.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
User-agent: *
Disallow: /api/
Disallow: /s/
Allow: /

User-agent: Googlebot
Disallow: /api/
Disallow: /s/
Allow: /

User-agent: Yandex
Disallow: /api/
Disallow: /s/
Allow: /

0 comments on commit 364dd7f

Please sign in to comment.