Skip to main content

使用 Jinja2 模板引擎生成 GitHub 配置文件 README 的 CLI 工具。

项目描述

个人资料自述文件

构建状态 文件状态

使用Jinja2模板引擎生成 GitHub 配置文件 README 的 CLI 工具。

它允许您使用Jinja2提供的所有功能来帮助您自定义 GitHub 配置文件 README,并将来自 GitHub API 的数据提供给您的模板。

阅读https://profile-readme.rtfd.io/上的文档。

安装

使用以下命令安装profile-readme

$ python3 -m pip install profile-readme

生活在边缘

如果您想在发布之前使用最新代码,请从master分支安装或更新代码:

$ python3 -m pip install -U git+https://github.com/Robert-96/profile-readme.git

快速开始

使用init命令生成带有示例模板的新项目:

$ profile-readme init

使用render命令更新您的README.md文件:

$ profile-readme render

高级用法

使用自定义构建脚本

命令行快捷方式很方便,但有时您的项目需要一些不同于默认设置的东西。要更改它们,您可以使用构建脚本。

一个最小的构建脚本看起来像这样:

from profile_readme import get_github_context, ProfileGenerator


context = {}

# If you don't need the GitHub data you can remove the next line
context.update(**get_github_context('octocat'))


if __name__ == "__main__":
    ProfileGenerator.render(
        template_path="README-TEMPLATE.md",
        output_path="README.md",
        context=context
    )

最后,只需将脚本另存为build.py(或类似的)并使用您的 Python 解释器运行它。

$ python build.py

注意:别忘了更新.github/workflows/readme.yml. 替换python3 -m profile_readme renderpython3 build.py

加载数据中

向模板提供数据的最简单方法是将ProfileGenerator.render变量名到它们的值(“上下文”)的映射作为context关键字参数传递。

from profile_readme import get_github_context, ProfileGenerator


context = {
    greeting='Hello, world!'
}

# If you don't need the GitHub data you can remove the next line
context.update(**get_github_context('octocat'))


if __name__ == "__main__":
    ProfileGenerator.render(
        template_path="README-TEMPLATE.md",
        output_path="README.md",
        context=context
    )

添加到此字典的任何内容都将在模板中可用:

# Title

{{ greeting }}

过滤器

变量可以通过过滤器进行修改。支持所有标准 Jinja2 过滤器(您可以在此处找到完整列表)。要添加您自己的过滤器,只需将过滤器作为参数传递给ProfileGenerator.

from profile_readme import get_github_context, ProfileGenerator


context = get_github_context('octocat')
filters = {
    'hello': lambda x: 'Hello, {}!',
}


if __name__ == "__main__":
    ProfileGenerator.render(
        template_path="README-TEMPLATE.md",
        output_path="README.md",
        context=context,
        filters=filters
    )

然后您可以按照您的预期在模板中使用它们:

{{ 'World'|hello }}

执照

这个项目是在MIT License下获得许可的。

下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

profile-readme-0.1.2.tar.gz (11.0 kB 查看哈希

已上传 source

内置分布

profile_readme-0.1.2-py3-none-any.whl (10.4 kB 图哈希)

已上传 py3