Skip to content

Commit

Permalink
Add Bluesky feed
Browse files Browse the repository at this point in the history
  • Loading branch information
dam5s committed Feb 23, 2024
1 parent 023536e commit 3b7c171
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 24 deletions.
1 change: 1 addition & 0 deletions Damo.Io.Server/src/App.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module DamoIoServer.App

open System
open DamoIoServer
open DamoIoServer.SourcesRepository
open FSharp.Control
open Giraffe
open Microsoft.Extensions.Logging
Expand Down
3 changes: 2 additions & 1 deletion Damo.Io.Server/src/Article.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ type ArticleRecord =
Content: string
Media: MediaRecord option
Date: Posix option
Source: Source }
SourceType: Source
SourceName: string }
6 changes: 5 additions & 1 deletion Damo.Io.Server/src/ArticleTemplate.fs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ let render (article: ArticleRecord) : XmlNode =
let articleContent = section [] [ rawText article.Content ]
let maybeSourceLink = trySourceLink article

let sourceNameClass = article.SourceName.Replace(" ", "")
let sourceTypeClass = article.SourceType.ToString()
let cssClasses = $"{sourceNameClass} {sourceTypeClass}"

HtmlElements.article
[ _class $"%A{article.Source}" ]
[ _class cssClasses ]
[ yield articleHeader
yield articleContent

Expand Down
5 changes: 3 additions & 2 deletions Damo.Io.Server/src/ArticlesRepository.fs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ let private about: ArticleRecord =
Content = aboutContent
Media = None
Date = None
Source = About }
SourceType = About
SourceName = "About" }

let mutable private allRecords: ArticleRecord list = []

Expand All @@ -55,6 +56,6 @@ let findAll () = about :: allRecords
type FindAllBySources = Source list -> ArticleRecord list

let findAllBySources: FindAllBySources =
fun sources -> findAll () |> List.filter (fun r -> List.contains r.Source sources)
fun sources -> findAll () |> List.filter (fun r -> List.contains r.SourceType sources)

let updateAll newRecords = allRecords <- newRecords
22 changes: 12 additions & 10 deletions Damo.Io.Server/src/FeedsProcessor.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module DamoIoServer.FeedsProcessor

open DamoIoServer.Article
open DamoIoServer.SourcesRepository
open FSharp.Control
open FeedsProcessing.Article
open FeedsProcessing.DataGateway
Expand All @@ -9,20 +10,21 @@ open FeedsProcessing.ProcessingResult
open FeedsProcessing.Xml
open Microsoft.Extensions.Logging

let private articleToRecord sourceType (article: Article) : ArticleRecord =
let private articleToRecord (sourceFeed: SourceFeed) (article: Article) : ArticleRecord =
{ Title = Article.title article
Link = Article.link article
Content = Article.content article
Media = Article.media article |> Option.map MediaRecord.ofMedia
Date = Article.date article
Source = sourceType }
SourceType = sourceFeed.Type
SourceName = sourceFeed.Name }

let private resultToList sourceType (result: ProcessingResult) =
List.map (articleToRecord sourceType) (Result.defaultValue [] result)
let private resultToList (sourceFeed: SourceFeed) (result: ProcessingResult) =
List.map (articleToRecord sourceFeed) (Result.defaultValue [] result)

