Generates Atom feeds from content.
Produces standard Atom XML feeds for syndication. Generates a main feed for all dated content and per-type feeds for specific content types.
Examples
contents = [%Sayfa.Content{title: "Hello", body: "<p>World</p>", date: ~D[2024-01-15], slug: "hello", meta: %{"url_prefix" => "articles"}}]
config = %{title: "My Site", base_url: "https://example.com", author: "Author"}
xml = Sayfa.Feed.generate(contents, config)
Summary
Functions
Generates a feed for the given filter and format.
Generates an Atom XML feed for a specific category.
Generates an Atom XML feed for a specific tag.
Generates an Atom XML feed for a specific content type.
Generates a JSON Feed 1.1 string for all dated content.
Generates a JSON Feed 1.1 string for a specific category.
Generates a JSON Feed 1.1 string for a specific tag.
Generates a JSON Feed 1.1 string for a specific content type.
Types
Functions
@spec generate([Sayfa.Content.t()], map(), filter(), format()) :: String.t()
Generates a feed for the given filter and format.
This is the core function that powers all feed generation. The convenience wrappers below delegate to it.
Examples
iex> contents = [%Sayfa.Content{title: "Hello", body: "<p>World</p>", date: ~D[2024-01-15], slug: "hello", meta: %{"url_prefix" => "articles"}}]
iex> config = %{title: "My Site", base_url: "https://example.com", author: "Author"}
iex> xml = Sayfa.Feed.generate(contents, config)
iex> xml =~ "<feed"
true
iex> contents = [%Sayfa.Content{title: "Hello", body: "<p>World</p>", date: ~D[2024-01-15], slug: "hello", meta: %{"url_prefix" => "articles"}}]
iex> config = %{title: "My Site", base_url: "https://example.com", author: "Author"}
iex> xml = Sayfa.Feed.generate(contents, config, :all, :atom)
iex> xml =~ "<feed"
true
@spec generate_for_category([Sayfa.Content.t()], String.t(), map()) :: String.t()
Generates an Atom XML feed for a specific category.
Examples
iex> contents = [%Sayfa.Content{title: "Categorized", body: "<p>A</p>", date: ~D[2024-01-15], slug: "categorized", categories: ["news"], meta: %{"url_prefix" => "articles"}}]
iex> config = %{title: "My Site", base_url: "https://example.com", author: "Author"}
iex> xml = Sayfa.Feed.generate_for_category(contents, "news", config)
iex> xml =~ "Categorized"
true
@spec generate_for_tag([Sayfa.Content.t()], String.t(), map()) :: String.t()
Generates an Atom XML feed for a specific tag.
Examples
iex> contents = [%Sayfa.Content{title: "Tagged", body: "<p>A</p>", date: ~D[2024-01-15], slug: "tagged", tags: ["elixir"], meta: %{"url_prefix" => "articles"}}]
iex> config = %{title: "My Site", base_url: "https://example.com", author: "Author"}
iex> xml = Sayfa.Feed.generate_for_tag(contents, "elixir", config)
iex> xml =~ "Tagged"
true
@spec generate_for_type([Sayfa.Content.t()], String.t(), map()) :: String.t()
Generates an Atom XML feed for a specific content type.
Examples
iex> contents = [
...> %Sayfa.Content{title: "Article", body: "<p>A</p>", date: ~D[2024-01-15], slug: "Article", meta: %{"content_type" => "articles", "url_prefix" => "articles"}},
...> %Sayfa.Content{title: "Note", body: "<p>B</p>", date: ~D[2024-01-10], slug: "note", meta: %{"content_type" => "notes", "url_prefix" => "notes"}}
...> ]
iex> config = %{title: "My Site", base_url: "https://example.com", author: "Author"}
iex> xml = Sayfa.Feed.generate_for_type(contents, "articles", config)
iex> xml =~ "Article"
true
iex> xml =~ "Note"
false
@spec generate_json([Sayfa.Content.t()], map()) :: String.t()
Generates a JSON Feed 1.1 string for all dated content.
Examples
iex> contents = [%Sayfa.Content{title: "Hello", body: "<p>World</p>", date: ~D[2024-01-15], slug: "hello", meta: %{"url_prefix" => "articles"}}]
iex> config = %{title: "My Site", base_url: "https://example.com", author: "Author"}
iex> json = Sayfa.Feed.generate_json(contents, config)
iex> json =~ "jsonfeed.org"
true
@spec generate_json_for_category([Sayfa.Content.t()], String.t(), map()) :: String.t()
Generates a JSON Feed 1.1 string for a specific category.
Examples
iex> contents = [%Sayfa.Content{title: "Categorized", body: "<p>A</p>", date: ~D[2024-01-15], slug: "categorized", categories: ["news"], meta: %{"url_prefix" => "articles"}}]
iex> config = %{title: "My Site", base_url: "https://example.com", author: "Author"}
iex> json = Sayfa.Feed.generate_json_for_category(contents, "news", config)
iex> json =~ "Categorized"
true
@spec generate_json_for_tag([Sayfa.Content.t()], String.t(), map()) :: String.t()
Generates a JSON Feed 1.1 string for a specific tag.
Examples
iex> contents = [%Sayfa.Content{title: "Tagged", body: "<p>A</p>", date: ~D[2024-01-15], slug: "tagged", tags: ["elixir"], meta: %{"url_prefix" => "articles"}}]
iex> config = %{title: "My Site", base_url: "https://example.com", author: "Author"}
iex> json = Sayfa.Feed.generate_json_for_tag(contents, "elixir", config)
iex> json =~ "Tagged"
true
@spec generate_json_for_type([Sayfa.Content.t()], String.t(), map()) :: String.t()
Generates a JSON Feed 1.1 string for a specific content type.
Examples
iex> contents = [
...> %Sayfa.Content{title: "Article", body: "<p>A</p>", date: ~D[2024-01-15], slug: "Article", meta: %{"content_type" => "articles", "url_prefix" => "articles"}},
...> %Sayfa.Content{title: "Note", body: "<p>B</p>", date: ~D[2024-01-10], slug: "note", meta: %{"content_type" => "notes", "url_prefix" => "notes"}}
...> ]
iex> config = %{title: "My Site", base_url: "https://example.com", author: "Author"}
iex> json = Sayfa.Feed.generate_json_for_type(contents, "articles", config)
iex> json =~ "Article"
true
iex> json =~ "Note"
false