【问题标题】:How can I know the markdown file name of the post in Octopress?如何知道 Octopress 中帖子的降价文件名?
【发布时间】:2014-03-04 03:28:06
【问题描述】:

除此之外,我试图显示一个编辑图标,单击该图标以调用带有博客标题的自定义协议。

例如,当2014-01-19-python-iteration-with-range.markdown是octopress博客的markdown时,点击侧边栏编辑图标open://Users /doc/prg/source/_post/2014-01-19-python-iteration-with-range.markdown 被调用。

我修改了 _config.yml 有这行:

post_asides: [
    asides/edit.html
]

我也把edit.html如下放到了asides目录下。

<section class="googleplus{% if site.googleplus_hidden %} googleplus-hidden{% endif %}">
  <h1>
    <a href="open:///Users/doc/prg/source/_posts/{{ ??? }}">
      <img src="/images/self_edit.png" width="32" height="32">
      Edit
    </a>
  </h1>
</section>

按照this site 中的提示,我尝试了page.path,但没有任何显示。

应该填什么变量???获取帖子的文件名? 或者我怎么知道八字帖的markdown文件名?

我想过用 {{ page.id }} 并用 - 替换 / 加上一些字符串更改可以得到markdown的文件路径,但我不知道如何翻译名称。

【问题讨论】:

    标签: blogs jekyll octopress


    【解决方案1】:

    我得到了this site的答复。

    当 page.path 不可用时,将以下代码复制到插件目录中的任何 rb 文件中。

     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
    

    而且我的链接是正确的。

    【讨论】:

    • 这不适用于 Jekyll 3.0 及更高版本...有什么想法吗?
    猜你喜欢
    • 2017-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-28
    相关资源
    最近更新 更多