Class: Jekyll::ActivityPub::Activity

Inherits:
Page
  • Object
show all
Includes:
Helper
Defined in:
lib/jekyll/activity_pub/activity.rb

Overview

Represents a post on ActivityPub

Constant Summary collapse

WHITE_SPACE =

HTML white space removal

/>\s+</.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

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, actor, doc, base = '', dir = '', name = 'index.jsonld') ⇒ Activity

Initialize with default data

Parameters:



31
32
33
34
35
36
37
38
39
# File 'lib/jekyll/activity_pub/activity.rb', line 31

def initialize(site, actor, doc, base = '', dir = '', name = 'index.jsonld')
  @doc = doc
  @context = StubContext.new(registers: { site: site })
  @actor = actor

  super(site, base, dir, name)

  trigger_hooks :post_init
end

Instance Attribute Details

#actorObject (readonly)

Parameters:



21
22
23
# File 'lib/jekyll/activity_pub/activity.rb', line 21

def actor
  @actor
end

#docObject (readonly)

Parameters:

  • :doc (Jekyll::Document)


18
19
20
# File 'lib/jekyll/activity_pub/activity.rb', line 18

def doc
  @doc
end

Instance Method Details

#read_yamlnil

Returns:

  • (nil)


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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/jekyll/activity_pub/activity.rb', line 42

def read_yaml(*)
  doc_content = doc.content.tr("\n", '').gsub(WHITE_SPACE, '><')

  id = absolute_url(url)

  self.data = {
    '@context' => [
      'https://www.w3.org/ns/activitystreams',
      {
        '@language' => locale,
        'sensitive' => 'as:sensitive'
      }
    ],
    'type' => 'Note',
    'id' => id,
    'url' => absolute_url(doc.url),
    'summary' => summary,
    'published' => (doc.data['created_at'] || doc.date).xmlschema,
    'updated' => doc.data['last_modified_at']&.xmlschema,
    'attributedTo' => absolute_url(actor.url),
    'to' => [
      'https://www.w3.org/ns/activitystreams#Public'
    ],
    'cc' => [Notifier.followers_url],
    'inReplyTo' => doc.data['in_reply_to'],
    'sensitive' => sensitive?,
    'content' => doc_content,
    'name' => doc.data['title'],
    'contentMap' => {
      locale => doc_content
    },
    'attachment' => attachments,
    'tag' => [],
    'replies' => Notifier.client.absolute_url(Notifier.replies(id).endpoint),
    'shares' => Notifier.client.absolute_url(Notifier.shares(id).endpoint),
    'likes' => Notifier.client.absolute_url(Notifier.likes(id).endpoint)
  }

  nil
end