使用Meteor可以创建部署特定的robots.txt文件吗?

3

我想在我的Meteor应用(在*.meteor.com上)的staging部署中包含一个public/robots.txt文件,基本上是为了完全避免这个版本的站点被爬取。我该如何做到这一点?我正在使用meteor deploy命令进行部署。

1个回答

0

我想出了一个(希望是暂时的?)解决方案,使用一个部署脚本,在调用meteor deploy之前创建public/robots.txt,并在最后删除public/robots.txt。

脚本:

#!/usr/bin/env python
import subprocess
import os.path

dpath = os.path.dirname(__file__)
if dpath:
  os.chdir(dpath)

if not os.path.exists('public'):
  os.makedirs('public')
robots = None
try:
  with open('public/robots.txt', 'wb') as robots:
    robots.write("""User-agent: *
Disallow: /
""")

  subprocess.check_call(["meteor", "deploy", '<myapp>.meteor.com'])
finally:
  if robots is not None:
    os.remove(robots.name)

如果没有安装spiderable包,Google实际上无法爬行您的网站。也许您的脚本可以简单地调用meteor remove spiderable,然后meteor deploy,接着再使用meteor add spiderable命令重新安装?或者只需在.meteor/packages文件中注释掉相关行即可。 - sbking
@sbking 嗯,我认为添加 robots.txt 或者移除 spiderable 只是实现细节问题。不应该有影响。 - aknuds1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接