IndieWeb.Post (IndieWeb v0.0.49) View Source

Post-specific logic for the IndieWeb.

This module provides helper methods for parsing MF2 data in a handy and simple fashion. The structure of the properties you'd use would be similar to that of a <abbr tittle="Micformats2 JSON">MF2+JSON</abbr> object:

{
  "items": [
      {
          "type": [
              "h-feed"
          ],
          "properties": {
              "name": [
                  "Updates"
              ],
              "uid": [
                  "https://v2.jacky.wtf/stream"
              ],
              "url": [
                  "https://v2.jacky.wtf/stream"
              ]
          },
          "lang": "en",
          "children": [
              {
                  "type": [
                      "h-entry"
                  ],
                  "properties": {
                      "summary": [
                          "One big step for Koype is going to be bridging the IndieWeb into the IPFS landscape. I have concerns over it not being privacy-centric since there’s no sense of private data (everything is publishable outwards). IPFS provides pubsub logic so I thi..."
                      ],
                      "url": [
                          "https://v2.jacky.wtf/post/4fbdcd28-b558-42bc-99a9-802e33d01810",
                          "https://v2.jacky.wtf/tag/7c1e5ef9-aa31-40e6-b26a-ecdba728b4a1",
                          "https://v2.jacky.wtf/tag/bc945dde-95bb-468e-9127-620f1c35cd70"
                      ],
                      "uid": [
                          "https://v2.jacky.wtf/post/4fbdcd28-b558-42bc-99a9-802e33d01810"
                      ],
                      "category": [
                          "https://v2.jacky.wtf/tag/7c1e5ef9-aa31-40e6-b26a-ecdba728b4a1",
                          "https://v2.jacky.wtf/tag/bc945dde-95bb-468e-9127-620f1c35cd70"
                      ],
                      "published": [
                          "2019-02-15T13:29:51.60956-08:00"
                      ]
                  },
                  "lang": "en"
              }
          ]
      },
      {
          "type": [
              "h-card"
          ],
          "properties": {
              "name": [
                  "Jacky Alcine"
              ],
              "tz": [
                  "America/Los_Angeles"
              ],
              "note": [
                  "I had a dream I could buy my way into heaven. When I woke up, I spent that on a m4.large from EvilCorp. Wait until I get my money right!"
              ],
              "url": [
                  "https://v2.jacky.wtf"
              ],
              "photo": [
                  "https://v2.jacky.wtf/media/image/floating/PhotoJacky%20n%203J5430.png?v=original"
              ]
          },
          "lang": "en"
      }
  ]
}

Link to this section Summary

Functions

Determines the type of a post from a set of types and its MF2 properties.

Determines the potential types exposed by the set of provided properties.

Determines if the provided type is a response type.

Returns a list of atoms representing response post types.

Link to this section Functions

Link to this function

determine_type(properties, types)

View Source (since http://ptd.spec.indieweb.org/#changes-from-28-october-2016-wd-to-1-march-2017-wd)

Specs

determine_type(map(), list()) :: atom()

Determines the type of a post from a set of types and its MF2 properties.

This aims to apply the Post Type Discovery algorithm for discovering what kind of post these properties result in.

Extra Types

  • listen posts can be detected with listen-of.
  • workout posts can be detected with workout.

Examples

iex> IndieWeb.Post.determine_type(%{"content" => ["Foo."], "name" => ["Foo."]}, ~w(note article)a)
:note

iex> IndieWeb.Post.determine_type(%{"content" => %{"value" => ["Foo."]}, "name" => ["On Bar"]}, ~w(note article)a)
:article

iex> IndieWeb.Post.determine_type(%{"content" => %{"value" => ["Foo."]}, "photo" => ["https://magic/jpeg"]}, ~w(note photo)a)
:photo
Link to this function

extract_from_reply_value(values)

View Source
Link to this function

extract_types(properties)

View Source

Specs

extract_types(map()) :: list()

Determines the potential types exposed by the set of provided properties.

The provided properties are scanned and checked to determine if a particular post type can be determined. The matching is a direct property to type mapping. You should use determine_type/2 to resolve the actual post type.

Examples

iex> IndieWeb.Post.extract_types(%{"photo" => ["https://magic/jpeg"]})
[:photo]

iex> IndieWeb.Post.extract_types(%{"content" => %{"value" => ["Just a note."]}})
[:note]

iex> IndieWeb.Post.extract_types(%{"content" => %{"value" => ["A whole blog post."]}, "name" => ["Magic."]})
[:article]

iex> IndieWeb.Post.extract_types(%{"properties" => %{"content" => %{"value" => ["A whole blog post."]}, "name" => ["Magic."]}})
[:article]
Link to this function

extract_uris(type, properties)

View Source
Link to this function

get_response_property_names_to_types()

View Source

Specs

get_response_property_names_to_types() :: map()

Specs

is_response_type?(atom()) :: boolean()

Determines if the provided type is a response type.

Examples

iex> IndieWeb.Post.is_response_type?(:note)
false

iex> IndieWeb.Post.is_response_type?(:rsvp)
true

Specs

response_types() :: [atom()]

Returns a list of atoms representing response post types.