Syndicator Blog

Syndicator

Inside the Syndicator OPML Export, a Version 1.0 File Shaped Like OPML 2.0

Every Syndicator build writes a file called /feeds.opml. It lists every source on the sites page, 116 of them right now, so anyone can load the whole set into a feed reader in one step. Every page on the site also points to it from the <head>:

<link rel="alternate" type="text/x-opml" title="All feeds" href="/feeds.opml" />

The file is small and the code behind it is about twenty lines. It's still worth a close look, because the first line of the file says version="1.0" and almost everything after it follows the rules of OPML 2.0.

The code

The export lives in lib/render.mjs, next to the Atom feed and the sitemap. The build calls it once with the parsed contents of feeds.json:

export function opml(feeds) {
  const outlines = feeds
    .map(
      (feed) =>
        `    <outline text="${esc(feed.name)}" title="${esc(feed.name)}" type="${
          feed.type === "json" ? "json" : "rss"
        }" xmlUrl="${esc(feed.feed)}" htmlUrl="${esc(feed.url)}"/>`,
    )
    .join("\n");

  return `<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
  <head>
    <title>${esc(config.text.opmlTitle)}</title>
  </head>
  <body>
${outlines}
  </body>
</opml>
`;
}

Running it against the current feeds.json gives a flat list with one outline per site:

<opml version="1.0">
  <head>
    <title>All feeds</title>
  </head>
  <body>
    <outline text="3V" title="3V" type="rss" xmlUrl="https://3v.org/index.xml" htmlUrl="https://3v.org/"/>
    <outline text="Abbreviatory" title="Abbreviatory" type="rss" xmlUrl="https://abbreviatory.com/index.xml" htmlUrl="https://abbreviatory.com/"/>

No folders, no nesting, no dates. Parsed back with a standard XML parser, all 116 outlines carry text, title, type, xmlUrl and htmlUrl, and title always matches text.

What OPML 1.0 asks for

Very little. The 1.0 spec, published by UserLand in September 2000, describes OPML as an outline format. The version attribute is just "a version string, of the form, x.y". The type attribute is "a string, it says how the other attributes of the <outline> are interpreted", and the spec lists no values for it. It says nothing about feeds at all. xmlUrl and htmlUrl are conventions that feed readers built on top of it.

So the Syndicator file is valid 1.0, but so is nearly any XML with an <opml> root, a head and a body.

What OPML 2.0 asks for

The 2.0 spec is where subscription lists became a defined thing. The rules that matter here:

  • Every outline needs a text attribute. "A missing text attribute in any outline element is an error."
  • A subscription outline has three required attributes: type, text and xmlUrl. htmlUrl, title, description, language and version are optional.
  • The type for a feed is rss. The spec says each item in a subscription list is "a node of type rss or an outline element that contains nodes of type rss."
  • On title: it "is probably the same as text, it should not be omitted."
  • Everything in <head> is optional, including title.

Syndicator's output meets every one of those. It writes the required three, adds htmlUrl, and repeats the name in title exactly as the spec suggests. The 2.0 spec also says a file "may be 1.0 if it conforms to the earlier version of this specification", which this one does. So the header isn't wrong. It just undersells the file. Changing one character to version="2.0" would describe it more accurately, and nothing else in the output would need to change.

Why readers don't care

Feed readers mostly ignore the version and look for xmlUrl. Miniflux is a good example because its OPML code is short and readable. Its reader has no field for type at all. An outline counts as a subscription when xmlUrl isn't empty. For the name, it takes title first, then text, then falls back to the site or feed URL.

That fallback order is the reason to write both attributes. Some tools read text, some read title. Writing the same value into both means every reader shows "3V" instead of a bare URL, whichever one it prefers.

The one rough edge

Look at the type line again. Syndicator can read JSON Feed as well as RSS and Atom, and when an entry in feeds.json has "type": "json", the export writes type="json". No OPML spec defines that value. OPML 2.0 does allow new ones ("OPML can also be extended by the addition of new values for the type attribute"), but a reader that follows the subscription list rules strictly is looking for rss. Miniflux would import the outline anyway, since it never reads type. A stricter importer could skip it.

Today this is theoretical. None of the 116 entries in feeds.json sets a type, so every outline in the file says type="rss", Hugo and WordPress feeds alike. If a JSON Feed source joins, writing rss for it too would be the safer choice for a subscription list, since the reader fetches the URL and finds out the format on its own.

Escaping

Site names come from feeds.json and feed URLs often carry query strings, so the export runs every value through esc(), the same function the HTML templates use. It replaces &, <, >, " and ' with entities. A test entry named Tom & Jerry's <Blog> with the feed URL https://ex.com/feed?a=1&b=2 comes out as:

<outline text="Tom &amp; Jerry&#39;s &lt;Blog&gt;" title="Tom &amp; Jerry&#39;s &lt;Blog&gt;" type="json" xmlUrl="https://ex.com/feed?a=1&amp;b=2" htmlUrl="https://ex.com/"/>

An XML parser reads that back to the original strings. A bare ampersand in an attribute is the classic way to break an OPML file. The XML is no longer well formed, and a strict parser rejects the whole file.

What it leaves out

There's no dateCreated, dateModified or ownerName in the head. All three are optional, and the spec wants RFC 822 dates for the first two. Syndicator rebuilds twice a day, so a creation date would change on every build without telling a reader anything useful. There are no categories either. The list is flat, which is fine for 116 feeds and means importers that flatten folders lose nothing.

If you want the whole network in your reader, download feeds.opml and use your reader's import option. For what the format looks like in general and how moving between readers works, see OPML files explained. For which feed URLs are in the list and why so many end in index.xml, see what 114 aggregated sites show about Hugo and WordPress feed URLs.