find_page_with_path_absolute_or_relative_to

in _plugins/site_structure.rb [111:166]


    def find_page_with_path_absolute_or_relative_to(site, path, referrent, structure_processed_pages)
      uncleaned_path = path

      
      puts "converting #{path} wrt #{referrent ? referrent.path : ""}" if @@verbose
      file = Pathname.new(File.dirname(referrent ? referrent.path : "")) + path

      if file.to_s.end_with? "/"
        if File.exist? File.join(file, 'index.md')
          file += 'index.md'
        elsif File.exist? File.join(file, 'index.html')
          file += 'index.html'
        else
          file += 'index.md'
        end
      end

      file = file.cleanpath
      
      file = file.relative_path_from(Pathname.new("/")) unless file.relative?
      path = "#{file}"

      
      page = structure_processed_pages[path]
      return page if page != nil

      
      page = site.pages.detect { |page| page.path == path }
      if !page
        page = site.pages.detect { |page| '/'+page.path == uncleaned_path }
        puts "WARNING: link to #{path} in #{referrent ? referrent.path : "root"} uses legacy absolute syntax without leading slash" if page
      end

      unless page
        

        if file.exist?
          puts "INFO: reading excluded file #{file} for site structure generation" if SiteStructure::DEBUG
          page = Jekyll::Page.new(site, site.source, File.dirname(file), File.basename(file))
          
          @rewrite.rewrite_paths(site, page)
        end

        unless page
          raise "No such file #{path} in site_structure call (from #{referrent ? referrent.path : ""})" unless SiteStructure::DEBUG
          puts "Could not find a page called: #{path} (referenced from #{referrent ? referrent.path : "root"}); skipping"
          return nil
        end
      end

      
      structure_processed_pages[path] = page

      page
    end