Sitemap generatior for sphinx
sphinx-sitemap的Python项目详细描述
一个Sphinx扩展,用于无提示地为生成符合sitemaps.org的站点地图 Sphinx文档的HTML版本。
安装
通过PIP直接安装,方法是:
pip install sphinx-sitemap
将sphinx_sitemap添加到sphinx conf.py中的extensions数组中。 例如:
extensions = ['sphinx_sitemap']
将sphinx conf.py中的html_baseurl值设置为当前值 带有尾随斜杠的文档的基URL。例如:
html_baseurl = 'https://my-site.com/docs/'
多语言配置
对于多语言站点地图,必须为每种语言/区域设置生成一个站点地图 然后手动将它们的位置添加到sitemapindex文件中。
扩展将查看当前语言的language配置值 正在生成,以及替代语言目录的locale_dirs值, 所以一定要准备好。
注意:扩展当前是自以为是的,因为它还将使用 version在生成的url中配置值。将其设置为latest是合适的 对于大多数用例。
对于每种语言/版本的构建,最终结果如下:
<?xml version="1.0" encoding="utf-8"?> <urlset xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url> <loc>https://my-site.com/docs/en/latest/index.html</loc> <xhtml:link href="https://my-site.com/docs/es/latest/index.html" hreflang="es" rel="alternate"/> <xhtml:link href="https://my-site.com/docs/fr/latest/index.html" hreflang="fr" rel="alternate"/> <xhtml:link href="https://my-site.com/docs/en/latest/index.html" hreflang="en" rel="alternate"/> </url> <url> <loc>https://my-site.com/docs/en/latest/about.html</loc> <xhtml:link href="https://my-site.com/docs/es/latest/about.html" hreflang="es" rel="alternate"/> <xhtml:link href="https://my-site.com/docs/fr/latest/about.html" hreflang="fr" rel="alternate"/> <xhtml:link href="https://my-site.com/docs/en/latest/index.html" hreflang="en" rel="alternate"/> </url> </urlset>
充分利用网站地图
在source目录中添加一个robots.txt文件,该文件包含指向 站点地图或站点地图索引。例如:
User-agent: * Sitemap: https://my-site.com/docs/sitemap.xml
然后,将robots.txt添加到html_extra_path配置值:
html_extra_path = ['robots.txt']
将站点地图或站点地图索引提交到相应的搜索引擎工具。
查看谁在使用它
您可以使用GitHub search或libraries.io查看谁在使用sphinx站点地图。
贡献
拉请求欢迎!请参阅CONTRIBUTING以获取有关如何做出最佳贡献的说明。
维护pypi版本
这些步骤将由维护人员运行,用于生成新的python包版本。
在sphinx_sitemap/version.py和setup.py中修订版本。
更新changelog.md
创建标记并推送到github:
git tag -a vX.Y.Z -m "Release vX.Y.Z" git push --tags origin master
在本地创建最新发行版:
python setup.py sdist
上传到test pypi.org存储库:
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
上传到production pypi.org存储库:
twine upload dist/*