# How to write an atom feed ?
2022-06-15T14:31:10Z

ATOM feeds let one subscribe to your website and get latest content. It is free. It can be used to publish content.
ATOM is RSS improved.

Instead of relying on provate social networks, you should consider using feeds.

Let's see how to write an ATOM feed.

First, insert a header : 

```
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="/atom.xsl" type="text/xsl"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <id>https://si3t.ch/log/</id>
  <title>log de prx</title>
  <icon>/favicon.svg</icon>
  <link rel="alternate" type="text/gemini" href="gemini://si3t.ch/log/"/>
  <link rel="alternate" type="text/html" href="https://si3t.ch/log/"/>
  <link rel="self" type="application/atom+xml" href="https://si3t.ch/log/atom.xml"/>
  <author>
    <name>prx</name>
    <email>prx@si3t.ch</email>
  </author>
  <updated>2022-06-08T15:55:32Z</updated>
```

As you can see, the two first line are xml declaration, the 2nd call a stylesheet to display the atom feed. It is optional.
Then, we open a tag "<feed>".
id should be unique, use an URL as example.
You should specify linksto tell where is the content (alternate) and where the feed actually is (self) in case of redirections. Add an author section if you want.
Finally, insert a date when your feed has been updated. It has to be modified each time you update your feed. Format is <year>-<month>-<day>T<hour>:<minutes>:<seconds>Z.

Then, you can add entries : they are your content. 1 entry = 1 article. Add as many as you want.

```
<entry>
    <title type="text">Youtube to mpd</title>
    <id>gemini://si3t.ch/log/2022-06-06-yt2mpd.gmi</id>
    <updated>2022-06-06T14:57:30Z</updated>
    <link rel="alternate" type="text/gemini" href="gemini://si3t.ch/log/2022-06-06-yt2mpd.gmi"/>
    <content type="text"><![CDATA[

	Some stuff...
	Your article...

]]></content>
  </entry>
```

As you can see, you can write some metadata : 

* a title
* the id of the entry. It must be unique (the url is quite good).
* time when it has been updated (created)
* a link to the article.
* A new tag to add the content. As example, I show here a plain text content wrapped in CDATA to avoid escaping and issues with html. If you se the type to "html", make sure you escape &,<,>,'," to &amp;, &lt;, &gt;, &apos; &quot;.

To end an entry : 
* Close the CDATA tag with "]]>" and content tag.
* Close entry tag.

Finally, close your feed since it must be XML valid content.

```
</feed>
```

That's it 😉

## See also

=> https://aboutfeeds.com/ About feeds.
=> https://validator.w3.org/feed/docs/atom.html What is Atom ?
=> https://si3t.ch/Logiciel-libre/atom-awk.xhtml atom.awk to generate an atom feed (http)
=> gemini://si3t.ch/Logiciel-libre/atom-awk.gmi atom.awk to generate an atom feed (gemini)