Class: Jekyll::ActivityPub::OrderedCollection
- Inherits:
-
Page
- Object
- Page
- Jekyll::ActivityPub::OrderedCollection
- Includes:
- Helper
- Defined in:
- lib/jekyll/activity_pub/ordered_collection.rb
Overview
An ordered collection of activities
Instance Method Summary collapse
-
#initialize(site, base = '', dir = '', name = 'ordered_collection.jsonld') ⇒ OrderedCollection
constructor
Initialize with default data.
-
#items_to_links! ⇒ nil
Turn items to URLs.
-
#order_items! ⇒ nil
Sort items.
-
#paginate! ⇒ nil
Paginates the collection if it has too many activities.
- #read_yaml ⇒ Object
Methods included from Helper
#content, #generate_excerpt?, #hook_owner, #locale, #place_in_layout?, #pruned_data, #render_with_liquid?, #to_json, #to_liquid, #trigger_hooks
Constructor Details
#initialize(site, base = '', dir = '', name = 'ordered_collection.jsonld') ⇒ OrderedCollection
Initialize with default data
19 20 21 22 23 24 25 |
# File 'lib/jekyll/activity_pub/ordered_collection.rb', line 19 def initialize(site, base = '', dir = '', name = 'ordered_collection.jsonld') @context = StubContext.new(registers: { site: site }) super trigger_hooks :post_init end |
Instance Method Details
#items_to_links! ⇒ nil
Turn items to URLs
51 52 53 54 55 56 57 |
# File 'lib/jekyll/activity_pub/ordered_collection.rb', line 51 def items_to_links! data['orderedItems'] = data['orderedItems'].map do |item| item.data['id'] end nil end |
#order_items! ⇒ nil
Sort items
40 41 42 43 44 45 46 |
# File 'lib/jekyll/activity_pub/ordered_collection.rb', line 40 def order_items! data['orderedItems'].sort! do |a, b| b.data['published'] <=> a.data['published'] end nil end |
#paginate! ⇒ nil
Paginates the collection if it has too many activities
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/jekyll/activity_pub/ordered_collection.rb', line 62 def paginate! return if always_paginate? || paginable? return if data['orderedItems'].empty? paged_data = data.dup pages = paginate(paged_data.delete('orderedItems')) assign_links! pages paged_data['first'] = absolute_url(pages.first.url) paged_data['last'] = absolute_url(pages.last.url) nil end |
#read_yaml ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/jekyll/activity_pub/ordered_collection.rb', line 27 def read_yaml(*) self.data = { '@context' => 'https://www.w3.org/ns/activitystreams', 'id' => absolute_url(url), 'type' => 'OrderedCollection', 'totalItems' => 0, 'orderedItems' => [] } end |