代码之家  ›  专栏  ›  技术社区  ›  thebjorn

如何链接到README.rst中docs文件夹中的图像?

  •  1
  • thebjorn  · 技术社区  · 7 年前

    我正在努力寻找一种方法来使用README.rst中同时出现在github和PyPI上的图像。

    .. image:: https://github.com/thebjorn/pydeps/blob/master/docs/_static/pydeps.svg
    

    在github上看起来不错( https://github.com/thebjorn/pydeps ),但在PyPI上显示为断开的链接( https://pypi.org/project/pydeps/1.6.0/ ).

    1 回复  |  直到 7 年前
        1
  •  4
  •   hoefling    7 年前

    你需要使用 raw.githubusercontent.com 而不是 github.com :

    .. image:: https://github.com/thebjorn/pydeps/blob/master/docs/_static/pydeps-pylib.svg
    

    将仅在Github本身上正确呈现,而

    .. image:: https://raw.githubusercontent.com/thebjorn/pydeps/master/docs/_static/pydeps-pylib.svg?sanitize=true
    


    首次尝试(已断开并删除)


    第二次尝试:

    1. 正确替换URL(同时删除 blob 分道扬镳-我的错,
    2. 附加物 ?sanitize=true 每个被替换的URL。

    $ sed -i '' 's,.. image:: https://github.com/\(.*\)/blob/\(.*\).svg,.. image:: https://raw.githubusercontent.com/\1/\2.svg?sanitize=true,g' README.rst
    

    on Github on TestPyPI ,都很好看。


    备选方案:使用 RawGit

    另一种可能是 罗吉特

    $ sed -i '' 's,.. image:: https://github.com/\(.*\)/blob/\(.*\)$,.. image:: https://cdn.rawgit.com/\1/\2,g' README.rst
    
    推荐文章