【问题标题】:How to use build_date_utc for copyright year in mkdocs.yml如何在 mkdocs.yml 中使用 build_date_utc 作为版权年份
【发布时间】:2021-06-15 09:07:29
【问题描述】:

在我的项目中,我想在 mkdocs 配置文件 mkdocs.yml 中使用当前年份作为版权信息。根据mkdocs documentation,有build_date_utc。有人可以举例说明如何使用它吗?我试过了

copyright: "&copy; 2017 - {{ build_date_utc.year }} <a href='https://example.org' target='_blank'>Example</a>"

但该参数在 HTML 中无法正确呈现。

更新:我发现它可以与 JavaScript 脚本一起使用,如下所示:

copyright: "&copy; 2017 - <script>document.write(new Date().getFullYear())</script> <a href='https://example.org' target='_blank'>Example</a>"

但我仍然对如何使用 build_date_utc 进行操作感兴趣。

【问题讨论】:

    标签: mkdocs


    【解决方案1】:

    根据您链接到build_date_utc 的 MkDoc 文档是:

    一个 Python 日期时间对象,表示文档在 UTC 中构建的日期和时间。

    由于它是一个 Python 日期时间对象,您可以像任何其他 Python 日期时间对象一样format it with strftime

    这对我有用,使用 mkdocs 1.2.1 和 jinja2 3.0.1:

    {% block footer %}
     &copy; {{ build_date_utc.strftime('%Y') }} 
     <a href='https://example.org' target='_blank'>Example</a>
    {% endblock %}
    

    【讨论】:

      猜你喜欢
      • 2018-06-18
      • 1970-01-01
      • 2016-03-23
      • 2021-05-05
      • 2012-10-12
      • 1970-01-01
      • 2022-12-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多