From 5a7ea1dd2ff4a01b514d9f6e9b25d203f264b60c Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 11 Sep 2024 09:50:03 +0200 Subject: [PATCH] Change some inline term definitions to new JSON-LD context --- app/helpers/context_helper.rb | 1 + app/serializers/activitypub/actor_serializer.rb | 6 +++--- .../activitypub/hashtag_serializer.rb | 2 +- app/serializers/activitypub/note_serializer.rb | 6 ++++-- config/initializers/json_ld_miscellany.rb | 16 ++++++++++++++++ 5 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 config/initializers/json_ld_miscellany.rb diff --git a/app/helpers/context_helper.rb b/app/helpers/context_helper.rb index a0c1781d2..229227df4 100644 --- a/app/helpers/context_helper.rb +++ b/app/helpers/context_helper.rb @@ -4,6 +4,7 @@ module ContextHelper NAMED_CONTEXT_MAP = { activitystreams: 'https://www.w3.org/ns/activitystreams', security: 'https://w3id.org/security/v1', + miscellany: 'https://purl.archive.org/socialweb/miscellany', }.freeze CONTEXT_EXTENSION_MAP = { diff --git a/app/serializers/activitypub/actor_serializer.rb b/app/serializers/activitypub/actor_serializer.rb index a6281e23b..a4990a473 100644 --- a/app/serializers/activitypub/actor_serializer.rb +++ b/app/serializers/activitypub/actor_serializer.rb @@ -4,10 +4,10 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer include RoutingHelper include FormattingHelper - context :security + context :security, :miscellany - context_extensions :manually_approves_followers, :featured, :also_known_as, - :moved_to, :property_value, :discoverable, :olm, :suspended, + context_extensions :featured, :also_known_as, + :property_value, :discoverable, :olm, :suspended, :memorial, :indexable, :attribution_domains attributes :id, :type, :following, :followers, diff --git a/app/serializers/activitypub/hashtag_serializer.rb b/app/serializers/activitypub/hashtag_serializer.rb index 2b24eb8cc..5dbd0fc45 100644 --- a/app/serializers/activitypub/hashtag_serializer.rb +++ b/app/serializers/activitypub/hashtag_serializer.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class ActivityPub::HashtagSerializer < ActivityPub::Serializer - context_extensions :hashtag + context :miscellany include RoutingHelper diff --git a/app/serializers/activitypub/note_serializer.rb b/app/serializers/activitypub/note_serializer.rb index 27e058199..a27562ade 100644 --- a/app/serializers/activitypub/note_serializer.rb +++ b/app/serializers/activitypub/note_serializer.rb @@ -3,7 +3,9 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer include FormattingHelper - context_extensions :atom_uri, :conversation, :sensitive, :voters_count + context :miscellany + + context_extensions :atom_uri, :conversation, :voters_count attributes :id, :type, :summary, :in_reply_to, :published, :url, @@ -254,7 +256,7 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer end class TagSerializer < ActivityPub::Serializer - context_extensions :hashtag + context :miscellany include RoutingHelper diff --git a/config/initializers/json_ld_miscellany.rb b/config/initializers/json_ld_miscellany.rb new file mode 100644 index 000000000..3ff18ccf7 --- /dev/null +++ b/config/initializers/json_ld_miscellany.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true +# This file generated automatically from https://purl.archive.org/socialweb/miscellany +require 'json/ld' +class JSON::LD::Context + add_preloaded("http://purl.archive.org/socialweb/miscellany") do + new(processingMode: "json-ld-1.1", term_definitions: { + "Hashtag" => TermDefinition.new("Hashtag", id: "https://www.w3.org/ns/activitystreams#Hashtag", simple: true), + "as" => TermDefinition.new("as", id: "https://www.w3.org/ns/activitystreams#", simple: true, prefix: true), + "manuallyApprovesFollowers" => TermDefinition.new("manuallyApprovesFollowers", id: "https://www.w3.org/ns/activitystreams#manuallyApprovesFollowers", type_mapping: "http://www.w3.org/2001/XMLSchema#boolean"), + "movedTo" => TermDefinition.new("movedTo", id: "https://www.w3.org/ns/activitystreams#movedTo", type_mapping: "@id"), + "sensitive" => TermDefinition.new("sensitive", id: "https://www.w3.org/ns/activitystreams#sensitive", type_mapping: "http://www.w3.org/2001/XMLSchema#boolean"), + "xsd" => TermDefinition.new("xsd", id: "http://www.w3.org/2001/XMLSchema#", simple: true, prefix: true) + }) + end + alias_preloaded("https://purl.archive.org/socialweb/miscellany", "http://purl.archive.org/socialweb/miscellany") +end