let private downloadAndProcessFeed (logger: ILogger) feed : Async<ProcessingResult> =
match feed with
| Xml(_, url) ->
let private downloadAndProcessFeed (logger: ILogger) (sourceFeed: SourceFeed) : Async<ProcessingResult> =
match sourceFeed.Feed with
| Xml(url) ->
async {
let! download = downloadContent url

Expand All @@ -43,9 +45,9 @@ let private downloadAndProcessFeed (logger: ILogger) feed : Async<ProcessingResu

let processFeeds (logger: ILogger) (sources: SourcesRepository.SourceFeed list) : AsyncSeq<ArticleRecord> =
asyncSeq {
for sourceType, feed in sources do
let! processingResult = downloadAndProcessFeed logger feed
let articles = processingResult |> resultToList sourceType
for sourceFeed in sources do
let! processingResult = downloadAndProcessFeed logger sourceFeed
let articles = processingResult |> resultToList sourceFeed

for a in articles do
yield a
Expand Down
26 changes: 20 additions & 6 deletions Damo.Io.Server/src/SourcesRepository.fs
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
[<RequireQualifiedAccess>]
module DamoIoServer.SourcesRepository

open DamoIoServer.Source
open FeedsProcessing.Download
open FeedsProcessing.Feeds

type SourceFeed = Source * Feed
type SourceFeed =
{ Type: Source
Name: string
Feed: Feed }

[<RequireQualifiedAccess>]
module SourcesRepository =

let findAll () : SourceFeed list =
[ (Code, Xml(FeedName "Github", Url "https://github.com/dam5s.atom"))
(Blog, Xml(FeedName "Blog", Url "https://blog.damo.io/rss.xml"))
(Social, Xml(FeedName "Mastodon", Url "https://mastodon.kleph.eu/users/dam5s.rss")) ]
let findAll () : SourceFeed list =
[ { Type = Code
Name = "Github"
Feed = Xml(Url "https://github.com/dam5s.atom") }
{ Type = Blog
Name = "Blog"
Feed = Xml(Url "https://blog.damo.io/rss.xml") }
{ Type = Social
Name = "Mastodon"
Feed = Xml(Url "https://mastodon.kleph.eu/users/dam5s.rss") }
{ Type = Social
Name = "Bluesky"
Feed = Xml(Url "https://bsky.app/profile/did:plc:zvnvcicnso363xz3gu6ho3mw/rss") } ]
9 changes: 8 additions & 1 deletion Damo.Io.Server/www/styles/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ article:last-child {
}

article.Social {
background-image: url('data:image/svg+xml;utf8,%3Csvg%20height%3D%222500%22%20width%3D%222331%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%22-0.41%200.22%20747.62%20801.4499999999999%22%3E%3Cpath%20d%3D%22M729.94%20479.5c-10.96%2056.4-98.17%20118.12-198.34%20130.08-52.23%206.23-103.66%2011.96-158.49%209.44-89.68-4.1-160.45-21.4-160.45-21.4%200%208.73.54%2017.04%201.62%2024.81%2011.66%2088.52%2087.76%2093.82%20159.84%2096.29%2072.76%202.49%20137.55-17.94%20137.55-17.94l2.99%2065.79s-50.89%2027.32-141.55%2032.35c-50%202.75-112.07-1.26-184.37-20.39C31.94%20737.02%204.97%20569.86.85%20400.26-.41%20349.9.37%20302.42.37%20262.7.37%2089.27%20113.99%2038.44%20113.99%2038.44%20171.28%2012.12%20269.59%201.06%20371.79.22h2.52c102.19.84%20200.57%2011.9%20257.86%2038.22%200%200%20113.62%2050.83%20113.62%20224.26%200%200%201.42%20127.96-15.85%20216.8%22%20fill%3D%22%23888%22%2F%3E%3Cpath%20d%3D%22M611.77%20276.16v209.99h-83.2V282.33c0-42.97-18.07-64.77-54.23-64.77-39.98%200-60.01%2025.86-60.01%2077.02v111.57h-82.71V294.58c0-51.16-20.04-77.02-60.01-77.02-36.16%200-54.24%2021.8-54.24%2064.77v203.82h-83.19V276.16c0-42.92%2010.93-77.03%2032.88-102.26%2022.63-25.23%2052.27-38.17%2089.07-38.17%2042.57%200%2074.81%2016.37%2096.12%2049.1l20.72%2034.74%2020.73-34.74c21.31-32.73%2053.55-49.1%2096.12-49.1%2036.79%200%2066.44%2012.94%2089.07%2038.17%2021.95%2025.23%2032.88%2059.34%2032.88%20102.26z%22%20fill%3D%22%23fff%22%2F%3E%3C%2Fsvg%3E');
background-repeat: no-repeat;
background-position-x: right var(--spacing-4);
background-position-y: var(--spacing-2);
Expand All @@ -264,6 +263,14 @@ article.Social {
}
}

article.Mastodon {
background-image: url('data:image/svg+xml;utf8,%3Csvg%20height%3D%222500%22%20width%3D%222331%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%22-0.41%200.22%20747.62%20801.4499999999999%22%3E%3Cpath%20d%3D%22M729.94%20479.5c-10.96%2056.4-98.17%20118.12-198.34%20130.08-52.23%206.23-103.66%2011.96-158.49%209.44-89.68-4.1-160.45-21.4-160.45-21.4%200%208.73.54%2017.04%201.62%2024.81%2011.66%2088.52%2087.76%2093.82%20159.84%2096.29%2072.76%202.49%20137.55-17.94%20137.55-17.94l2.99%2065.79s-50.89%2027.32-141.55%2032.35c-50%202.75-112.07-1.26-184.37-20.39C31.94%20737.02%204.97%20569.86.85%20400.26-.41%20349.9.37%20302.42.37%20262.7.37%2089.27%20113.99%2038.44%20113.99%2038.44%20171.28%2012.12%20269.59%201.06%20371.79.22h2.52c102.19.84%20200.57%2011.9%20257.86%2038.22%200%200%20113.62%2050.83%20113.62%20224.26%200%200%201.42%20127.96-15.85%20216.8%22%20fill%3D%22%23888%22%2F%3E%3Cpath%20d%3D%22M611.77%20276.16v209.99h-83.2V282.33c0-42.97-18.07-64.77-54.23-64.77-39.98%200-60.01%2025.86-60.01%2077.02v111.57h-82.71V294.58c0-51.16-20.04-77.02-60.01-77.02-36.16%200-54.24%2021.8-54.24%2064.77v203.82h-83.19V276.16c0-42.92%2010.93-77.03%2032.88-102.26%2022.63-25.23%2052.27-38.17%2089.07-38.17%2042.57%200%2074.81%2016.37%2096.12%2049.1l20.72%2034.74%2020.73-34.74c21.31-32.73%2053.55-49.1%2096.12-49.1%2036.79%200%2066.44%2012.94%2089.07%2038.17%2021.95%2025.23%2032.88%2059.34%2032.88%20102.26z%22%20fill%3D%22%23fff%22%2F%3E%3C%2Fsvg%3E');
}

article.Bluesky {
background-image: url('data:image/svg+xml;utf8,%3Csvg%20width%3D%22100%25%22%20height%3D%22100%25%22%20viewBox%3D%220%200%2092%2082%22%20version%3D%221.1%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22%20xml%3Aspace%3D%22preserve%22%20xmlns%3Aserif%3D%22http%3A%2F%2Fwww.serif.com%2F%22%20style%3D%22fill-rule%3Aevenodd%3Bclip-rule%3Aevenodd%3Bstroke-linejoin%3Around%3Bstroke-miterlimit%3A2%3B%22%3E%3Cpath%20d%3D%22M19.942%2C5.501C30.489%2C13.446%2041.836%2C29.553%2046%2C38.197L46%2C61.027C46%2C60.541%2045.813%2C61.091%2045.411%2C62.274C43.237%2C68.679%2034.747%2C93.679%2015.334%2C73.693C5.112%2C63.171%209.844%2C52.648%2028.451%2C49.471C17.806%2C51.288%205.839%2C48.285%202.556%2C36.512C1.61%2C33.125%200%2C12.264%200%2C9.447C0%2C-4.667%2012.332%2C-0.23%2019.942%2C5.501ZM72.058%2C5.501C61.511%2C13.446%2050.164%2C29.553%2046%2C38.197L46%2C61.027C46%2C60.541%2046.187%2C61.091%2046.589%2C62.274C48.763%2C68.679%2057.253%2C93.679%2076.666%2C73.693C86.888%2C63.171%2082.156%2C52.648%2063.549%2C49.471C74.194%2C51.288%2086.161%2C48.285%2089.444%2C36.512C90.39%2C33.125%2092%2C12.264%2092%2C9.447C92%2C-4.667%2079.669%2C-0.23%2072.058%2C5.501Z%22%20style%3D%22fill%3Argb(136%2C136%2C136)%3Bfill-rule%3Anonzero%3B%22%2F%3E%3C%2Fsvg%3E%0A')
}

.main-menu {
list-style-type: none;

Expand Down
4 changes: 1 addition & 3 deletions FeedsProcessing/src/Feeds.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@ module FeedsProcessing.Feeds
open FeedsProcessing.Download


type FeedName = FeedName of string

type Feed = Xml of FeedName * Url
type Feed = Xml of Url
1 change: 1 addition & 0 deletions somanyfeeds.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=Berrigaud_0027s/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Bluesky/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=damo/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Fantomas/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=htmx/@EntryIndexedValue">True</s:Boolean>
Expand Down

0 comments on commit 3b7c171

Please sign in to comment.