Skip to content
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

Implement a specific robots.txt for Volto sites #183

Merged
merged 8 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions news/178.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Implement a specific robots.txt for Volto sites.
There is an upgrade step which will update the existing plone.robots_txt registry setting unless it has been customized.
@ericof
2 changes: 1 addition & 1 deletion src/plone/volto/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<metadata>
<version>1018</version>
<version>1019</version>
<dependencies>
<dependency>profile-plone.restapi:blocks</dependency>
</dependencies>
Expand Down
60 changes: 0 additions & 60 deletions src/plone/volto/profiles/default/registry.xml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<registry>

<!-- Allowed sizes -->
<record field="allowed_sizes"
interface="plone.base.interfaces.controlpanel.IImagingSchema"
name="plone.allowed_sizes"
purge="True"
>
<!-- Purge the existing ones! -->
<value>
<element>icon 32:32</element>
<element>tile 64:64</element>
<element>thumb 128:128</element>
<element>mini 200:65536</element>
<element>preview 400:65536</element>
<element>teaser 600:65536</element>
<element>large 800:65536</element>
<element>larger 1000:65536</element>
<element>great 1200:65536</element>
<element>huge 1600:65536</element>
</value>
</record>
</registry>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<registry>

<record field="show_excluded_items"
interface="plone.base.interfaces.controlpanel.INavigationSchema"
name="plone.show_excluded_items"
>
<value>False</value>
</record>

</registry>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<registry>

<record field="types_not_searched"
interface="plone.base.interfaces.controlpanel.ISearchSchema"
name="plone.types_not_searched"
purge="true"
>
<value />
</record>

</registry>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<registry>
<record field="robots_txt"
interface="plone.base.interfaces.controlpanel.ISiteSchema"
name="plone.robots_txt"
purge="true"
>
<value>Sitemap: {portal_url}/sitemap-index.xml

# Define access-restrictions for robots/spiders
# http://www.robotstxt.org/wc/norobots.html

User-agent: *
Disallow: /search
Disallow: /login

# Add Googlebot-specific syntax extension to exclude forms
# that are repeated for each piece of content in the site
# the wildcard is only supported by Googlebot
# http://www.google.com/support/webmasters/bin/answer.py?answer=40367&amp;ctx=sibling

User-Agent: Googlebot
Disallow: /*login
Disallow: /*search
Disallow: /*edit
</value>
</record>
</registry>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<registry>
<record field="types_use_view_action_in_listings"
interface="plone.base.interfaces.controlpanel.ITypesSchema"
name="plone.types_use_view_action_in_listings"
purge="true"
>
<value />
</record>
</registry>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<registry>

<records interface="plone.volto.interfaces.IVoltoSettings"
prefix="volto"
/>

</registry>
11 changes: 11 additions & 0 deletions src/plone/volto/profiles/default/registry/registry.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<registry>

<record name="plone.icon.volto-settings">
<field type="plone.registry.field.TextLine">
<title>Plone Icon Volto Control Panel</title>
</field>
<value key="resource">++plone++plone.volto/volto.svg</value>
</record>

</registry>
34 changes: 34 additions & 0 deletions src/plone/volto/upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,37 @@ def rename_distribution(context):
report.name = "volto"
if report.answers.get("distribution") == "default":
report.answers["distribution"] = "volto"


ROBOTS_TXT = """Sitemap: {portal_url}/sitemap-index.xml

# Define access-restrictions for robots/spiders
# http://www.robotstxt.org/wc/norobots.html

User-agent: *
Disallow: /search
Disallow: /login

# Add Googlebot-specific syntax extension to exclude forms
# that are repeated for each piece of content in the site
# the wildcard is only supported by Googlebot
# http://www.google.com/support/webmasters/bin/answer.py?answer=40367&ctx=sibling

User-Agent: Googlebot
Disallow: /*login
Disallow: /*search
Disallow: /*edit
"""


def update_robots_txt(context):
from plone.base.interfaces.controlpanel import ROBOTS_TXT as CLASSIC_ROBOTS

current_value = api.portal.get_registry_record("plone.robots_txt")
if current_value == CLASSIC_ROBOTS:
api.portal.set_registry_record("plone.robots_txt", ROBOTS_TXT)
logger.info("Updated plone.robots_txt registry with sane value.")
else:
logger.info(
"Ignoring plone.robots_txt registry as it was modified in this portal."
)
10 changes: 10 additions & 0 deletions src/plone/volto/upgrades.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,14 @@
/>
</genericsetup:upgradeSteps>

<genericsetup:upgradeSteps
profile="plone.volto:default"
source="1018"
destination="1019"
>
<genericsetup:upgradeStep
title="Update robots_txt setting for Volto"
handler=".upgrades.update_robots_txt"
/>
</genericsetup:upgradeSteps>
</configure>
2 changes: 1 addition & 1 deletion tests/setup/test_setup_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_browserlayer(self, browser_layers):

def test_latest_version(self, profile_last_version):
"""Test latest version of default profile."""
assert profile_last_version(f"{PACKAGE_NAME}:default") == "1018"
assert profile_last_version(f"{PACKAGE_NAME}:default") == "1019"

@pytest.mark.parametrize(
"portal_type,behavior",
Expand Down
Loading