statiqdev / Statiq.Web

Statiq Web is a flexible static site generator written in .NET.
https://statiq.dev/web
Other
1.64k stars 235 forks source link

FeedItemId not being set #906

Closed drmathias closed 4 years ago

drmathias commented 4 years ago

When updating from Statiq.Web 1.0.0-alpha.14 to a newer release, an exception is thrown during the build, if FeedItemId is defined in the feed file.

feed.yml

...
FeedItemId: >
  => $"tag:{Domain},{Published}:{DocumentName}"

Exception:

System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=Statiq.Feeds
  StackTrace:
   at Statiq.Feeds.Syndication.Atom.AtomEntry..ctor(IFeedItem source) in C:\Code\statiqdev\Statiq.Framework\src\extensions\Statiq.Feeds\Syndication\Atom\AtomEntry.cs:line 36
   at Statiq.Feeds.Syndication.Atom.AtomFeed.<>c.<.ctor>b__5_0(IFeedItem x) in C:\Code\statiqdev\Statiq.Framework\src\extensions\Statiq.Feeds\Syndication\Atom\AtomFeed.cs:line 106
   at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext()
   at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
   at System.Collections.Generic.List`1.AddRange(IEnumerable`1 collection)
   at Statiq.Feeds.Syndication.Atom.AtomFeed..ctor(IFeed source) in C:\Code\statiqdev\Statiq.Framework\src\extensions\Statiq.Feeds\Syndication\Atom\AtomFeed.cs:line 106
   at Statiq.Feeds.Syndication.FeedType.<>c.<.cctor>b__9_2(IFeed source) in C:\Code\statiqdev\Statiq.Framework\src\extensions\Statiq.Feeds\Syndication\FeedType.cs:line 20
   at Statiq.Feeds.Syndication.FeedType.GetFeed(IFeed source) in C:\Code\statiqdev\Statiq.Framework\src\extensions\Statiq.Feeds\Syndication\FeedType.cs:line 33
   at Statiq.Feeds.Syndication.FeedSerializer.SerializeXml(FeedType feedType, IFeed feed, Stream output, String xsltUrl, Boolean prettyPrint) in C:\Code\statiqdev\Statiq.Framework\src\extensions\Statiq.Feeds\Syndication\FeedSerializer.cs:line 75
   at Statiq.Feeds.Syndication.FeedSerializer.SerializeXml(FeedType feedType, IFeed feed, Stream output, String xsltUrl) in C:\Code\statiqdev\Statiq.Framework\src\extensions\Statiq.Feeds\Syndication\FeedSerializer.cs:line 60
   at Statiq.Feeds.Syndication.FeedSerializer.SerializeXml(FeedType feedType, IFeed feed, Stream output) in C:\Code\statiqdev\Statiq.Framework\src\extensions\Statiq.Feeds\Syndication\FeedSerializer.cs:line 54
   at Statiq.Feeds.GenerateFeeds.<GenerateFeedAsync>d__60.MoveNext() in C:\Code\statiqdev\Statiq.Framework\src\extensions\Statiq.Feeds\GenerateFeeds.cs:line 569
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

  This exception was originally thrown at this call stack:
    Statiq.Feeds.Syndication.Atom.AtomEntry.AtomEntry(Statiq.Feeds.Syndication.IFeedItem) in AtomEntry.cs

It appears that instead of being set to the value specified in the feed file, the feed entry IDs are being set to null, causing the module to throw an exception. However if not defined, the feed entry IDs are set to the default generated value.

Version 1.0.0-alpha.14 and lower does not have this issue and the feed gets generated as expected.

daveaglick commented 4 years ago

Ahh - I see the problem. The feed item ID is expecting a Uri and since the style of item ID in your front matter can't be parsed as one it's just returning null. This changed/regressed as part of a fix to pass better data to the underlying GeenrateFeeds module.

I'd be curious what you were ending up with before. The RSS/Atom library has always used URIs so somewhere along the way it must have gotten converted to one.

My first instinct is that I should change the underlying RSS/Atom library in Statiq.Feeds (which I forked from somewhere else) to use a string instead of a URI. That ID value actually maps to the RSS GUID, which appears to be a string according to the best specification data I could find: https://cyber.harvard.edu/rss/rss.html#ltguidgtSubelementOfLtitemgt

Any thoughts on that?

daveaglick commented 4 years ago

After just a bit more digging I guess the theory was that the unique link to a feed item was that item's ID, but I think you've just shown that's not a great universal strategy and we should allow alternate non-URI IDs too.

drmathias commented 4 years ago

Can't seem to find the change that was made, though using Uri should work fine with tag URIs. However I think you're right in saying it would be better to use a string, as it adheres to the RSS & Atom specs better. Sometimes GUID/UUIDs are used as item IDs and using Uri wouldn't work for those.

daveaglick commented 4 years ago

This should be fixed and will go out with the next release.