Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/docs/filters/laravel/clean_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Docs
class Laravel
class CleanHtmlFilter < Filter
def call
if subpath.start_with?('/api')
if base_url.origin.start_with?('https://api.laravel.com')
api
else
other
Expand Down
50 changes: 45 additions & 5 deletions lib/docs/filters/laravel/entries.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
module Docs
class EntryIndex
def types_as_json
@types.values
.sort_by { |type| natural_sort_key(type.name) }
.map(&:as_json)
end

def natural_sort_key(name)
name.downcase.scan(/\d+|\D+/).map do |part|
part.match?(/\A\d+\z/) ? [0, part.to_i] : [1, part]
end
end
end

class Laravel
class EntriesFilter < Docs::EntriesFilter
def get_name
Expand All @@ -12,10 +26,28 @@ def get_name
end

def get_type
unless api_page?
link = at_css(".docs_sidebar li a[href='#{result[:path].split('/').last}']")
heading = link.ancestors('li').last.at_css('> h2')
return heading ? "Guides: #{heading.content.strip}" : 'Guides'
if docs_page? and (version.to_i > 5 or is_version_5)
guide_sections = css(".docs_sidebar > ul > li")
active_link = guide_sections.at_css("li.active a")

active_section = active_link.ancestors('li.sub--on')
index = guide_sections.index(active_section.first)

heading = active_section.at_css('> h2')

return heading ? "Guides: #{index} - #{heading.content.strip}" : 'Guides'
end

if docs_page? and (version === "4.2")
guide_sections = css(".docs_sidebar > ul > li")
active_link = guide_sections.at_css("ul > li > a[href$='#{result[:path]}']")

active_section = active_link.ancestors('li')
index = guide_sections.index(active_section.last)

heading = active_section.at_css('> h2')

return heading ? "Guides: #{index} - #{heading.content.strip}" : 'Guides'
end

type = slug.remove(%r{api/[1-9]?\d.[0-9x]/}).remove('Illuminate/').remove(/\/\w+?\z/).gsub('/', '\\')
Expand Down Expand Up @@ -47,12 +79,20 @@ def additional_entries
end

def api_page?
subpath.start_with?('/api')
current_url.origin.start_with?('https://api.laravel.com')
end

def docs_page?
current_url.origin.start_with?('https://laravel.com')
end

def include_default_entry?
!subpath.end_with?('classes.html')
end

def is_version_5
["5.0", "5.1", "5.2", "5.3", "5.4", "5.5", "5.6", "5.7", "5.8"].include? version
end
end
end
end
Loading
Loading