Skip to content

Commit

Permalink
Include robots.txt in UI and API for handling of web crawlers
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Kanzer authored and Aaron Kanzer committed Nov 25, 2024
1 parent 0a4bf70 commit bdbeb30
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,5 @@ dmypy.json

# Editor settings
.vscode

.idea/
.DS_Store
2 changes: 2 additions & 0 deletions dandiapi/api/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .dandiset import DandisetViewSet
from .dashboard import DashboardView, mailchimp_csv_view, user_approval_view
from .info import info_view
from .robots import robots_txt_view
from .root import root_content_view
from .stats import stats_view
from .upload import (
Expand Down Expand Up @@ -36,4 +37,5 @@
'stats_view',
'info_view',
'root_content_view',
'robots_txt_view'
]
10 changes: 10 additions & 0 deletions dandiapi/api/views/robots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.views.decorators.cache import cache_page
from django.http import HttpResponse

@cache_page(60 * 60 * 24) # 24 hour cache
def robots_txt_view(request):
content = """
User-agent: *
Disallow: /
"""
return HttpResponse(content, content_type="text/plain")
3 changes: 3 additions & 0 deletions dandiapi/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
blob_read_view,
info_view,
mailchimp_csv_view,
robots_txt_view,
root_content_view,
stats_view,
upload_complete_view,
Expand Down Expand Up @@ -80,9 +81,11 @@ def to_url(self, value):
register_converter(DandisetIDConverter, 'dandiset_id')
urlpatterns = [
path('', root_content_view),
path("robots.txt", robots_txt_view),
path('api/', include(router.urls)),
path('api/auth/token/', auth_token_view, name='auth-token'),
path('api/stats/', stats_view),
path('api/stats/', stats_view),
path('api/info/', info_view),
path('api/blobs/digest/', blob_read_view, name='blob-read'),
path('api/uploads/initialize/', upload_initialize_view, name='upload-initialize'),
Expand Down
2 changes: 2 additions & 0 deletions web/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
User-agent: *
Disallow: /

0 comments on commit bdbeb30

Please sign in to comment.