Library
Module
Module type
Parameter
Class
Class type
Syndic.Atom
: RFC 4287 compliant Atom parser.
module Error : module type of Syndic_error
The common signature that all error modules must (at least) satisfy.
type text_construct =
| Text of string
Text(content)
| Html of Uri.t option * string
Html(xmlbase, content)
where the content is left unparsed.
| Xhtml of Uri.t option * Syndic_xml.t list
Xhtml(xmlbase, content)
A text construct. It contains human-readable text, usually in small quantities. The content of Text constructs is Language-Sensitive.
Describes a person, corporation, or similar entity (hereafter, 'person') that indicates the author of the entry or feed. See RFC 4287 § 3.2. Person constructs allow extension Metadata elements (see Section 6.4).
They are used for authors (See RFC 4287 § 4.2.1) and contributors (See RFC 4287 § 4.2.3)
val author : ?uri:Uri.t -> ?email:string -> string -> author
The category
element conveys information about a category associated with an entry or feed. This specification assigns no meaning to the content (if any) of this element. See RFC 4287 § 4.2.2.
term
is a string that identifies the category to which the entry or feed belongs. See RFC 4287 § 4.2.2.2scheme
, if present, is an IRI that identifies a categorization scheme. See RFC 4287 § 4.2.2.3label
, if present, is a human-readable label for display in end-user applications. The content of the "label" attribute is Language-Sensitive. See RFC 4287 § 4.2.2.1val category : ?scheme:Uri.t -> ?label:string -> string -> category
The generator
element's content identifies the agent used to generate a feed, for debugging and other purposes.
content
is a human-readable name for the generating agent.uri
, if present, SHOULD produce a representation that is relevant to that agent.version
, if present, indicates the version of the generating agent.See RFC 4287 § 4.2.4.
val generator : ?uri:Uri.t -> ?version:string -> string -> generator
The icon
element's content is an IRI reference RFC3987
that identifies an image that provides iconic visual identification for a feed.
The image SHOULD have an aspect ratio of one (horizontal) to one (vertical) and SHOULD be suitable for presentation at a small size.
The id
element conveys a permanent, universally unique identifier for an entry or feed.
Its content MUST be an IRI, as defined by RFC3987
. Note that the definition of "IRI" excludes relative references. Though the IRI might use a dereferencable scheme, Atom Processors MUST NOT assume it can be dereferenced.
There is more information in the RFC but they are not necessary here, at least, they can not be checked here.
link
elements MAY have a "rel" attribute that indicates the link relation type. If the "rel" attribute is not present, the link element MUST be interpreted as if the link relation type is "alternate".
The value of "rel" MUST be a string that is non-empty and matches either the "isegment-nz-nc" or the "IRI" production in RFC3987
. Note that use of a relative reference other than a simple name is not allowed.
type link = {
href : Uri.t;
rel : rel;
type_media : string option;
hreflang : string option;
title : string option;
length : int option;
}
link
defines a reference from an entry or feed to a Web resource. This specification assigns no meaning to the content (if any) of this element. See RFC 4287 § 4.2.7
href
contains the link's IRI. The value MUST be a IRI reference RFC3987
. See RFC 4287 § 4.2.7.1.type_media
is an advisory media type: it is a hint about the type of the representation that is expected to be returned when the value of the href attribute is dereferenced. Note that the type attribute does not override the actual media type returned with the representation. Link elements MAY have a type attribute, whose value MUST conform to the syntax of a MIME media type MIMEREG
. See RFC 4287 § 4.2.7.3hreflang
describes the language of the resource pointed to by the href attribute. When used together with the rel="alternate", it implies a translated version of the entry. Link elements MAY have an hreflang attribute, whose value MUST be a language tag RFC3066
. See RFC 4287 § 4.2.7.4title
conveys human-readable information about the link. The content of the "title" attribute is Language-Sensitive. See RFC 4287 § 4.2.7.5.length
indicates an advisory length of the linked content in octets; it is a hint about the content length of the representation returned when the IRI in the href attribute is mapped to a URI and dereferenced. Note that the length attribute does not override the actual content length of the representation as reported by the underlying protocol. Link elements MAY have a length attribute. See RFC 4287 § 4.2.7.6.logo
is an IRI reference RFC3987
that identifies an image that provides visual identification for a feed.
The image SHOULD have an aspect ratio of 2 (horizontal) to 1 (vertical).
type published = Syndic_date.t
published
is a Date construct indicating an instant in time associated with an event early in the life cycle of the entry.
Typically, published
will be associated with the initial creation or first availability of the resource.
type rights = text_construct
rights
is a Text construct that conveys information about rights held in and over an entry or feed. The rights
element SHOULD NOT be used to convey machine-readable licensing information.
If an atom:entry element does not contain an atom:rights element, then the atom:rights element of the containing atom:feed element, if present, is considered to apply to the entry.
type title = text_construct
title
is a Text construct that conveys a human-readable title for an entry or feed. See RFC 4287 § 4.2.14
type subtitle = text_construct
subtitle
is a Text construct that conveys a human-readable description or subtitle for a feed. See RFC 4287 § 4.2.12
type updated = Syndic_date.t
updated
is a Date construct indicating the most recent instant in time when an entry or feed was modified in a way the publisher considers significant. Therefore, not all modifications necessarily result in a changed updated
value.
Publishers MAY change the value of this element over time.
type source = {
categories : category list;
contributors : author list;
generator : generator option;
icon : icon option;
id : id;
links : link list;
logo : logo option;
rights : rights option;
subtitle : subtitle option;
title : title;
updated : updated option;
}
If an entry
is copied from one feed into another feed, then the source feed
's metadata (all child elements of atom:feed other than the atom:entry elements) MAY be preserved within the copied entry by adding an atom:source child element, if it is not already present in the entry, and including some or all of the source feed's Metadata elements as the atom:source element's children. Such metadata SHOULD be preserved if the source atom:feed contains any of the child elements atom:author, atom:contributor, atom:rights, or atom:category and those child elements are not present in the source atom:entry.
The atom:source element is designed to allow the aggregation of entries from different feeds while retaining information about an entry's source feed. For this reason, Atom Processors that are performing such aggregation SHOULD include at least the required feed-level Metadata fields (id
, title
, and updated
) in the source
element.
A MIME type that conform to the syntax of a MIME media type, but MUST NOT be a composite type (see Section 4.2.6 of MIMEREG
).
type content =
| Text of string
| Html of Uri.t option * string
| Xhtml of Uri.t option * Syndic_xml.t list
| Mime of mime * string
| Src of mime option * Uri.t
content
either contains or links to the content of the entry. The value of content
is Language-Sensitive. See RFC 4287 § 4.1.3
Text
, Html
, Xhtml
or Mime
means that the content was part of the document and is provided as an argument. The first argument to Html
and Xhtml
is the possible xml:base value. See RFC 4287 § 3.1.1Src(m, iri)
means that the content is to be found at iri
and has MIME type m
. Atom Processors MAY use the IRI to retrieve the content and MAY choose to ignore remote content or to present it in a different manner than local content. The value of m
is advisory; that is to say, when the corresponding URI (mapped from an IRI, if necessary) is dereferenced, if the server providing that content also provides a media type, the server-provided media type is authoritative. See RFC 4287 § 4.1.3.2type summary = text_construct
type entry = {
categories : category list;
content : content option;
contributors : author list;
id : id;
links : link list;
published : published option;
rights : rights option;
source : source option;
summary : summary option;
title : title;
updated : updated;
}
entry
represents an individual entry, acting as a container for metadata and data associated with the entry. This element can appear as a child of the atom:feed element, or it can appear as the document (i.e., top-level) element of a stand-alone Atom Entry Document.
The specification mandates that each entry contains an author unless it contains some sources or the feed contains an author element. This library ensures that the authors are properly dispatched to all locations.
The following child elements are defined by this specification (note that it requires the presence of some of these elements):
content = None
, then links
MUST contain at least one element with a rel attribute value of Alternate
.links
with a rel attribute value of Alternate
that has the same combination of type and hreflang attribute values.links
beyond those described above.There MUST be an summary
in either of the following cases:
MIMEREG
, but is not an XML media type RFC3023
, does not begin with "text/", and does not end with "/xml" or "+xml".type feed = {
categories : category list;
contributors : author list;
generator : generator option;
icon : icon option;
id : id;
links : link list;
logo : logo option;
rights : rights option;
subtitle : subtitle option;
title : title;
updated : updated;
entries : entry list;
}
feed
is the document (i.e., top-level) element of an Atom Feed Document, acting as a container for metadata and data associated with the feed. Its element children consist of metadata elements followed by zero or more atom:entry child elements.
links
SHOULD have a rel
attribute value of Self
. This is the preferred URI for retrieving Atom Feed Documents representing this Atom feed.links
with a rel attribute value of Alternate
that has the same combination of type and hreflang attribute values.links
beyond those described above.If multiple entry
elements with the same id
value appear in an Atom Feed Document, they represent the same entry. Their updated
timestamps SHOULD be different. If an Atom Feed Document contains multiple entries with the same id
, Atom Processors MAY choose to display all of them or some subset of them. One typical behavior would be to display only the entry with the latest updated
timestamp.
val parse : ?self:Uri.t -> ?xmlbase:Uri.t -> Xmlm.input -> feed
parse xml
returns the feed corresponding to xml
. Beware that xml
is mutable, so when the parsing fails, one has to create a new copy of xml
to use it with another function. If you retrieve xml
from a URL, you should use that URL as ~xmlbase
.
Raise Error.Expected
, Expected_Data
or Error.Duplicate_Link
if xml
is not a valid Atom document.
val to_xml : feed -> Syndic_xml.t
to_xml f
converts the feed f
to an XML tree.
val output : feed -> Xmlm.dest -> unit
output f dest
writes the XML tree of the feed f
to dest
.
val write : feed -> string -> unit
write f fname
writes the XML tree of the feed f
to the file named fname
.
Compare entries so that older dates are smaller. The date of the entry is taken from the published
field, if available, or otherwise updated
is used.
Compare entries so that more recent dates are smaller. The date of the entry is taken from the published
field, if available, or otherwise updated
is used.
val aggregate :
?id:id ->
?updated:updated ->
?subtitle:subtitle ->
?title:text_construct ->
?sort:[ `Newest_first | `Oldest_first | `None ] ->
?n:int ->
feed list ->
feed
aggregate feeds
returns a single feed containing all the posts in feeds
. In order to track the origin of each post in the aggrated feed, it is recommended that each feed in feeds
possesses a link with rel = Self
so that the source
added to each entry contains a link to the original feed. If an entry contains a source
, il will not be overwritten.
set_self feed url
add or replace the URI in the self link of the feed. You can also set the hreflang
and length
of the self link.
get_self feed
return the self link of the feed, if any is present.
set_main_author feed author
will add author
in front of the list of authors of the feed
(if an author with the same name already exists, the optional information are merged, the ones in author
taking precedence). Also remove all empty authors (name = "" and no URI, no email) and replace them with author
if no author is left and an authors is mandatory.