Get the full filename of the post in convecter of Jekyll


#1

I am using markdown extension in jekyll using convecter. For example:

module Jekyll
  class MyConverter < Converter
    safe false
    priority :high

    def matches(ext)
      ext =~ /^.(md|markdown)$/i
    end

    def output_ext(ext)
      ".html"
    end

    def my_process (content)
      # something
    end

    def convert(content)
      # Here my markdown processing
      # content = my_process(content)

      # Here I want to use the path to the markdown file
      # puts (filename)

      site = Jekyll::Site.new(@config)
      converter = site.find_converter_instance(Jekyll::Converters::Markdown)
      converter.convert(content)
    end
  end
end

Is it possible to get the full name of the file or its location for which markdown text is converted to html?

For example, I have a markdown file:

Bla bla bla.

[Text of the link](gallery)

Bla bla bla

And I want a list of the files in directory gallery . How to get a list of files from a specific directory I know, but in the convecter I need to know the full path to this markdown file. Is there any way to do that?


#2

Use Jekyll::Hooks:

module Jekyll
  class MyHookProcess
    class << self
      def my_process(content)
        # something
        content
      end
    end
  end
end

Jekyll::Hooks.register([:posts], :pre_render) do |post|
  #puts ("post.date = " + post.date)
  #puts ("post.path = " + post.path)
  #puts ("post.url = " + post.url)
  post.content = Jekyll::MyHookProcess.my_process(post.content)
end