summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-02-26 14:08:10 +0100
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-02-26 14:08:10 +0100
commit34c67488c6ebdc19daf7699d424e8257619aa96d (patch)
treeb52e3a38774be185291b5a360194676211f88e34
init
-rw-r--r--.envrc1
-rw-r--r--.gitignore1
-rw-r--r--CHANGELOG.md5
-rw-r--r--LICENSE26
-rw-r--r--app/Main.hs63
-rw-r--r--default.nix24
-rw-r--r--feed-nomath-org.cabal25
-rw-r--r--shell.nix1
8 files changed, 146 insertions, 0 deletions
diff --git a/.envrc b/.envrc
new file mode 100644
index 0000000..1d953f4
--- /dev/null
+++ b/.envrc
@@ -0,0 +1 @@
+use nix
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..8075013
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/dist-newstyle
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..f3576c0
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,5 @@
+# Revision history for feed-nomath-org
+
+## 0.1.0.0 -- YYYY-mm-dd
+
+* First version. Released on an unsuspecting world.
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..9128a61
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,26 @@
+Copyright (c) 2024, Alexander Foremny
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the
+ distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/app/Main.hs b/app/Main.hs
new file mode 100644
index 0000000..35e675a
--- /dev/null
+++ b/app/Main.hs
@@ -0,0 +1,63 @@
+{-# LANGUAGE BlockArguments #-}
+{-# LANGUAGE LambdaCase #-}
+{-# LANGUAGE OverloadedStrings #-}
+{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
+
+module Main where
+
+import Conduit
+import Data.Maybe
+import Data.XML.Types
+import Network.HTTP.Conduit
+import Text.Atom.Conduit.Parse
+import Text.Atom.Conduit.Render
+import Text.XML.Stream.Parse
+import Text.XML.Stream.Render
+import Text.XML.Unresolved (elementToEvents)
+
+main :: IO ()
+main = do
+ request <- parseRequest "https://code.nomath.org/abuilder/atom"
+ manager <- newManager tlsManagerSettings
+ runResourceT do
+ response <- http request manager
+ runConduit $
+ ( \feed ->
+ renderAtomFeed feed
+ .| renderBytes def
+ .| printC
+ )
+ . fromJust
+ =<< responseBody response
+ .| parseBytes def
+ .| massage
+ .| atomFeed
+
+massage :: ConduitT Event Event (ResourceT IO) ()
+massage = do
+ await >>= \case
+ Nothing -> pure ()
+ Just e -> do
+ yield e -- BeginDocument
+ await >>= \case
+ Nothing -> pure ()
+ Just e -> do
+ yield e -- <feed>
+ yieldMany (elementToEvents idE)
+ yieldMany (elementToEvents updatedE)
+ mapC id
+ where
+ idE =
+ -- TODO(id)
+ Element
+ "{http://www.w3.org/2005/Atom}id"
+ []
+ [ NodeContent (ContentText "TODO")
+ ]
+ updatedE =
+ -- TODO(updated)
+ Element
+ "{http://www.w3.org/2005/Atom}updated"
+ []
+ [ NodeContent (ContentText "1970-01-01T00:00:00Z")
+ ]
diff --git a/default.nix b/default.nix
new file mode 100644
index 0000000..830ada3
--- /dev/null
+++ b/default.nix
@@ -0,0 +1,24 @@
+{ pkgs ? import <nixpkgs> { } }:
+let
+ haskellPackages = pkgs.haskellPackages.override {
+ overrides = self: super: {
+ feed-nomath-org = self.callCabal2nix "feed-nomath-org" ./. { };
+ };
+ };
+in
+rec {
+ inherit (haskellPackages) feed-nomath-org;
+ shell = haskellPackages.shellFor {
+ packages = _: [
+ feed-nomath-org
+ haskellPackages.atom-conduit
+ ];
+ buildInputs = [
+ haskellPackages.cabal2nix
+ haskellPackages.cabal-install
+ haskellPackages.ormolu
+ ];
+ withHoogle = true;
+ withHaddock = true;
+ };
+}
diff --git a/feed-nomath-org.cabal b/feed-nomath-org.cabal
new file mode 100644
index 0000000..0ceecfa
--- /dev/null
+++ b/feed-nomath-org.cabal
@@ -0,0 +1,25 @@
+cabal-version: 3.4
+name: feed-nomath-org
+version: 0.1.0.0
+license: BSD-2-Clause
+license-file: LICENSE
+maintainer: aforemny@posteo.de
+author: Alexander Foremny
+category: Web
+build-type: Simple
+extra-doc-files: CHANGELOG.md
+
+executable feed-nomath-org
+ main-is: Main.hs
+ hs-source-dirs: app
+ default-language: GHC2021
+ ghc-options: -Wall
+ build-depends:
+ atom-conduit,
+ base,
+ bytestring,
+ conduit,
+ http-conduit,
+ resourcet,
+ xml-conduit,
+ xml-types
diff --git a/shell.nix b/shell.nix
new file mode 100644
index 0000000..a6bdf20
--- /dev/null
+++ b/shell.nix
@@ -0,0 +1 @@
+(import ./. { }).shell