Current section

Files

Jump to
html_to_markdown lib html_to_markdown document_metadata.ex
Raw

lib/html_to_markdown/document_metadata.ex

# This file is auto-generated by alef — DO NOT EDIT.
# alef:hash:430ef19cdc26a55b0159e1184f51c34147623cbcbb638e254629267528dd6c7f
# To regenerate: alef generate
# To verify freshness: alef verify --exit-code
defmodule HtmlToMarkdown.DocumentMetadata do
@moduledoc """
Document-level metadata extracted from `<head>` and top-level elements.
Contains all metadata typically used by search engines, social media platforms,
and browsers for document indexing and presentation.
# Examples
```
let doc = DocumentMetadata {
title: Some("My Article".to_string()),
description: Some("A great article about Rust".to_string()),
keywords: vec!["rust".to_string(), "programming".to_string()],
..Default::default()
};
assert_eq!(doc.title, Some("My Article".to_string()));
```
"""
@typedoc "Document-level metadata extracted from `<head>` and top-level elements."
@type t :: %__MODULE__{
title: String.t() | nil,
description: String.t() | nil,
keywords: [String.t()],
author: String.t() | nil,
canonical_url: String.t() | nil,
base_href: String.t() | nil,
language: String.t() | nil,
text_direction: String.t() | nil | nil,
open_graph: map(),
twitter_card: map(),
meta_tags: map()
}
defstruct title: nil,
description: nil,
keywords: [],
author: nil,
canonical_url: nil,
base_href: nil,
language: nil,
text_direction: nil,
open_graph: %{},
twitter_card: %{},
meta_tags: %{}
defimpl Jason.Encoder do
@doc false
def encode(value, opts) do
value
|> Map.from_struct()
|> Enum.reject(fn {_k, v} -> v == nil end)
|> Enum.into(%{})
|> Jason.Encoder.encode(opts)
end
end
end