generate_index.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:docs 作者: hasura 项目源码 文件源码
def onFinishBuilding(app, exception):
    currentVersion = app.env.config["version"]
    if "latest_docs_version" in app.env.config["html_context"].keys():
        latestVersion = app.env.config["html_context"]["latest_docs_version"]
    else:
        latestVersion = "dev"
    base_domain = app.env.config["html_context"]["SITEMAP_DOMAIN"]

    file_path = "./_build/algolia_index/index.json"
    sitemap_path = "./_build/sitemap/sitemap_" + currentVersion + ".xml"

    checkDirectory(file_path)
    checkDirectory(sitemap_path)

    f = open(file_path, 'w+')

    root = ET.Element("urlset")
    root.set("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9")

    for link in indexObjs:
        url = ET.SubElement(root, "url")
        ET.SubElement(url, "loc").text = base_domain + str(currentVersion) + "/" + link["url"]
        ET.SubElement(url, "changefreq").text = "daily"
        ET.SubElement(url, "priority").text = "1" if ( currentVersion == latestVersion ) else "0.5"

    ET.ElementTree(root).write(sitemap_path)

    f.write(json.dumps(indexObjs))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号