GitHub Pages - How to prevent conversion of file names to *.html in links

梦想与她 提交于 2020-01-03 00:38:53

问题


I am using GitHub Pages to create a static web site. It does a great job processing links such that file1.md becomes file1.html in the rendered output:

For example:

[Link text](https://github.com/some-repo/some-file.md)

in the Markdown source becomes this when rendered using GitHub Pages:

<a href="https://github.com/some-repo/some-file.html">Link text</a>

Can I override this conversion somehow and link to an actual md file? In other words, output that looks like this:

<a href="http://https://github.com/some-repo/some-file.md">Link text</a>

Thanks for any insight you can lend!

I have tried embedding the HTML <a> element in the source, but the conversion still happens.


回答1:


You can get the path to a particular page (.md file) using the page.path variable.

That path is relative to the branch directory in your repo.

So you can link to the .md source file using this URL:

https://github.com/YourUsername/YourRepo/blob/your-branch/{{ page.path }}

For my purposes, I use this URL:

https://github.com/KevinWorkman/HappyCoding/blob/gh-pages/{{ page.path }}

If you already know the path, then you can use that directly instead of using the page.path variable:

https://github.com/YourUsername/YourRepo/blob/your-branch/some/path/some-file.md


来源:https://stackoverflow.com/questions/57367689/github-pages-how-to-prevent-conversion-of-file-names-to-html-in-links

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!