-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Changes on 404, robots, and sitemap #6798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f8b9abf
Tests
stsewd 36123df
Adapt code to new design doc
stsewd 0ff5e15
Merge branch 'master' into 404-robots-sitemap
stsewd 393a9ca
Merge branch 'master' into 404-robots-sitemap
stsewd 867dd30
Merge branch 'master' into 404-robots-sitemap
stsewd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,19 +14,17 @@ | |
from django.views import View | ||
from django.views.decorators.cache import cache_page | ||
|
||
from readthedocs.builds.constants import LATEST, STABLE, EXTERNAL | ||
from readthedocs.builds.constants import EXTERNAL, LATEST, STABLE | ||
from readthedocs.builds.models import Version | ||
from readthedocs.core.utils.extend import SettingsOverrideObject | ||
from readthedocs.projects import constants | ||
from readthedocs.projects.templatetags.projects_tags import sort_version_aware | ||
from readthedocs.redirects.exceptions import InfiniteRedirectException | ||
|
||
from .mixins import ServeDocsMixin, ServeRedirectMixin | ||
|
||
from .decorators import map_project_slug | ||
from .mixins import ServeDocsMixin, ServeRedirectMixin | ||
from .utils import _get_project_data_from_request | ||
|
||
|
||
log = logging.getLogger(__name__) # noqa | ||
|
||
|
||
|
@@ -266,14 +264,17 @@ def get(self, request, proxito_path, template_name='404.html'): | |
if default_version_slug != version_slug: | ||
versions.append(default_version_slug) | ||
for version_slug_404 in versions: | ||
if not self.allowed_user(request, final_project, version_slug_404): | ||
continue | ||
|
||
storage_root_path = final_project.get_storage_path( | ||
type_='html', | ||
version_slug=version_slug_404, | ||
include_file=False, | ||
version_type=self.version_type, | ||
) | ||
for tryfile in ('404.html', '404/index.html'): | ||
storage_root_path = final_project.get_storage_path( | ||
type_='html', | ||
version_slug=version_slug_404, | ||
include_file=False, | ||
version_type=self.version_type, | ||
) | ||
storage_filename_path = os.path.join(storage_root_path, tryfile) | ||
storage_filename_path = f'{storage_root_path}/{tryfile}' | ||
if storage.exists(storage_filename_path): | ||
log.info( | ||
'Serving custom 404.html page: [project: %s] [version: %s]', | ||
|
@@ -307,9 +308,7 @@ def get(self, request, project): | |
version = project.versions.get(slug=version_slug) | ||
|
||
no_serve_robots_txt = any([ | ||
# If project is private or, | ||
project.privacy_level == constants.PRIVATE, | ||
# default version is private or, | ||
# If the default version is private or, | ||
version.privacy_level == constants.PRIVATE, | ||
# default version is not active or, | ||
not version.active, | ||
|
@@ -327,7 +326,7 @@ def get(self, request, project): | |
include_file=False, | ||
version_type=self.version_type, | ||
) | ||
path = os.path.join(storage_path, 'robots.txt') | ||
path = f'{storage_path}/robots.txt' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't use path.join for storage paths, there are more in this file |
||
|
||
storage = get_storage_class(settings.RTD_BUILD_MEDIA_STORAGE)() | ||
if storage.exists(path): | ||
|
@@ -369,9 +368,7 @@ def get(self, request, project): | |
frequency. Starting from 1 and decreasing by 0.1 for priorities and starting | ||
from daily, weekly to monthly for change frequency. | ||
|
||
If the project is private, the view raises ``Http404``. On the other hand, | ||
if the project is public but a version is private, this one is not included | ||
in the sitemap. | ||
If the project doesn't have any public version, the view raises ``Http404``. | ||
|
||
:param request: Django request object | ||
:param project: Project instance to generate the sitemap | ||
|
@@ -417,15 +414,14 @@ def changefreqs_generator(): | |
changefreqs = ['weekly', 'daily'] | ||
yield from itertools.chain(changefreqs, itertools.repeat('monthly')) | ||
|
||
if project.privacy_level == constants.PRIVATE: | ||
public_versions = Version.internal.public( | ||
project=project, | ||
only_active=True, | ||
) | ||
if not public_versions.exists(): | ||
raise Http404 | ||
|
||
sorted_versions = sort_version_aware( | ||
Version.internal.public( | ||
project=project, | ||
only_active=True, | ||
), | ||
) | ||
sorted_versions = sort_version_aware(public_versions) | ||
|
||
# This is a hack to swap the latest version with | ||
# stable version to get the stable version first in the sitemap. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. This is going to add even more queries to our slow 404's. I'm a bit worried about that. I guess it won't cause a query on the .org, which is where i'm most worried about it, so it should be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, on .org that function just returns True, it doesn't query the db.