Class: Scribo::ContentFindService
- Inherits:
-
ApplicationService
- Object
- ApplicationService
- Scribo::ContentFindService
- Defined in:
- app/services/scribo/content_find_service.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#site ⇒ Object
readonly
Returns the value of attribute site.
Instance Method Summary collapse
-
#initialize(site, options = {}) ⇒ ContentFindService
constructor
A new instance of ContentFindService.
- #perform ⇒ Object
Methods inherited from ApplicationService
Constructor Details
#initialize(site, options = {}) ⇒ ContentFindService
Returns a new instance of ContentFindService.
9 10 11 12 13 |
# File 'app/services/scribo/content_find_service.rb', line 9 def initialize(site, = {}) super() @site = site @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'app/services/scribo/content_find_service.rb', line 7 def @options end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
7 8 9 |
# File 'app/services/scribo/content_find_service.rb', line 7 def site @site end |
Instance Method Details
#perform ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/services/scribo/content_find_service.rb', line 15 def perform return [:content] if [:content].is_a?(Scribo::Content) scope = site.contents if [:path] path = CGI.unescape([:path]) path = path[site.baseurl.length..-1] if path.start_with?(site.baseurl) # Deal with collections path_parts = path.split('/') first_path_part = path_parts[0] if site.collections.include?(first_path_part) path_parts[0] = '_' + path_parts[0] [:restricted] = false path = path_parts.join('/') end # End - Deal with collections scope = scope.located(path, restricted: [:restricted]) end # FIXME: Not to pretty content = if [:root] scope.roots.first else result = scope.where.not(kind: 'folder').first result = scope.where(kind: 'folder').first unless scope.present? result = Scribo::Content.new(kind: 'text', path: '/directory.link', full_path: '/directory.link', data: "#{[:path]}/") if result&.folder? result end # Find by content id content ||= Scribo::Content&.published&.find_by_id([:path][1..-1]) if [:path] && [:path][1..-1].length == 36 if [:path] == '/humans.txt' content ||= Scribo::Content.new(kind: 'text', path: '/humans.txt', full_path: '/humans.txt', data: Scribo.config.default_humans_txt) elsif [:path] == '/robots.txt' content ||= Scribo::Content.new(kind: 'text', path: '/robots.txt', full_path: '/robots.txt', data: Scribo.config.default_robots_txt) elsif [:path] == '/favicon.ico' content ||= Scribo::Content.new(kind: 'asset', path: '/favicon.ico', full_path: '/favicon.ico', data: Base64.decode64(Scribo.config.default_favicon_ico)) end # FIXME: Find a better way for this content ||= site&.contents&.located('/404')&.first content ||= site&.contents&.located('/404.html')&.first content ||= site&.contents&.located('/404.md')&.first content end |