我的目标是创建从任何已发布的jekyll页面返回其在Github上的位置的链接.
因此,在构建此URL时,我需要访问页面的路径名.但是,我没有在api中看到提供此信息的模板的任何内容.我查看了页面的源代码,但是当通过模板访问时,没有文件/路径属性具有值.
cbo*_*tig 31
更新:现在你可以使用{{page.path}}
.
看起来您可以使用液体代码构建您的链接: {{ page.url }}
例如,如果您想要此页面:http://railsdocs.org/pages/get-involved.html链接到此页面:https://github.com/dogweather/railsdocs.org/blob/gh-pages/页/ get-involved.md
好像你可以添加类似的东西:
[source](https://github.com/dogweather/railsdocs.org/blob/gh-pages/{{page.url | replace:'.html','.md'}})
Run Code Online (Sandbox Code Playgroud)
降价并获得您想要的链接.
或者,我们可以编写一个允许页面直接访问其文件名的生成器.将其添加到目录中的.rb
文件_plugins
:
module Jekyll
class PagePathGenerator < Generator
safe true
## See post.dir and post.base for directory information.
def generate(site)
site.posts.each do |post|
post.data['path'] = post.name
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
然后我们可以可靠地获得帖子的文件名{{ page.path }}
.此解决方案比从URL转换更强大,因为页面名称可以包含在将其转换为URL时"清理"的字符.(帖子还需要添加日期信息等).相反,这个插件让我们可以直接访问帖子的名称.
如果还需要数据,类似的策略可以让我们获得帖子的路径.
mik*_*ing 15
我不确定这是什么时候添加的,但是page.path
给出了源文件相对于Jekyll根目录的路径.
归档时间: |
|
查看次数: |
7275 次 |
最近记录: |