dynamic /robots.txt

This commit is contained in:
j 2017-12-15 12:59:56 +00:00
parent 3b73fe78bd
commit c640d1253e
6 changed files with 18 additions and 11 deletions

View File

@ -89,11 +89,17 @@ def opensearch_xml(request):
'application/xml' 'application/xml'
) )
def robots_txt(request, url): def robots_txt(request):
return HttpResponse( if settings.CONFIG['site'].get('public'):
'User-agent: *\nDisallow:\nSitemap: %s\n' % request.build_absolute_uri('/sitemap.xml'), robots_txt = '''User-agent: *
'text/plain' Disallow:
) Sitemap: {}
'''.format(request.build_absolute_uri('/sitemap.xml'))
else:
robots_txt = '''User-agent: *
Disallow: /
'''
return HttpResponse(robots_txt, 'text/plain')
def getPage(request, data): def getPage(request, data):
''' '''
@ -113,7 +119,7 @@ def getPage(request, data):
name = data['name'] name = data['name']
page, created = models.Page.objects.get_or_create(name=name) page, created = models.Page.objects.get_or_create(name=name)
if created: if created:
page.text= '' page.text = ''
page.save() page.save()
response = json_response({'name': page.name, 'text': page.text}) response = json_response({'name': page.name, 'text': page.text})
return render_to_json_response(response) return render_to_json_response(response)

View File

@ -1110,6 +1110,7 @@
"https": true, "https": true,
"id": "0xdb", "id": "0xdb",
"name": "0xDB", "name": "0xDB",
"public": true,
"sendReferrer": false, "sendReferrer": false,
"url": "0xDB.org" "url": "0xDB.org"
}, },

View File

@ -1579,10 +1579,11 @@
// E-mail address uses by the system (from) // E-mail address uses by the system (from)
"system": "system@indiancine.ma" "system": "system@indiancine.ma"
}, },
"folderdepth": 4, "folderdepth": 4,
"https": true, "https": true,
"id": "indiancinema", "id": "indiancinema",
"name": "Indiancine.ma", "name": "Indiancine.ma",
"public": true,
"sendReferrer": true, "sendReferrer": true,
"url": "indiancine.ma" "url": "indiancine.ma"
}, },

View File

@ -1063,6 +1063,7 @@
"https": true, "https": true,
"id": "padma", "id": "padma",
"name": "Pad.ma", "name": "Pad.ma",
"public": false,
"sendReferrer": true, "sendReferrer": true,
"url": "pad.ma" "url": "pad.ma"
}, },

View File

@ -1002,6 +1002,8 @@ examples (config.SITENAME.jsonc) that are part of this pan.do/ra distribution.
"https": false, "https": false,
"id": "pandora", "id": "pandora",
"name": "pan.do/ra", "name": "pan.do/ra",
// Set to true to allow search engines to index the site
"public": false,
"sendReferrer": true, "sendReferrer": true,
"url": "pandora.local" "url": "pandora.local"
}, },

View File

@ -54,10 +54,6 @@ urlpatterns = [
url(r'^texts/$', text.views.text), url(r'^texts/$', text.views.text),
url(r'^texts/(?P<id>.*?)/\d+$', text.views.text), url(r'^texts/(?P<id>.*?)/\d+$', text.views.text),
url(r'^texts/(?P<id>.*?)$', text.views.text), url(r'^texts/(?P<id>.*?)$', text.views.text),
url(r'^robots.txt$', serve_static_file, {
'location': os.path.join(settings.STATIC_ROOT, 'robots.txt'),
'content_type': 'text/plain'
}),
url(r'^favicon.ico$', serve_static_file, { url(r'^favicon.ico$', serve_static_file, {
'location': os.path.join(settings.STATIC_ROOT, 'png/icon.16.png'), 'location': os.path.join(settings.STATIC_ROOT, 'png/icon.16.png'),
'content_type': 'image/x-icon' 'content_type': 'image/x-icon'